mocktestgen commited on
Commit
c152e15
·
verified ·
1 Parent(s): af956aa
Files changed (1) hide show
  1. A +27 -0
A ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ question_gen = pipeline("text2text-generation", model="valhalla/t5-small-qg-hl")
5
+
6
+ def generate_questions(input_text, num_questions, question_type):
7
+ highlighted_text = input_text
8
+ if question_type == "mcq":
9
+ prefix = "generate questions:"
10
+ elif question_type == "subjective":
11
+ prefix = "generate descriptive questions:"
12
+ else:
13
+ prefix = "generate questions:"
14
+ prompt = f"{prefix} {highlighted_text}"
15
+ questions = question_gen(prompt, max_length=64, num_return_sequences=num_questions)
16
+ return [q['generated_text'] for q in questions]
17
+
18
+ with gr.Blocks() as demo:
19
+ gr.Markdown("# AI Mock Test Generator")
20
+ input_text = gr.Textbox(lines=10, label="Paste text or content here")
21
+ num_questions = gr.Slider(minimum=1, maximum=10, value=5, label="Number of Questions")
22
+ question_type = gr.Radio(choices=["mcq", "subjective", "mixed"], value="mixed", label="Question Type")
23
+ output = gr.Textbox(label="Generated Questions", lines=10)
24
+ btn = gr.Button("Generate")
25
+ btn.click(fn=generate_questions, inputs=[input_text, num_questions, question_type], outputs=output)
26
+
27
+ demo.launch()