capradeepgujaran commited on
Commit
fcbe222
·
verified ·
1 Parent(s): 076d2e7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +44 -0
app.py CHANGED
@@ -490,6 +490,50 @@ class QuizApp:
490
  <p>You need 80% or higher to pass and receive a certificate.</p>
491
  </div>
492
  """
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
493
  def create_quiz_interface():
494
  if not os.getenv("GROQ_API_KEY"):
495
  raise EnvironmentError("Please set your GROQ_API_KEY environment variable")
 
490
  <p>You need 80% or higher to pass and receive a certificate.</p>
491
  </div>
492
  """
493
+ def on_generate_questions(text: str, num_questions: int) -> List:
494
+ """Generate quiz questions and setup initial state"""
495
+ success, questions = quiz_app.generate_questions(text, num_questions)
496
+
497
+ # Handle failure case
498
+ if not success or not questions:
499
+ return [
500
+ "", # question_display
501
+ gr.update(choices=[], visible=False), # current_options
502
+ "", # question_counter
503
+ gr.update(visible=False), # question_box
504
+ [], # current_questions
505
+ 0, # current_question_idx
506
+ [None] * 5, # answer_state
507
+ gr.Tabs(selected=2), # tabs - navigate to assessment tab
508
+ gr.update(visible=False), # results_group
509
+ gr.update(visible=False) # view_cert_btn
510
+ ]
511
+
512
+ # Setup initial state with first question
513
+ initial_answers = [None] * len(questions)
514
+ question = questions[0]
515
+ question_html = f"""
516
+ # Question 1 of {len(questions)}
517
+
518
+ {question.question}
519
+ """
520
+
521
+ return [
522
+ question_html, # question_display
523
+ gr.update(
524
+ choices=question.options,
525
+ value=None,
526
+ visible=True,
527
+ label="Select your answer:"
528
+ ), # current_options
529
+ f"Question 1 of {len(questions)}", # question_counter
530
+ gr.update(visible=True), # question_box
531
+ questions, # current_questions
532
+ 0, # current_question_idx
533
+ initial_answers, # answer_state
534
+ gr.Tabs(selected=2), # tabs - navigate to assessment tab
535
+ gr.update(visible=False), # results_group
536
+ gr.update(visible=False) # view_cert_btn
537
  def create_quiz_interface():
538
  if not os.getenv("GROQ_API_KEY"):
539
  raise EnvironmentError("Please set your GROQ_API_KEY environment variable")