thuyentruong commited on
Commit
feda098
·
verified ·
1 Parent(s): 4b09d8f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -2
app.py CHANGED
@@ -4,6 +4,7 @@ from transformers import AutoModelForSeq2SeqLM
4
  from transformers import AutoTokenizer
5
  from transformers import GenerationConfig
6
  import re
 
7
  model_name='google/flan-t5-base'
8
  model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
9
  tokenizer = AutoTokenizer.from_pretrained(model_name, use_fast=True)
@@ -21,9 +22,11 @@ Sentiment analysis:
21
  Sentiments: Negative
22
  PPrint Key words: tired, long process
23
  """
 
24
  def make_prompt(sentence):
25
  prompt = Examples_to_teach_model+ "Text: " + sentence + "Sentiment analysis:"
26
  return prompt
 
27
  def split_conj(text):
28
  return re.sub('(but|yet|although|however|nevertheless|on the other hand|still|though)', "|", text).split('|')
29
 
@@ -48,13 +51,19 @@ def get_sentiment_from_llm(review_text):
48
  skip_special_tokens=True)
49
  ls_outputs.append("\n".join(output.split('PPrint ')))
50
  return "\n".join(ls_outputs)
 
51
  demo = gr.Blocks()
52
  sentiment_extr = gr.Interface(
53
  fn=get_sentiment_from_llm,
54
  inputs=gr.Textbox(label="Text input", type="text"),
55
  outputs=gr.Textbox(label="Sentiments", type="text"),
56
- title="Sentiments analysis",
57
- description="Sentiment analysis and keywords extraction. Powered by prompt tuned flan-t5 from Google. <br> The model is run on small CPU. Please allow 2-3 minutes for longer inputs.",
 
 
 
 
 
58
  )
59
  with demo:
60
  gr.TabbedInterface([sentiment_extr], ["Sentiment text analysis"])
 
4
  from transformers import AutoTokenizer
5
  from transformers import GenerationConfig
6
  import re
7
+
8
  model_name='google/flan-t5-base'
9
  model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
10
  tokenizer = AutoTokenizer.from_pretrained(model_name, use_fast=True)
 
22
  Sentiments: Negative
23
  PPrint Key words: tired, long process
24
  """
25
+
26
  def make_prompt(sentence):
27
  prompt = Examples_to_teach_model+ "Text: " + sentence + "Sentiment analysis:"
28
  return prompt
29
+
30
  def split_conj(text):
31
  return re.sub('(but|yet|although|however|nevertheless|on the other hand|still|though)', "|", text).split('|')
32
 
 
51
  skip_special_tokens=True)
52
  ls_outputs.append("\n".join(output.split('PPrint ')))
53
  return "\n".join(ls_outputs)
54
+
55
  demo = gr.Blocks()
56
  sentiment_extr = gr.Interface(
57
  fn=get_sentiment_from_llm,
58
  inputs=gr.Textbox(label="Text input", type="text"),
59
  outputs=gr.Textbox(label="Sentiments", type="text"),
60
+ title="Sentiment analysis and keywords extraction",
61
+ description=""""
62
+ Enter one or two sentence into the Text Input and click enter to see the sentiments extracted. <br>
63
+ For longer input, please allow 2-3 minutes as the model is running on small CPU. <br>
64
+ Base model: Flan-t5 from Google. <br>
65
+ Prompt tuned by Thuyen Truong for sentiment extraction.
66
+ """
67
  )
68
  with demo:
69
  gr.TabbedInterface([sentiment_extr], ["Sentiment text analysis"])