Vinay115 commited on
Commit
373fb15
·
verified ·
1 Parent(s): 126f0cf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -3
app.py CHANGED
@@ -7,8 +7,13 @@ import sentencepiece
7
  from google.protobuf import text_format
8
  import re
9
 
10
- # Load sentiment analysis pipeline
11
- sentiment_model = pipeline("sentiment-analysis")
 
 
 
 
 
12
 
13
  # Function to analyze text and calculate risk
14
  def analyze_text(text):
@@ -17,7 +22,8 @@ def analyze_text(text):
17
  score = result['score']
18
 
19
  # Simple risk scoring logic
20
- risk_score = score * (1.5 if sentiment == "NEGATIVE" else 1.0)
 
21
  escalation = risk_score > 0.7 # threshold
22
  return sentiment, risk_score, escalation
23
 
@@ -30,6 +36,7 @@ def process_input(text):
30
  title = "SocialAegis MVP"
31
  description = """
32
  A sentiment-based escalation engine to detect emotional volatility in social media posts.
 
33
  """
34
 
35
  iface = gr.Interface(
 
7
  from google.protobuf import text_format
8
  import re
9
 
10
+ # Load multilingual social media sentiment analysis model
11
+ sentiment_model = pipeline(
12
+ "text-classification",
13
+ model="cardiffnlp/twitter-xlm-roberta-base-sentiment",
14
+ tokenizer="cardiffnlp/twitter-xlm-roberta-base-sentiment",
15
+ return_all_scores=False
16
+ )
17
 
18
  # Function to analyze text and calculate risk
19
  def analyze_text(text):
 
22
  score = result['score']
23
 
24
  # Simple risk scoring logic
25
+ # Adjusted to also flag high-intensity "negative" and "neutral" sentiment
26
+ risk_score = score * (1.5 if sentiment.upper() in ["NEGATIVE", "LABEL_0"] else 1.0)
27
  escalation = risk_score > 0.7 # threshold
28
  return sentiment, risk_score, escalation
29
 
 
36
  title = "SocialAegis MVP"
37
  description = """
38
  A sentiment-based escalation engine to detect emotional volatility in social media posts.
39
+ Now using a multilingual, social-media-trained model.
40
  """
41
 
42
  iface = gr.Interface(