Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -63,7 +63,8 @@ EXPLANATIONS = {
|
|
63 |
"guilt_tripping": "Guilt-tripping involves making someone feel guilty or responsible for things they didn’t do, often to manipulate their behavior.",
|
64 |
"emotional_manipulation": "Emotional manipulation is using guilt, fear, or emotional dependency to control another person’s thoughts, feelings, or actions.",
|
65 |
"manipulation": "Manipulation refers to using deceptive tactics to control or influence someone’s emotions, decisions, or behavior to serve the manipulator’s own interests.",
|
66 |
-
"non_abusive": "Non-abusive language is communication that is respectful, empathetic, and free of harmful behaviors or manipulation."
|
|
|
67 |
}
|
68 |
|
69 |
def calculate_abuse_level(scores, thresholds):
|
@@ -84,7 +85,7 @@ def interpret_abuse_level(score):
|
|
84 |
else:
|
85 |
return "Very Low / Likely Safe"
|
86 |
|
87 |
-
def analyze_messages(input_text):
|
88 |
input_text = input_text.strip()
|
89 |
if not input_text:
|
90 |
return "Please enter a message for analysis."
|
@@ -105,6 +106,11 @@ def analyze_messages(input_text):
|
|
105 |
pattern_count = sum(score > adjusted_thresholds[label] for label, score in zip(PATTERN_LABELS, scores[:15]))
|
106 |
danger_flag_count = sum(score > adjusted_thresholds[label] for label, score in zip(DANGER_LABELS, scores[15:18]))
|
107 |
|
|
|
|
|
|
|
|
|
|
|
108 |
non_abusive_score = scores[LABELS.index('non_abusive')]
|
109 |
if non_abusive_score > adjusted_thresholds['non_abusive']:
|
110 |
return "This message is classified as non-abusive."
|
@@ -140,7 +146,16 @@ def analyze_messages(input_text):
|
|
140 |
|
141 |
iface = gr.Interface(
|
142 |
fn=analyze_messages,
|
143 |
-
inputs=
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
144 |
outputs=[
|
145 |
gr.Textbox(label="Analysis Result"),
|
146 |
],
|
@@ -148,4 +163,4 @@ iface = gr.Interface(
|
|
148 |
)
|
149 |
|
150 |
if __name__ == "__main__":
|
151 |
-
iface.launch()
|
|
|
63 |
"guilt_tripping": "Guilt-tripping involves making someone feel guilty or responsible for things they didn’t do, often to manipulate their behavior.",
|
64 |
"emotional_manipulation": "Emotional manipulation is using guilt, fear, or emotional dependency to control another person’s thoughts, feelings, or actions.",
|
65 |
"manipulation": "Manipulation refers to using deceptive tactics to control or influence someone’s emotions, decisions, or behavior to serve the manipulator’s own interests.",
|
66 |
+
"non_abusive": "Non-abusive language is communication that is respectful, empathetic, and free of harmful behaviors or manipulation.",
|
67 |
+
"obscure_formal": "Obscure or overly formal language used manipulatively to create confusion, avoid responsibility, or assert superiority."
|
68 |
}
|
69 |
|
70 |
def calculate_abuse_level(scores, thresholds):
|
|
|
85 |
else:
|
86 |
return "Very Low / Likely Safe"
|
87 |
|
88 |
+
def analyze_messages(input_text, risk_flags):
|
89 |
input_text = input_text.strip()
|
90 |
if not input_text:
|
91 |
return "Please enter a message for analysis."
|
|
|
106 |
pattern_count = sum(score > adjusted_thresholds[label] for label, score in zip(PATTERN_LABELS, scores[:15]))
|
107 |
danger_flag_count = sum(score > adjusted_thresholds[label] for label, score in zip(DANGER_LABELS, scores[15:18]))
|
108 |
|
109 |
+
# Incorporate risk flag count
|
110 |
+
user_risk_count = len(risk_flags)
|
111 |
+
if user_risk_count >= 2:
|
112 |
+
danger_flag_count += 1 # elevate risk signal
|
113 |
+
|
114 |
non_abusive_score = scores[LABELS.index('non_abusive')]
|
115 |
if non_abusive_score > adjusted_thresholds['non_abusive']:
|
116 |
return "This message is classified as non-abusive."
|
|
|
146 |
|
147 |
iface = gr.Interface(
|
148 |
fn=analyze_messages,
|
149 |
+
inputs=[
|
150 |
+
gr.Textbox(lines=10, placeholder="Enter message here..."),
|
151 |
+
gr.CheckboxGroup(label="Do any of these apply to your situation?", choices=[
|
152 |
+
"They've threatened harm",
|
153 |
+
"They isolate me",
|
154 |
+
"I’ve changed my behavior out of fear",
|
155 |
+
"They monitor/follow me",
|
156 |
+
"I feel unsafe when alone with them"
|
157 |
+
])
|
158 |
+
],
|
159 |
outputs=[
|
160 |
gr.Textbox(label="Analysis Result"),
|
161 |
],
|
|
|
163 |
)
|
164 |
|
165 |
if __name__ == "__main__":
|
166 |
+
iface.launch()
|