rameshmoorthy commited on
Commit
528a43d
·
verified ·
1 Parent(s): a3d4b9a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -5
app.py CHANGED
@@ -83,11 +83,19 @@ def retrieve_and_generate_quiz(question_difficulty, topic):
83
  documents_str = '\n'.join(documents)
84
  quiz_data = generate_quiz_data(question_difficulty, topic, documents_str)
85
  if not quiz_data or not quiz_data.items:
86
- return "Error: Failed to generate quiz."
87
 
88
- # Display only the questions as plain text
89
- questions = [f"{i}. {item.question}" for i, item in enumerate(quiz_data.items[:10], 1)]
90
- return "\n".join(questions)
 
 
 
 
 
 
 
 
91
 
92
  with gr.Blocks(title="Quiz Generator Test") as QUIZBOT:
93
  with gr.Row():
@@ -97,7 +105,7 @@ with gr.Blocks(title="Quiz Generator Test") as QUIZBOT:
97
  difficulty_radio = gr.Radio(["easy", "average", "hard"], label="How difficult should the quiz be?")
98
 
99
  generate_quiz_btn = gr.Button("Generate Quiz")
100
- quiz_output = gr.Textbox(label="Quiz Questions", interactive=False)
101
 
102
  # Register the click event without @ decorator
103
  generate_quiz_btn.click(
 
83
  documents_str = '\n'.join(documents)
84
  quiz_data = generate_quiz_data(question_difficulty, topic, documents_str)
85
  if not quiz_data or not quiz_data.items:
86
+ return gr.update(value="Error: Failed to generate quiz.", visible=True)
87
 
88
+ # Generate HTML for questions and choices
89
+ html_content = "<div style='font-family: Arial, sans-serif; padding: 10px;'>"
90
+ for i, item in enumerate(quiz_data.items[:10], 1):
91
+ html_content += f"<h3>Question {i}: {item.question}</h3>"
92
+ html_content += "<ul style='list-style-type: none;'>"
93
+ for j, choice in enumerate(item.choices, 1):
94
+ html_content += f"<li>C{j}: {choice}</li>"
95
+ html_content += "</ul>"
96
+ html_content += "</div>"
97
+
98
+ return gr.update(value=html_content, visible=True)
99
 
100
  with gr.Blocks(title="Quiz Generator Test") as QUIZBOT:
101
  with gr.Row():
 
105
  difficulty_radio = gr.Radio(["easy", "average", "hard"], label="How difficult should the quiz be?")
106
 
107
  generate_quiz_btn = gr.Button("Generate Quiz")
108
+ quiz_output = gr.HTML(visible=False)
109
 
110
  # Register the click event without @ decorator
111
  generate_quiz_btn.click(