Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -2,9 +2,9 @@ import gradio as gr
|
|
2 |
import pandas as pd
|
3 |
from mcq_generator import ImprovedMCQGenerator, is_suitable_for_students
|
4 |
import io
|
5 |
-
import tempfile
|
6 |
-
import os
|
7 |
|
|
|
|
|
8 |
|
9 |
def generate_mcqs_ui(paragraph, num_questions):
|
10 |
if not paragraph.strip():
|
@@ -14,6 +14,7 @@ def generate_mcqs_ui(paragraph, num_questions):
|
|
14 |
return None, None, "β The paragraph is not suitable for MCQ generation (due to bias/toxicity/short length)."
|
15 |
|
16 |
try:
|
|
|
17 |
mcqs = mcq_generator.generate_mcqs(paragraph, num_questions)
|
18 |
|
19 |
# Create pretty formatted MCQ list
|
@@ -67,5 +68,36 @@ def generate_mcqs_ui(paragraph, num_questions):
|
|
67 |
return None, None, f"β Error generating MCQs: {str(e)}"
|
68 |
|
69 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
70 |
demo.launch(share=True, server_name="0.0.0.0", server_port=7860)
|
71 |
-
|
|
|
2 |
import pandas as pd
|
3 |
from mcq_generator import ImprovedMCQGenerator, is_suitable_for_students
|
4 |
import io
|
|
|
|
|
5 |
|
6 |
+
# Initialize MCQ Generator
|
7 |
+
mcq_generator = ImprovedMCQGenerator()
|
8 |
|
9 |
def generate_mcqs_ui(paragraph, num_questions):
|
10 |
if not paragraph.strip():
|
|
|
14 |
return None, None, "β The paragraph is not suitable for MCQ generation (due to bias/toxicity/short length)."
|
15 |
|
16 |
try:
|
17 |
+
# Generate MCQs using the generator
|
18 |
mcqs = mcq_generator.generate_mcqs(paragraph, num_questions)
|
19 |
|
20 |
# Create pretty formatted MCQ list
|
|
|
68 |
return None, None, f"β Error generating MCQs: {str(e)}"
|
69 |
|
70 |
|
71 |
+
# Define Gradio interface
|
72 |
+
with gr.Blocks() as demo:
|
73 |
+
gr.Markdown("<h1 style='text-align:center;'>π Smart MCQ Generator</h1>")
|
74 |
+
|
75 |
+
# Input for the paragraph and number of questions
|
76 |
+
with gr.Row():
|
77 |
+
paragraph_input = gr.Textbox(lines=8, label="Enter Paragraph for MCQs", placeholder="Paste your study material here...")
|
78 |
+
with gr.Row():
|
79 |
+
num_questions_slider = gr.Slider(1, 10, step=1, value=5, label="Number of Questions")
|
80 |
+
|
81 |
+
# Generate Button
|
82 |
+
with gr.Row():
|
83 |
+
generate_btn = gr.Button("π Generate MCQs")
|
84 |
+
|
85 |
+
# Status box to show the message (success/error)
|
86 |
+
status = gr.Textbox(label="Status", interactive=False)
|
87 |
+
|
88 |
+
# MCQ output and download links
|
89 |
+
with gr.Row():
|
90 |
+
mcq_output = gr.HTML()
|
91 |
+
|
92 |
+
with gr.Row():
|
93 |
+
download_output = gr.File(label="Download MCQs (TXT/CSV)")
|
94 |
+
|
95 |
+
# Set up the button to trigger MCQ generation
|
96 |
+
generate_btn.click(
|
97 |
+
fn=generate_mcqs_ui,
|
98 |
+
inputs=[paragraph_input, num_questions_slider],
|
99 |
+
outputs=[mcq_output, download_output, status]
|
100 |
+
)
|
101 |
+
|
102 |
+
# Launch the app
|
103 |
demo.launch(share=True, server_name="0.0.0.0", server_port=7860)
|
|