Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -2,17 +2,17 @@ from transformers import T5ForConditionalGeneration, T5Tokenizer
|
|
2 |
import gradio as gr
|
3 |
|
4 |
model_name = "t5-small"
|
5 |
-
|
6 |
model = T5ForConditionalGeneration.from_pretrained(model_name)
|
7 |
|
8 |
def text2text_sentiment(text):
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
|
15 |
-
|
|
|
16 |
out = gr.Textbox(lines=1, label="Sentiment")
|
17 |
-
|
18 |
-
gr.Interface(text2text_sentiment, inputs=in_para, outputs=out)
|
|
|
2 |
import gradio as gr
|
3 |
|
4 |
model_name = "t5-small"
|
5 |
+
text2text_token= T5Tokenizer.from_pretrained(model_name)
|
6 |
model = T5ForConditionalGeneration.from_pretrained(model_name)
|
7 |
|
8 |
def text2text_sentiment(text):
|
9 |
+
input = "sst2 sentence: " + text
|
10 |
+
encoded = text2text_token(input, return_tensors="pt")
|
11 |
+
tokens = model.generate(**encoded)
|
12 |
+
response = text2text_token.batch_decode(tokens)
|
13 |
+
return response
|
14 |
|
15 |
+
# UX
|
16 |
+
in_para = gr.Textbox(lines=1, label="Input text in English", placeholder="Place your text in English...")
|
17 |
out = gr.Textbox(lines=1, label="Sentiment")
|
18 |
+
grad.Interface(text2text_sentiment, inputs=in_para, outputs=out).launch()
|
|