Update app.py
Browse files
app.py
CHANGED
|
@@ -1,50 +1,44 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from
|
| 3 |
-
import os
|
| 4 |
|
| 5 |
-
#
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
# 2. إعداد العميل مع نموذج جوجل المستقر جداً
|
| 9 |
-
# هذا النموذج هو "الجوكر" ويعمل دائماً على السيرفرات المجانية
|
| 10 |
-
model_id = "google/flan-t5-large"
|
| 11 |
-
client = InferenceClient(model=model_id, token=hf_token)
|
| 12 |
|
| 13 |
def analyze_response(prompt):
|
| 14 |
if not prompt:
|
| 15 |
-
return "
|
| 16 |
|
| 17 |
try:
|
| 18 |
-
#
|
| 19 |
-
|
| 20 |
-
|
| 21 |
|
| 22 |
-
#
|
| 23 |
evaluation = ""
|
| 24 |
-
if len(
|
| 25 |
-
evaluation = "✅ النموذج فهم وأجاب"
|
| 26 |
else:
|
| 27 |
-
evaluation = "⚠️ إجابة
|
| 28 |
|
| 29 |
-
return
|
| 30 |
|
| 31 |
except Exception as e:
|
| 32 |
-
return f"
|
| 33 |
|
| 34 |
# واجهة التطبيق
|
| 35 |
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
| 36 |
-
gr.Markdown("# 🤖 اختبار فهم النماذج
|
| 37 |
-
gr.Markdown(
|
| 38 |
-
gr.Markdown("💡 ملحوظة: هذا النموذج يعمل بأفضل كفاءة باللغة الإنجليزية.")
|
| 39 |
|
| 40 |
with gr.Row():
|
| 41 |
-
input_text = gr.Textbox(label="أدخل الـ Prompt
|
| 42 |
|
| 43 |
-
btn = gr.Button("
|
| 44 |
|
| 45 |
with gr.Row():
|
| 46 |
-
output_text = gr.Textbox(label="
|
| 47 |
-
eval_text = gr.Label(label="
|
| 48 |
|
| 49 |
btn.click(analyze_response, inputs=input_text, outputs=[output_text, eval_text])
|
| 50 |
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
|
|
|
| 3 |
|
| 4 |
+
# إعداد النموذج محلياً (سيتم تحميله مرة واحدة عند التشغيل)
|
| 5 |
+
# نستخدم نموذج "flan-t5-small" لأنه خفيف وسريع ويعمل بدون إنترنت
|
| 6 |
+
pipe = pipeline("text2text-generation", model="google/flan-t5-small")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
def analyze_response(prompt):
|
| 9 |
if not prompt:
|
| 10 |
+
return "Please enter text.", "⚪"
|
| 11 |
|
| 12 |
try:
|
| 13 |
+
# التوليد باستخدام المعالج الداخلي للموقع
|
| 14 |
+
output = pipe(prompt, max_length=100)
|
| 15 |
+
response_text = output[0]['generated_text']
|
| 16 |
|
| 17 |
+
# التقييم
|
| 18 |
evaluation = ""
|
| 19 |
+
if len(response_text) > 2:
|
| 20 |
+
evaluation = "✅ النموذج فهم وأجاب (Success)"
|
| 21 |
else:
|
| 22 |
+
evaluation = "⚠️ إجابة قصيرة (Short)"
|
| 23 |
|
| 24 |
+
return response_text, evaluation
|
| 25 |
|
| 26 |
except Exception as e:
|
| 27 |
+
return f"Error: {str(e)}", "❌ Failed"
|
| 28 |
|
| 29 |
# واجهة التطبيق
|
| 30 |
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
| 31 |
+
gr.Markdown("# 🤖 اختبار فهم النماذج (Local Model Test)")
|
| 32 |
+
gr.Markdown("يتم الآن تشغيل النموذج داخلياً (Local Execution) لضمان الاستقرار.")
|
|
|
|
| 33 |
|
| 34 |
with gr.Row():
|
| 35 |
+
input_text = gr.Textbox(label="أدخل الـ Prompt (English preferred)", placeholder="Example: What is the capital of Egypt?")
|
| 36 |
|
| 37 |
+
btn = gr.Button("تشغيل التحليل", variant="primary")
|
| 38 |
|
| 39 |
with gr.Row():
|
| 40 |
+
output_text = gr.Textbox(label="الرد (Response)")
|
| 41 |
+
eval_text = gr.Label(label="التقييم (Evaluation)")
|
| 42 |
|
| 43 |
btn.click(analyze_response, inputs=input_text, outputs=[output_text, eval_text])
|
| 44 |
|