Spaces:
Runtime error
Runtime error
Commit
·
6c31d06
1
Parent(s):
a258be0
Add question generator
Browse files
app.py
CHANGED
@@ -11,5 +11,26 @@ def summarize(text):
|
|
11 |
|
12 |
return tokenizer.decode(outputs[0], skip_special_tokens=True)
|
13 |
|
14 |
-
|
15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
return tokenizer.decode(outputs[0], skip_special_tokens=True)
|
13 |
|
14 |
+
|
15 |
+
def generate_question(text):
|
16 |
+
checkpoint = "mrm8488/t5-base-finetuned-question-generation-ap"
|
17 |
+
tokenizer = AutoTokenizer.from_pretrained(checkpoint, use_fast=False)
|
18 |
+
model = AutoModelForSeq2SeqLM.from_pretrained(checkpoint)
|
19 |
+
|
20 |
+
prompt = f"answer: {text} context: {text}"
|
21 |
+
inputs = tokenizer(prompt, truncation=True, return_tensors="pt").input_ids
|
22 |
+
outputs = model.generate(inputs)
|
23 |
+
|
24 |
+
generated_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
25 |
+
|
26 |
+
_, question = generated_text.split("question: ")
|
27 |
+
|
28 |
+
return question
|
29 |
+
|
30 |
+
|
31 |
+
summarize_interface = gr.Interface(fn=summarize, inputs="text", outputs="text")
|
32 |
+
question_interface = gr.Interface(fn=generate_question, inputs="text", outputs="text")
|
33 |
+
tabs = gr.TabbedInterface(
|
34 |
+
[summarize_interface, question_interface], ["Summarize an article", "Generate a question"]
|
35 |
+
)
|
36 |
+
tabs.launch()
|