Spaces:
Runtime error
Runtime error
Upload 2 files
Browse files
app.py
CHANGED
@@ -1,25 +1,26 @@
|
|
1 |
-
# app.py
|
2 |
-
|
3 |
import gradio as gr
|
4 |
from transformers import pipeline
|
5 |
|
6 |
-
#
|
7 |
-
question_generator = pipeline("
|
8 |
|
9 |
def generate_questions(text):
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
|
|
|
|
16 |
|
17 |
-
|
|
|
18 |
fn=generate_questions,
|
19 |
-
inputs=gr.Textbox(lines=
|
20 |
-
outputs=
|
21 |
-
title="
|
22 |
-
description="
|
23 |
)
|
24 |
|
25 |
-
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
|
4 |
+
# β
Use the correct pipeline task
|
5 |
+
question_generator = pipeline("text2text-generation", model="valhalla/t5-base-e2e-qg")
|
6 |
|
7 |
def generate_questions(text):
|
8 |
+
# Split text into chunks (optional)
|
9 |
+
chunks = text.split(". ")
|
10 |
+
questions = []
|
11 |
+
for chunk in chunks:
|
12 |
+
if len(chunk.strip()) > 0:
|
13 |
+
result = question_generator(chunk, max_length=64)[0]['generated_text']
|
14 |
+
questions.append(f"β {result}")
|
15 |
+
return "\n".join(questions)
|
16 |
|
17 |
+
# Gradio interface
|
18 |
+
interface = gr.Interface(
|
19 |
fn=generate_questions,
|
20 |
+
inputs=gr.Textbox(lines=15, placeholder="Paste your long text here..."),
|
21 |
+
outputs="text",
|
22 |
+
title="π Generate Questions from Text",
|
23 |
+
description="Uses a T5 model to generate questions from a multi-sentence paragraph."
|
24 |
)
|
25 |
|
26 |
+
interface.launch()
|