Paraj01 commited on
Commit
254b661
·
verified ·
1 Parent(s): e0d01e1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -10
app.py CHANGED
@@ -1,21 +1,25 @@
1
  from transformers import pipeline
2
  import gradio as gr
3
 
4
- classifier = pipeline("sentiment-analysis")
5
 
6
  def classify_text(text):
7
- result=classifier(text)
8
- label=result[0]['label']
9
- score = result[0]['score']
10
-
11
- return f"{label} with score {score}"
 
 
 
 
12
 
13
  interface = gr.Interface(
14
  fn=classify_text,
15
- inputs=gr.Textbox("Write anything(*-_-)"),
16
  outputs="text",
17
- title="Serntiment Analysis",
18
- description="Enter Text to Check the Sentiment."
19
  )
20
 
21
- interface.launch(debug=True,share=True)
 
1
  from transformers import pipeline
2
  import gradio as gr
3
 
4
+ classifier = pipeline("sentiment-analysis", model="cardiffnlp/twitter-roberta-base-sentiment")
5
 
6
  def classify_text(text):
7
+ result = classifier(text)
8
+ label = result[0]['label']
9
+ if label == 'LABEL_0':
10
+ label='Negative'
11
+ if label == 'LABEL_1':
12
+ label='Neutral'
13
+ if label == 'LABEL_2':
14
+ label='Positive'
15
+ return f"{label}"
16
 
17
  interface = gr.Interface(
18
  fn=classify_text,
19
+ inputs=gr.Textbox(label="Write anything (*-_-)"),
20
  outputs="text",
21
+ title="Sentiment Analysis",
22
+ description="Enter text to check the sentiment (Positive or Negative)."
23
  )
24
 
25
+ interface.launch(debug=True, share=True)