skylord commited on
Commit
3255f31
1 Parent(s): b56b900
Files changed (1) hide show
  1. app.py +5 -3
app.py CHANGED
@@ -4,6 +4,8 @@ from gradio.components import Textbox
4
 
5
  # Load the sentiment analysis pipeline with DistilBERT
6
  distilbert_pipeline = pipeline("sentiment-analysis", model="distilbert-base-uncased-finetuned-sst-2-english")
 
 
7
 
8
  def predict_sentiment(text):
9
  """
@@ -12,15 +14,15 @@ def predict_sentiment(text):
12
  :return: str, predicted sentiment and confidence score.
13
  """
14
  result = distilbert_pipeline(text)[0]
15
- label = result['label']
16
  score = result['score']
17
- return f"Sentiment: {label}, Confidence: {score:.2f}"
18
 
19
  input1 = Textbox(lines=2, placeholder="Type your text here...")
20
 
21
  # Create a Gradio interface
22
  iface = gr.Interface(fn=predict_sentiment,
23
- inputs=input1
24
  outputs="text",
25
  title="Talk2Loop Sensitive statement tags",
26
  description="This model predicts the sensitivity of the input text. Enter a sentence to see if it's sensitive or not.")
 
4
 
5
  # Load the sentiment analysis pipeline with DistilBERT
6
  distilbert_pipeline = pipeline("sentiment-analysis", model="distilbert-base-uncased-finetuned-sst-2-english")
7
+ label_map = {"POSITIVE":"OTHER", "NEGATIVE":"SENSITIVE"}
8
+
9
 
10
  def predict_sentiment(text):
11
  """
 
14
  :return: str, predicted sentiment and confidence score.
15
  """
16
  result = distilbert_pipeline(text)[0]
17
+ label = label_map[result['label']]
18
  score = result['score']
19
+ return f"TAG: {label}, Confidence: {score:.2f}"
20
 
21
  input1 = Textbox(lines=2, placeholder="Type your text here...")
22
 
23
  # Create a Gradio interface
24
  iface = gr.Interface(fn=predict_sentiment,
25
+ inputs=input1,
26
  outputs="text",
27
  title="Talk2Loop Sensitive statement tags",
28
  description="This model predicts the sensitivity of the input text. Enter a sentence to see if it's sensitive or not.")