import gradio as gr from transformers import pipeline # إعداد النموذج محلياً (سيتم تحميله مرة واحدة عند التشغيل) # نستخدم نموذج "flan-t5-small" لأنه خفيف وسريع ويعمل بدون إنترنت 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()