Spaces:
Runtime error
Runtime error
Update app.py
Browse filesT5 task grammar check
app.py
CHANGED
@@ -305,20 +305,41 @@
|
|
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
|
315 |
-
inp = "
|
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="
|
323 |
|
324 |
-
grad.Interface(
|
|
|
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()
|
325 |
+
|
326 |
+
#-----------------------------------------------------------------------------------
|
327 |
+
# 14. Text-to-Text Generation using the T5 model - Task 5 grammar check.
|
328 |
+
|
329 |
from transformers import T5ForConditionalGeneration, T5Tokenizer
|
330 |
import gradio as grad
|
331 |
|
332 |
text2text_tkn= T5Tokenizer.from_pretrained("t5-small")
|
333 |
mdl = T5ForConditionalGeneration.from_pretrained("t5-small")
|
334 |
|
335 |
+
def text2text_acceptable_sentence(text):
|
336 |
+
inp = "cola sentence: "+text
|
337 |
enc = text2text_tkn(inp, return_tensors="pt")
|
338 |
tokens = mdl.generate(**enc)
|
339 |
response=text2text_tkn.batch_decode(tokens)
|
340 |
return response
|
341 |
|
342 |
para=grad.Textbox(lines=1, label="English Text", placeholder="Text in English")
|
343 |
+
out=grad.Textbox(lines=1, label="Whether the sentence is acceptable or not")
|
344 |
|
345 |
+
grad.Interface(text2text_acceptable_sentence, inputs=para, outputs=out).launch()
|