Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -3,6 +3,7 @@ import torch
|
|
3 |
import numpy as np
|
4 |
from transformers import AutoModelForSequenceClassification, AutoTokenizer
|
5 |
from transformers import RobertaForSequenceClassification, RobertaTokenizer
|
|
|
6 |
|
7 |
# custom fine-tuned sentiment model
|
8 |
sentiment_model = AutoModelForSequenceClassification.from_pretrained("SamanthaStorm/tether-sentiment")
|
@@ -78,9 +79,12 @@ def interpret_abuse_level(score):
|
|
78 |
|
79 |
def analyze_messages(input_text, risk_flags):
|
80 |
input_text = input_text.strip()
|
81 |
-
|
82 |
return "Please enter a message for analysis."
|
83 |
|
|
|
|
|
|
|
84 |
sentiment = custom_sentiment(input_text)
|
85 |
sentiment_label = sentiment['label']
|
86 |
sentiment_score = sentiment['score']
|
@@ -136,7 +140,10 @@ def analyze_messages(input_text, risk_flags):
|
|
136 |
result += "\n\n⚠️ You indicated the following:\n" + "\n".join([f"• {flag}" for flag in contextual_flags])
|
137 |
if high_risk_context:
|
138 |
result += "\n\n🚨 These responses suggest a high-risk situation. Consider seeking immediate help or safety planning resources."
|
139 |
-
|
|
|
|
|
|
|
140 |
return result
|
141 |
|
142 |
iface = gr.Interface(
|
|
|
3 |
import numpy as np
|
4 |
from transformers import AutoModelForSequenceClassification, AutoTokenizer
|
5 |
from transformers import RobertaForSequenceClassification, RobertaTokenizer
|
6 |
+
from motif_tagging import tag_motifs
|
7 |
|
8 |
# custom fine-tuned sentiment model
|
9 |
sentiment_model = AutoModelForSequenceClassification.from_pretrained("SamanthaStorm/tether-sentiment")
|
|
|
79 |
|
80 |
def analyze_messages(input_text, risk_flags):
|
81 |
input_text = input_text.strip()
|
82 |
+
if not input_text:
|
83 |
return "Please enter a message for analysis."
|
84 |
|
85 |
+
motif_tags, matched_phrases = tag_motifs(input_text)
|
86 |
+
contextual_flags = risk_flags + motif_tags # Combine checkbox and motif flags
|
87 |
+
|
88 |
sentiment = custom_sentiment(input_text)
|
89 |
sentiment_label = sentiment['label']
|
90 |
sentiment_score = sentiment['score']
|
|
|
140 |
result += "\n\n⚠️ You indicated the following:\n" + "\n".join([f"• {flag}" for flag in contextual_flags])
|
141 |
if high_risk_context:
|
142 |
result += "\n\n🚨 These responses suggest a high-risk situation. Consider seeking immediate help or safety planning resources."
|
143 |
+
if matched_phrases:
|
144 |
+
result += "\n\n🧠 Detected High-Risk Language:\n"
|
145 |
+
for label, pattern in matched_phrases:
|
146 |
+
result += f"• {label.replace('_', ' ').title()} phrase matched\n"
|
147 |
return result
|
148 |
|
149 |
iface = gr.Interface(
|