Spaces:
Runtime error
Runtime error
Update app.py
Browse filesT5 task sentiment analysis
app.py
CHANGED
@@ -281,24 +281,44 @@
|
|
281 |
#-----------------------------------------------------------------------------------
|
282 |
# 12. Text-to-Text Generation using the T5 model - Task 3 Translation.
|
283 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
284 |
from transformers import T5ForConditionalGeneration, T5Tokenizer
|
285 |
import gradio as grad
|
286 |
|
287 |
text2text_tkn= T5Tokenizer.from_pretrained("t5-small")
|
288 |
mdl = T5ForConditionalGeneration.from_pretrained("t5-small")
|
289 |
|
290 |
-
def
|
291 |
-
|
292 |
-
# inp = "translate English to German:: "+text
|
293 |
-
# English to Frendh
|
294 |
-
inp = "translate English to French:: " +text
|
295 |
enc = text2text_tkn(inp, return_tensors="pt")
|
296 |
tokens = mdl.generate(**enc)
|
297 |
response=text2text_tkn.batch_decode(tokens)
|
298 |
return response
|
299 |
|
300 |
para=grad.Textbox(lines=1, label="English Text", placeholder="Text in English")
|
301 |
-
out=grad.Textbox(lines=1, label="
|
302 |
-
|
303 |
-
grad.Interface(text2text_translation, inputs=para, outputs=out).launch()
|
304 |
|
|
|
|
281 |
#-----------------------------------------------------------------------------------
|
282 |
# 12. Text-to-Text Generation using the T5 model - Task 3 Translation.
|
283 |
|
284 |
+
# from transformers import T5ForConditionalGeneration, T5Tokenizer
|
285 |
+
# import gradio as grad
|
286 |
+
|
287 |
+
# text2text_tkn= T5Tokenizer.from_pretrained("t5-small")
|
288 |
+
# mdl = T5ForConditionalGeneration.from_pretrained("t5-small")
|
289 |
+
|
290 |
+
# def text2text_translation(text):
|
291 |
+
# # English to German
|
292 |
+
# # inp = "translate English to German:: "+text
|
293 |
+
# # English to Frendh
|
294 |
+
# inp = "translate English to French:: " +text
|
295 |
+
# enc = text2text_tkn(inp, return_tensors="pt")
|
296 |
+
# tokens = mdl.generate(**enc)
|
297 |
+
# response=text2text_tkn.batch_decode(tokens)
|
298 |
+
# return response
|
299 |
+
|
300 |
+
# para=grad.Textbox(lines=1, label="English Text", placeholder="Text in English")
|
301 |
+
# out=grad.Textbox(lines=1, label="French Translation")
|
302 |
+
|
303 |
+
# grad.Interface(text2text_translation, inputs=para, outputs=out).launch()
|
304 |
+
|
305 |
+
#-----------------------------------------------------------------------------------
|
306 |
+
# 13. Text-to-Text Generation using the T5 model - Task 4 sentiment analysis.
|
307 |
+
|
308 |
from transformers import T5ForConditionalGeneration, T5Tokenizer
|
309 |
import gradio as grad
|
310 |
|
311 |
text2text_tkn= T5Tokenizer.from_pretrained("t5-small")
|
312 |
mdl = T5ForConditionalGeneration.from_pretrained("t5-small")
|
313 |
|
314 |
+
def text2text_sentiment(text):
|
315 |
+
inp = "sst2 sentence: "+text
|
|
|
|
|
|
|
316 |
enc = text2text_tkn(inp, return_tensors="pt")
|
317 |
tokens = mdl.generate(**enc)
|
318 |
response=text2text_tkn.batch_decode(tokens)
|
319 |
return response
|
320 |
|
321 |
para=grad.Textbox(lines=1, label="English Text", placeholder="Text in English")
|
322 |
+
out=grad.Textbox(lines=1, label="Sentiment")
|
|
|
|
|
323 |
|
324 |
+
grad.Interface(text2text_sentiment, inputs=para, outputs=out).launch()
|