Leen172 commited on
Commit
e28f0a3
·
verified ·
1 Parent(s): e2fd94e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +56 -5
app.py CHANGED
@@ -334,11 +334,12 @@ input[type="range"]::-webkit-slider-thumb { background:#ff7d2d; }
334
  """
335
 
336
 
 
337
  # ---------- واجهة Gradio ----------
338
  with gr.Blocks(title="Question Generator", css=CSS) as demo:
339
- gr.Markdown("<h2 style='text-align:center;margin-top:8px;'>Question Generator</h2>", elem_classes=["soft"])
340
 
341
- # القسم A: الإدخال (نص/ملف)
342
  input_group = gr.Group(visible=True)
343
  with input_group:
344
  with gr.Row():
@@ -347,8 +348,10 @@ with gr.Blocks(title="Question Generator", css=CSS) as demo:
347
  text_area = gr.Textbox(lines=10, placeholder="ألصق هنا مقطع نصي...", label=None)
348
  num_q = gr.Slider(4, 20, value=DEFAULT_NUM_QUESTIONS, step=1, label="عدد الأسئلة")
349
  with gr.Column(scale=1):
350
- file_comp = gr.File(label="اختر ملفًا", file_count="single",
351
- file_types=[".pdf",".txt"], type="filepath", elem_classes=["upload-like"])
 
 
352
  with gr.Accordion("خيارات متقدمة (لـ PDF المصوّر)", open=False):
353
  trocr_model = gr.Dropdown(
354
  choices=[
@@ -362,7 +365,55 @@ with gr.Blocks(title="Question Generator", css=CSS) as demo:
362
  trocr_zoom = gr.Slider(2.0, 3.5, value=DEFAULT_TROCR_ZOOM, step=0.1, label="Zoom OCR")
363
  btn_build = gr.Button("توليد الأسئلة", elem_classes=["button-primary"])
364
  toast = gr.Markdown("", elem_classes=["soft"])
365
- input_card = gr.Markdown("", visible=False) # placeholder
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
366
 
367
  # القسم B: الاختبار
368
  quiz_group = gr.Group(visible=False)
 
334
  """
335
 
336
 
337
+
338
  # ---------- واجهة Gradio ----------
339
  with gr.Blocks(title="Question Generator", css=CSS) as demo:
340
+ gr.Markdown("<h2 class='top-title' style='text-align:center;margin-top:8px;'>Question Generator</h2>")
341
 
342
+ # ===== القسم A: الإدخال (نص/ملف) =====
343
  input_group = gr.Group(visible=True)
344
  with input_group:
345
  with gr.Row():
 
348
  text_area = gr.Textbox(lines=10, placeholder="ألصق هنا مقطع نصي...", label=None)
349
  num_q = gr.Slider(4, 20, value=DEFAULT_NUM_QUESTIONS, step=1, label="عدد الأسئلة")
350
  with gr.Column(scale=1):
351
+ file_comp = gr.File(
352
+ label="اختر ملفًا", file_count="single",
353
+ file_types=[".pdf",".txt"], type="filepath", elem_classes=["upload-like"]
354
+ )
355
  with gr.Accordion("خيارات متقدمة (لـ PDF المصوّر)", open=False):
356
  trocr_model = gr.Dropdown(
357
  choices=[
 
365
  trocr_zoom = gr.Slider(2.0, 3.5, value=DEFAULT_TROCR_ZOOM, step=0.1, label="Zoom OCR")
366
  btn_build = gr.Button("توليد الأسئلة", elem_classes=["button-primary"])
367
  toast = gr.Markdown("", elem_classes=["soft"])
368
+
369
+ # حالة عامة للاختبار
370
+ state = gr.State(None)
371
+
372
+ # ===== القسم B: الاختبار =====
373
+ quiz_group = gr.Group(visible=False)
374
+ with quiz_group:
375
+ with gr.Row():
376
+ progress = gr.Label("", elem_classes=["progress"])
377
+ with gr.Row():
378
+ with gr.Column():
379
+ # مكوّنات السؤال
380
+ q_md = gr.Markdown("", elem_classes=["card"])
381
+ choices = gr.Radio(choices=[], label="اختر الإجابة", interactive=True, elem_classes=["radio"])
382
+ feedback = gr.Markdown("")
383
+ exp_md = gr.Markdown("")
384
+ with gr.Row():
385
+ btn_prev = gr.Button("السابق")
386
+ btn_next = gr.Button("التالي")
387
+ btn_reveal = gr.Button("إظهار الإجابة")
388
+ btn_finish = gr.Button("إنهاء الاختبار", elem_classes=["button-primary"])
389
+ btn_reset = gr.Button("العودة للواجهة", variant="secondary")
390
+
391
+ # ===== الربط المنطقي =====
392
+ # بناء الاختبار من الإدخال
393
+ btn_build.click(
394
+ build_quiz,
395
+ inputs=[text_area, file_comp, num_q, trocr_model, trocr_zoom],
396
+ outputs=[state, input_group, quiz_group, toast]
397
+ ).then(
398
+ fn=show, inputs=[state],
399
+ outputs=[q_md, choices, exp_md, feedback, progress]
400
+ )
401
+
402
+ # تفاعلات الاختبار
403
+ choices.change(lambda s, c: choose(s, c), inputs=[state, choices], outputs=[state, feedback])
404
+ btn_prev.click(prev_, inputs=[state], outputs=[state]).then(show, inputs=[state], outputs=[q_md, choices, exp_md, feedback, progress])
405
+ btn_next.click(next_, inputs=[state], outputs=[state]).then(show, inputs=[state], outputs=[q_md, choices, exp_md, feedback, progress])
406
+ btn_reveal.click(reveal, inputs=[state], outputs=[state, feedback]).then(show, inputs=[state], outputs=[q_md, choices, exp_md, feedback, progress])
407
+ btn_finish.click(finish, inputs=[state], outputs=[state, feedback])
408
+
409
+ # رجوع للواجهة الأولى
410
+ btn_reset.click(
411
+ lambda: (None, gr.update(visible=True), gr.update(visible=False), "", "", "", "", ""),
412
+ outputs=[state, input_group, quiz_group, feedback, q_md, choices, exp_md, progress]
413
+ )
414
+
415
+ if __name__ == "__main__":
416
+ demo.queue().launch()
417
 
418
  # القسم B: الاختبار
419
  quiz_group = gr.Group(visible=False)