fatimataba21 commited on
Commit
07dd12c
·
1 Parent(s): ac65f3b

message de commit

Browse files
Files changed (1) hide show
  1. app.py +29 -6
app.py CHANGED
@@ -636,11 +636,34 @@ if __name__ == "__main__":
636
  app_state = AppState()
637
  app_state.reset_with_questions(questions)
638
 
639
- # Define a basic function to return the current question for demonstration
640
- def get_question():
641
- q = app_state.get_current_question()
642
- return q["question"] if q else "Fin des questions."
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
643
 
644
- # Create and launch Gradio interface
645
- demo = gr.Interface(fn=get_question, inputs=[], outputs="text", live=True)
646
  demo.launch()
 
636
  app_state = AppState()
637
  app_state.reset_with_questions(questions)
638
 
639
+ # Prepare the first question display
640
+ curr = app_state.get_current_question()
641
+ init_display = f"{curr['question']}\n\n" + "\n".join(curr["options"]) if curr else "Aucune question."
642
+
643
+ with gr.Blocks() as demo:
644
+ gr.Markdown("## Quiz de Deep Learning")
645
+ q_box = gr.Markdown(init_display)
646
+ answer_radio = gr.Radio(choices=curr["options"] if curr else [], label="Votre réponse")
647
+ message = gr.Markdown("")
648
+
649
+ def submit_answer(selected_option):
650
+ curr_q = app_state.get_current_question()
651
+ # Si pas de question courante, rien à faire.
652
+ if curr_q is None:
653
+ return q_box.update(value="Quiz terminé."), gr.Radio.update(choices=[], value=None, interactive=False), message.update(value="")
654
+ # Enregister la réponse
655
+ is_correct = (selected_option == curr_q["correct"])
656
+ app_state.add_result(curr_q, selected_option, is_correct)
657
+ nxt = app_state.next_question()
658
+ if nxt:
659
+ display = f"{nxt['question']}\n\n" + "\n".join(nxt["options"])
660
+ return q_box.update(value=display), gr.Radio.update(choices=nxt["options"], value=None), message.update(value="")
661
+ else:
662
+ stats = calculate_stats(app_state.results)
663
+ final_msg = "Quiz terminé.\n\n" + stats
664
+ return q_box.update(value=final_msg), gr.Radio.update(choices=[], value=None, interactive=False), message.update(value="")
665
+
666
+ submit_btn = gr.Button("Submit")
667
+ submit_btn.click(fn=submit_answer, inputs=answer_radio, outputs=[q_box, answer_radio, message])
668
 
 
 
669
  demo.launch()