Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -11,62 +11,44 @@ model_name = "mistral-small-latest"
|
|
| 11 |
def generate_question(text):
|
| 12 |
|
| 13 |
prompt = f"""
|
| 14 |
-
|
| 15 |
|
| 16 |
-
|
|
|
|
| 17 |
|
| 18 |
-
|
| 19 |
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
-
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
-
|
| 27 |
|
| 28 |
-
|
|
|
|
| 29 |
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
إذا كان هناك معلومة (مثل أصبغة معينة أو مادة كيميائية) لن يضطر المتعلم لذكرها، أعد صياغة السؤال ليتضمنها.
|
| 33 |
-
|
| 34 |
-
الآن، صغ السؤال النهائي ثم اشرح لي باختصار كيف يضمن هذا السؤال استرجاع كافة تفاصيل النص.
|
| 35 |
-
إليك النص: {text}
|
| 36 |
-
التزم فقط بالحقائق الواردة في النص، ولا تطلب في السؤال تفسيرات وظيفية أو علمية ما لم تكن مذكورة صراحة في الفقرة.
|
| 37 |
-
السؤال:
|
| 38 |
"""
|
| 39 |
-
|
| 40 |
try:
|
| 41 |
response = client.chat.complete(
|
| 42 |
model=model_name,
|
| 43 |
-
messages=[
|
| 44 |
-
|
| 45 |
-
],
|
| 46 |
-
temperature=0.3
|
| 47 |
)
|
| 48 |
|
| 49 |
-
return response.choices[0].message.content
|
| 50 |
|
| 51 |
except Exception as e:
|
| 52 |
-
return f"حدث خطأ: {e}"
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
# Gradio UI
|
| 56 |
-
demo = gr.Interface(
|
| 57 |
-
fn=generate_question,
|
| 58 |
-
inputs=[
|
| 59 |
-
gr.Textbox(
|
| 60 |
-
lines=10,
|
| 61 |
-
label="الفقرة"
|
| 62 |
-
)
|
| 63 |
-
],
|
| 64 |
-
outputs=gr.Textbox(
|
| 65 |
-
lines=14,
|
| 66 |
-
label="السؤال المولد"
|
| 67 |
-
),
|
| 68 |
-
title="مولد الأسئلة العربية باستخدام Mistral Nemo",
|
| 69 |
-
description="أدخل عنوان الدرس والفقرة وسيتم توليد سؤال شامل."
|
| 70 |
-
)
|
| 71 |
-
|
| 72 |
-
demo.launch()
|
|
|
|
| 11 |
def generate_question(text):
|
| 12 |
|
| 13 |
prompt = f"""
|
| 14 |
+
You are an expert Arabic educational content designer.
|
| 15 |
|
| 16 |
+
TASK:
|
| 17 |
+
Generate ONE comprehensive question that covers the main ideas of the given text.
|
| 18 |
|
| 19 |
+
STRICT RULES:
|
| 20 |
|
| 21 |
+
1. The question must be:
|
| 22 |
+
- Clear and concise (maximum 25 words)
|
| 23 |
+
- Written in correct Modern Standard Arabic
|
| 24 |
+
- A single sentence only
|
| 25 |
|
| 26 |
+
2. The question should:
|
| 27 |
+
- Cover the main idea of the text
|
| 28 |
+
- Encourage recalling most key points
|
| 29 |
+
- NOT require listing every tiny detail
|
| 30 |
|
| 31 |
+
3. DO NOT:
|
| 32 |
+
- Repeat phrases
|
| 33 |
+
- Ask multiple questions
|
| 34 |
+
- Explain anything
|
| 35 |
+
- Add analysis or commentary
|
| 36 |
|
| 37 |
+
4. Output ONLY the question.
|
| 38 |
|
| 39 |
+
TEXT:
|
| 40 |
+
{text}
|
| 41 |
|
| 42 |
+
FINAL QUESTION:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
"""
|
|
|
|
| 44 |
try:
|
| 45 |
response = client.chat.complete(
|
| 46 |
model=model_name,
|
| 47 |
+
messages=[{"role": "user", "content": prompt}],
|
| 48 |
+
temperature=0.2
|
|
|
|
|
|
|
| 49 |
)
|
| 50 |
|
| 51 |
+
return response.choices[0].message.content.strip()
|
| 52 |
|
| 53 |
except Exception as e:
|
| 54 |
+
return f"حدث خطأ: {e}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|