run480 commited on
Commit
17f7791
·
verified ·
1 Parent(s): 3ea16af

Update app.py

Browse files

T5 task grammar check

Files changed (1) hide show
  1. app.py +25 -4
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 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()
 
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()