mocktestgen commited on
Commit
b72ff58
·
verified ·
1 Parent(s): d2fa8cd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -10
app.py CHANGED
@@ -2,18 +2,17 @@ import gradio as gr
2
  from transformers import pipeline
3
  question_gen = pipeline("text2text-generation", model="valhalla/t5-base-qg-hl")
4
 
5
- def generate_questions(input_text, num_questions, question_type):
6
- highlighted_text = input_text
7
- if question_type == "mcq":
8
- prefix = "generate questions:"
9
- elif question_type == "subjective":
10
- prefix = "generate descriptive questions:"
11
  else:
12
- prefix = "generate questions:"
13
- prompt = f"{prefix} {highlighted_text}"
14
- questions = question_gen(prompt, max_length=64, num_return_sequences=num_questions)
15
- return [q['generated_text'] for q in questions]
16
 
 
 
 
17
  with gr.Blocks() as demo:
18
  gr.Markdown("# AI Mock Test Generator")
19
  input_text = gr.Textbox(lines=10, label="Paste text or content here")
 
2
  from transformers import pipeline
3
  question_gen = pipeline("text2text-generation", model="valhalla/t5-base-qg-hl")
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")