shalabyelectronics commited on
Commit
fa326ca
·
verified ·
1 Parent(s): 1dc1b0b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -26
app.py CHANGED
@@ -1,50 +1,44 @@
1
  import gradio as gr
2
- from huggingface_hub import InferenceClient
3
- import os
4
 
5
- # 1. جلب التوكن
6
- hf_token = os.getenv("HF_TOKEN")
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
- # 3. الإرسال المباشر (Text Generation)
19
- # هذا النموذج يقبل الأسئلة مباشرة دون تعقيدات المحادثة
20
- response = client.text_generation(prompt, max_new_tokens=200)
21
 
22
- # 4. التقييم
23
  evaluation = ""
24
- if len(response) > 2:
25
- evaluation = "✅ النموذج فهم وأجاب"
26
  else:
27
- evaluation = "⚠️ إجابة غير واضحة"
28
 
29
- return response, evaluation
30
 
31
  except Exception as e:
32
- return f"خطأ: {str(e)}", "فشل "
33
 
34
  # واجهة التطبيق
35
  with gr.Blocks(theme=gr.themes.Soft()) as demo:
36
- gr.Markdown("# 🤖 اختبار فهم النماذج للنصوص (Prompt Understanding Test)")
37
- gr.Markdown(f"Current Model: {model_id}")
38
- gr.Markdown("💡 ملحوظة: هذا النموذج يعمل بأفضل كفاءة باللغة الإنجليزية.")
39
 
40
  with gr.Row():
41
- input_text = gr.Textbox(label="أدخل الـ Prompt هنا", placeholder="Example: What is the capital of Egypt?")
42
 
43
- btn = gr.Button("إرسال للتحليل", variant="primary")
44
 
45
  with gr.Row():
46
- output_text = gr.Textbox(label="رد النموذج (AI Response)")
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