Spaces:
Runtime error
Runtime error
Commit
·
f957ae9
1
Parent(s):
7508c57
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import AutoModelWithLMHead, AutoTokenizer
|
2 |
+
import gradio as grad
|
3 |
+
|
4 |
+
text2text_tkn = AutoTokenizer.from_pretrained('mrm8488/t5-base-finetuned-question-generation-ap')
|
5 |
+
mdl = AutoModelWithLMHead.from_pretrained('mrm8488/t5-base-finetuned-question-generation-ap')
|
6 |
+
|
7 |
+
def text2text(context, answer):
|
8 |
+
input_text = "answer: %s context: %s </s>" % (answer, context)
|
9 |
+
features = text2text_tkn([input_text], return_tensors = 'pt')
|
10 |
+
output = mdl.generate(
|
11 |
+
input_ids = features['input_ids'],
|
12 |
+
attention_mask = features['attention_mask'],
|
13 |
+
max_length = 64
|
14 |
+
)
|
15 |
+
response = text2text_tkn.decode(output[0])
|
16 |
+
|
17 |
+
return response
|
18 |
+
|
19 |
+
context = grad.Textbox(lines = 10, label = 'English', placeholder = 'Context')
|
20 |
+
ans = grad.Textbox(lines = 1, label = 'Answer')
|
21 |
+
out = grad.Textbox(lines = 1, label = 'Generated Question')
|
22 |
+
grad.Interface(
|
23 |
+
text2text,
|
24 |
+
inputs = [context, ans],
|
25 |
+
outputs = out
|
26 |
+
).lanuch()
|