Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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(
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
prefix = "generate descriptive questions:"
|
| 11 |
else:
|
| 12 |
-
|
| 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")
|