mocktestgen commited on
Commit
4418e3f
·
verified ·
1 Parent(s): 5c0f704

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -12
app.py CHANGED
@@ -1,24 +1,22 @@
1
  import gradio as gr
2
  from transformers import pipeline
 
 
3
  question_gen = pipeline("text2text-generation", model="iarfmoose/t5-base-question-generator")
4
 
 
5
  def generate_questions(text, num_questions, question_type):
6
- # Insert highlight tags around the first sentence for question generation
7
- sentences = text.split('.')
8
- if len(sentences) > 1:
9
- highlighted = f"<hl> {sentences[0].strip()} <hl>." + '.'.join(sentences[1:])
10
- else:
11
- highlighted = f"<hl> {text.strip()} <hl>"
12
-
13
- prompt = f"generate questions: {highlighted}"
14
  results = question_gen(prompt, max_length=128, num_return_sequences=num_questions)
15
  return "\n\n".join([f"{i+1}. {r['generated_text']}" for i, r in enumerate(results)])
 
 
16
  with gr.Blocks() as demo:
17
  gr.Markdown("# AI Mock Test Generator")
18
- input_text = gr.Textbox(lines=10, label="Paste text or content here")
19
- num_questions = gr.Slider(minimum=1, maximum=10, value=5, label="Number of Questions")
20
- question_type = gr.Radio(choices=["mcq", "subjective", "mixed"], value="mixed", label="Question Type")
21
- output = gr.Textbox(label="Generated Questions", lines=10)
22
  btn = gr.Button("Generate")
23
  btn.click(fn=generate_questions, inputs=[input_text, num_questions, question_type], outputs=output)
24
 
 
1
  import gradio as gr
2
  from transformers import pipeline
3
+
4
+ # Load the question generation model
5
  question_gen = pipeline("text2text-generation", model="iarfmoose/t5-base-question-generator")
6
 
7
+ # Function to generate questions
8
  def generate_questions(text, num_questions, question_type):
9
+ prompt = f"generate questions: {text}"
 
 
 
 
 
 
 
10
  results = question_gen(prompt, max_length=128, num_return_sequences=num_questions)
11
  return "\n\n".join([f"{i+1}. {r['generated_text']}" for i, r in enumerate(results)])
12
+
13
+ # Gradio app
14
  with gr.Blocks() as demo:
15
  gr.Markdown("# AI Mock Test Generator")
16
+ input_text = gr.Textbox(lines=10, label="Paste your study material here")
17
+ num_questions = gr.Slider(minimum=1, maximum=5, value=3, label="Number of Questions")
18
+ question_type = gr.Radio(["subjective"], value="subjective", label="Question Type (only subjective supported now)")
19
+ output = gr.Textbox(label="Generated Questions")
20
  btn = gr.Button("Generate")
21
  btn.click(fn=generate_questions, inputs=[input_text, num_questions, question_type], outputs=output)
22