File size: 1,768 Bytes
52cbca4 fa326ca 52cbca4 fa326ca 52cbca4 fa326ca d02a12f 52cbca4 fa326ca d02a12f fa326ca 932c1eb fa326ca d02a12f fa326ca 932c1eb fa326ca d02a12f 52cbca4 fa326ca 52cbca4 101322e 52cbca4 fa326ca 52cbca4 fa326ca 52cbca4 fa326ca 52cbca4 fa326ca 52cbca4 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
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() |