mimoha commited on
Commit
a97a87b
·
verified ·
1 Parent(s): 6518593

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -11
app.py CHANGED
@@ -14,7 +14,7 @@ model = genai.GenerativeModel(MODEL_NAME)
14
 
15
  def generate_mcqs_gemini(paragraph: str, n_questions: int, n_choices: int = 4):
16
  if not paragraph or paragraph.strip() == "":
17
- return "⚠️ Please enter a paragraph first."
18
 
19
  prompt = f"""
20
  الفقرة:
@@ -48,20 +48,25 @@ def generate_mcqs_gemini(paragraph: str, n_questions: int, n_choices: int = 4):
48
  mcqs = data.get("mcqs", [])
49
 
50
  if not mcqs:
51
- return "⚠️ Could not parse MCQs."
 
 
 
 
 
52
 
53
- # تنسيق النتائج للعرض
54
- output = ""
55
  for i, q in enumerate(mcqs, 1):
56
- output += f"\nQ{i}: {q['question']}\n"
57
  for j, opt in enumerate(q["options"]):
58
- output += f" {j}) {opt}\n"
 
59
  correct_idx = q["answer_index"]
60
- output += f"✅ Correct: {q['options'][correct_idx]}\n"
61
- return output
 
62
 
63
  except Exception as e:
64
- return f"⚠️ Error while connecting to API: {e}"
65
 
66
 
67
  with gr.Blocks() as demo:
@@ -79,13 +84,14 @@ with gr.Blocks() as demo:
79
  precision=0
80
  )
81
 
82
- output = gr.Textbox(label="Generated MCQs", lines=20)
 
83
 
84
  submit_btn = gr.Button("Submit")
85
  submit_btn.click(
86
  fn=generate_mcqs_gemini,
87
  inputs=[paragraph, n_questions],
88
- outputs=output
89
  )
90
 
91
  if __name__ == "__main__":
 
14
 
15
  def generate_mcqs_gemini(paragraph: str, n_questions: int, n_choices: int = 4):
16
  if not paragraph or paragraph.strip() == "":
17
+ return " Please enter a paragraph first.", ""
18
 
19
  prompt = f"""
20
  الفقرة:
 
48
  mcqs = data.get("mcqs", [])
49
 
50
  if not mcqs:
51
+ return " Could not parse MCQs.", ""
52
+
53
+ # الأسئلة بدون الحلول
54
+ questions_text = ""
55
+ # الحلول فقط
56
+ answers_text = ""
57
 
 
 
58
  for i, q in enumerate(mcqs, 1):
59
+ questions_text += f"\nQ{i}: {q['question']}\n"
60
  for j, opt in enumerate(q["options"]):
61
+ questions_text += f" {j}) {opt}\n"
62
+
63
  correct_idx = q["answer_index"]
64
+ answers_text += f"Q{i} {q['options'][correct_idx]}\n"
65
+
66
+ return questions_text, answers_text
67
 
68
  except Exception as e:
69
+ return f" Error while connecting to API: {e}", ""
70
 
71
 
72
  with gr.Blocks() as demo:
 
84
  precision=0
85
  )
86
 
87
+ output_questions = gr.Textbox(label="Generated MCQs (without answers)", lines=20)
88
+ output_answers = gr.Textbox(label="Answers", lines=10)
89
 
90
  submit_btn = gr.Button("Submit")
91
  submit_btn.click(
92
  fn=generate_mcqs_gemini,
93
  inputs=[paragraph, n_questions],
94
+ outputs=[output_questions, output_answers]
95
  )
96
 
97
  if __name__ == "__main__":