| | import gradio as gr |
| | from transformers import pipeline |
| |
|
| | |
| | |
| | pipe = pipeline("text2text-generation", model="google/flan-t5-small") |
| |
|
| | def analyze_response(prompt): |
| | if not prompt: |
| | return "Please enter text.", "⚪" |
| | |
| | try: |
| | |
| | output = pipe(prompt, max_length=100) |
| | response_text = output[0]['generated_text'] |
| | |
| | |
| | evaluation = "" |
| | if len(response_text) > 2: |
| | evaluation = "✅ النموذج فهم وأجاب (Success)" |
| | else: |
| | evaluation = "⚠️ إجابة قصيرة (Short)" |
| | |
| | return response_text, evaluation |
| |
|
| | except Exception as e: |
| | return f"Error: {str(e)}", "❌ Failed" |
| |
|
| | |
| | with gr.Blocks(theme=gr.themes.Soft()) as demo: |
| | gr.Markdown("# 🤖 اختبار فهم النماذج (Local Model Test)") |
| | gr.Markdown("يتم الآن تشغيل النموذج داخلياً (Local Execution) لضمان الاستقرار.") |
| | |
| | with gr.Row(): |
| | input_text = gr.Textbox(label="أدخل الـ Prompt (English preferred)", placeholder="Example: What is the capital of Egypt?") |
| | |
| | btn = gr.Button("تشغيل التحليل", variant="primary") |
| | |
| | with gr.Row(): |
| | output_text = gr.Textbox(label="الرد (Response)") |
| | eval_text = gr.Label(label="التقييم (Evaluation)") |
| |
|
| | btn.click(analyze_response, inputs=input_text, outputs=[output_text, eval_text]) |
| |
|
| | demo.launch() |