Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,58 +9,45 @@ model_name = "mistral-large-latest"
|
|
| 9 |
|
| 10 |
|
| 11 |
def generate_MCQquestion(text):
|
| 12 |
-
|
| 13 |
prompt = f"""
|
| 14 |
You are a strict Arabic exam generator.
|
| 15 |
-
|
| 16 |
You MUST use ONLY the information explicitly written in the Context.
|
| 17 |
DO NOT use any external knowledge.
|
| 18 |
-
|
| 19 |
-
|
| 20 |
Context:
|
| 21 |
{text}
|
|
|
|
| 22 |
Generate MCQs in Arabic based on the length of the Context.
|
| 23 |
-
|
| 24 |
Question count rules:
|
| 25 |
-
- Very short context (
|
| 26 |
-
- Short context (100β300 words):
|
| 27 |
-
- Medium context (300β700 words):
|
| 28 |
-
- Long context (
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
-
|
| 38 |
-
-
|
| 39 |
-
- If the
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
Options rules:
|
| 43 |
-
- 4 options per question
|
| 44 |
-
- Only one correct answer
|
| 45 |
-
- Incorrect options must be plausible but still related to the Context
|
| 46 |
-
- No duplicate options
|
| 47 |
-
|
| 48 |
Return ONLY valid JSON:
|
| 49 |
-
|
| 50 |
{{
|
| 51 |
"mcqs": [
|
| 52 |
{{
|
| 53 |
"question": "string",
|
| 54 |
"options": ["opt1", "opt2", "opt3", "opt4"],
|
| 55 |
-
"answer_index": integer
|
| 56 |
"answer_source": "exact sentence from context"
|
| 57 |
}}
|
| 58 |
]
|
| 59 |
}}
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
"""
|
| 64 |
|
| 65 |
try:
|
| 66 |
|
|
|
|
| 9 |
|
| 10 |
|
| 11 |
def generate_MCQquestion(text):
|
|
|
|
| 12 |
prompt = f"""
|
| 13 |
You are a strict Arabic exam generator.
|
|
|
|
| 14 |
You MUST use ONLY the information explicitly written in the Context.
|
| 15 |
DO NOT use any external knowledge.
|
| 16 |
+
|
|
|
|
| 17 |
Context:
|
| 18 |
{text}
|
| 19 |
+
|
| 20 |
Generate MCQs in Arabic based on the length of the Context.
|
| 21 |
+
|
| 22 |
Question count rules:
|
| 23 |
+
- Very short context (< 100 words): 3 questions.
|
| 24 |
+
- Short context (100β300 words): 3β5 questions.
|
| 25 |
+
- Medium context (300β700 words): 5β7 questions.
|
| 26 |
+
- Long context (> 700 words): 7β10 questions.
|
| 27 |
+
|
| 28 |
+
STRICT RULES FOR OPTIONS & ANSWERS:
|
| 29 |
+
1. **Randomize Answer Position:** The correct answer index (0-3) MUST be distributed randomly across the questions. Do NOT always place the correct answer at index 0.
|
| 30 |
+
2. **Length Consistency:** All 4 options for a single question should have roughly the same length. Do NOT make the correct answer significantly longer or more detailed than the distractors.
|
| 31 |
+
3. **Plausible Distractors:** Incorrect options must be highly plausible and derived from the context's vocabulary to challenge the student.
|
| 32 |
+
4. **Source Integrity:** Every correct answer and its "answer_source" MUST exist explicitly in the text.
|
| 33 |
+
|
| 34 |
+
STRICT QUALITY RULES:
|
| 35 |
+
- Quality over quantity.
|
| 36 |
+
- No outside knowledge or general info.
|
| 37 |
+
- If the context doesn't support the required number of questions, stop at what is factual.
|
| 38 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
Return ONLY valid JSON:
|
|
|
|
| 40 |
{{
|
| 41 |
"mcqs": [
|
| 42 |
{{
|
| 43 |
"question": "string",
|
| 44 |
"options": ["opt1", "opt2", "opt3", "opt4"],
|
| 45 |
+
"answer_index": integer (0 to 3),
|
| 46 |
"answer_source": "exact sentence from context"
|
| 47 |
}}
|
| 48 |
]
|
| 49 |
}}
|
| 50 |
+
"""
|
|
|
|
|
|
|
|
|
|
| 51 |
|
| 52 |
try:
|
| 53 |
|