Spaces:
Runtime error
Runtime error
hf-dongpyo
commited on
Commit
•
c2dbaac
1
Parent(s):
8a39aa7
Update app.py
Browse files
app.py
CHANGED
@@ -1,8 +1,13 @@
|
|
1 |
from transformers import AutoModelWithLMHead, AutoTokenizer
|
2 |
import gradio as grad
|
3 |
|
4 |
-
|
5 |
-
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
def text2text(context, answer):
|
8 |
input_text = "answer: %s context: %s </s>" % (answer, context)
|
@@ -16,11 +21,32 @@ def text2text(context, answer):
|
|
16 |
|
17 |
return response
|
18 |
|
19 |
-
|
20 |
-
|
21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
grad.Interface(
|
23 |
-
|
24 |
-
inputs = [context, ans],
|
|
|
|
|
25 |
outputs = out
|
26 |
).launch()
|
|
|
1 |
from transformers import AutoModelWithLMHead, AutoTokenizer
|
2 |
import gradio as grad
|
3 |
|
4 |
+
# make a question
|
5 |
+
# text2text_tkn = AutoTokenizer.from_pretrained('mrm8488/t5-base-finetuned-question-generation-ap')
|
6 |
+
# mdl = AutoModelWithLMHead.from_pretrained('mrm8488/t5-base-finetuned-question-generation-ap')
|
7 |
+
|
8 |
+
# summarize
|
9 |
+
text2text_tkn = AutoTokenizer.from_pretrained('deep-learning-analytics/wikihow-t5-small')
|
10 |
+
mdl = AutoModelWithLMHead.from_pretrained('deep-learning-analytics/wikihow-t5-small')
|
11 |
|
12 |
def text2text(context, answer):
|
13 |
input_text = "answer: %s context: %s </s>" % (answer, context)
|
|
|
21 |
|
22 |
return response
|
23 |
|
24 |
+
def text2text_summary(para):
|
25 |
+
initial_txt = para.strip().replace("\n", "")
|
26 |
+
tkn_text = text2text_tkn.encode(initial_txt, return_tensors = 'pt')
|
27 |
+
tkn_ids = mdl.generate(
|
28 |
+
tkn_text,
|
29 |
+
max_length = 250,
|
30 |
+
num_beams = 5,
|
31 |
+
repetition_penalty = 2.5,
|
32 |
+
early_stopping = True
|
33 |
+
)
|
34 |
+
|
35 |
+
response = text2text_tkn.encode(tkn_ids[0], skip_special_tokens = True)
|
36 |
+
|
37 |
+
return response
|
38 |
+
|
39 |
+
# context = grad.Textbox(lines = 10, label = 'English', placeholder = 'Context')
|
40 |
+
# ans = grad.Textbox(lines = 1, label = 'Answer')
|
41 |
+
# out = grad.Textbox(lines = 1, label = 'Generated Question')
|
42 |
+
|
43 |
+
para = grad.Textbox(lines = 10, label = 'Paragraph', placeholder = 'Copy paragraph')
|
44 |
+
out = grad.Textbox(lines = 1, label = 'Summary')
|
45 |
+
|
46 |
grad.Interface(
|
47 |
+
# text2text,
|
48 |
+
# inputs = [context, ans],
|
49 |
+
text2text_summary,
|
50 |
+
inputs = para,
|
51 |
outputs = out
|
52 |
).launch()
|