SamanthaStorm commited on
Commit
7229eb1
·
verified ·
1 Parent(s): b4fd4b2

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +67 -0
app.py ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ !pip install gradio
2
+
3
+ import gradio as gr
4
+
5
+ # Define your DV detection patterns
6
+ patterns = [
7
+ {
8
+ "id": "identity_erosion_001",
9
+ "name": "Loss of Personal Joy",
10
+ "trigger_keywords": ["used to love", "don’t anymore", "haven’t done that in years", "stopped doing"],
11
+ "concern": "Identity erosion / subtle control",
12
+ "follow_up_therapist": "What made you stop?",
13
+ "follow_up_cop": "When did you stop doing that, and did anyone tell you not to?",
14
+ "insight": "Loss of joyful or self-expressive activities may reflect identity suppression or partner-based discouragement.",
15
+ "escalation": "Moderate"
16
+ },
17
+ {
18
+ "id": "economic_control_001",
19
+ "name": "Self-Denial Framed as Budgeting",
20
+ "trigger_keywords": ["we can’t afford", "not in the budget", "no money for that"],
21
+ "concern": "Covert economic control",
22
+ "follow_up_therapist": "Has there ever been something they wanted to spend money on that you didn’t think you could afford?",
23
+ "follow_up_cop": "Who decides what money gets spent on?",
24
+ "insight": "When financial limitations are selectively applied to personal growth, it's often a form of control.",
25
+ "escalation": "Moderate"
26
+ },
27
+ {
28
+ "id": "control_checkins_001",
29
+ "name": "Monitoring & Check-ins",
30
+ "trigger_keywords": ["have to check in", "need to be home by", "text when I get there"],
31
+ "concern": "Surveillance / conditional autonomy",
32
+ "follow_up_therapist": "What happens if you're late or forget to check in?",
33
+ "follow_up_cop": "What happens if you don’t check in or come home late?",
34
+ "insight": "Frequent required check-ins can signal coercive oversight or fear-based compliance.",
35
+ "escalation": "High"
36
+ },
37
+ ]
38
+
39
+ # Analysis function
40
+ def analyze_input(text, role):
41
+ role_key = "therapist" if role == "Therapist" else "cop"
42
+ input_text = text.lower()
43
+ results = []
44
+ for pattern in patterns:
45
+ if any(keyword in input_text for keyword in pattern["trigger_keywords"]):
46
+ results.append(
47
+ f"🔍 Pattern Detected: {pattern['name']}\n"
48
+ f"Concern: {pattern['concern']}\n"
49
+ f"Follow-Up Question: {pattern[f'follow_up_{role_key}']}\n"
50
+ f"Insight: {pattern['insight']}\n"
51
+ f"Escalation Risk: {pattern['escalation']}\n"
52
+ )
53
+ if not results:
54
+ return "No clear abuse pattern detected. Continue listening for contradictions, self-blame, or fear-based justifications."
55
+ return "\n\n".join(results)
56
+
57
+ # Build UI
58
+ gr.Interface(
59
+ fn=analyze_input,
60
+ inputs=[
61
+ gr.Textbox(lines=4, label="What did the person say?"),
62
+ gr.Radio(["Therapist", "Law Enforcement"], label="Your Role")
63
+ ],
64
+ outputs="text",
65
+ title="DV Pattern Recognition Tool (Prototype)",
66
+ description="Enter a client or witness quote. The tool flags DV-related behavioral cues and suggests follow-up questions based on your role."
67
+ ).launch()