yasserrmd commited on
Commit
4164d84
·
verified ·
1 Parent(s): 08983dc

Upload 5 files

Browse files
Files changed (5) hide show
  1. app.db +0 -0
  2. config.py +9 -0
  3. populate_db.py +135 -0
  4. requirements.txt +24 -0
  5. run.py +7 -0
app.db ADDED
Binary file (86 kB). View file
 
config.py ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+
3
+ class Config:
4
+ SECRET_KEY = os.environ.get("SECRET_KEY") or "you-will-never-guess"
5
+ SQLALCHEMY_DATABASE_URI = os.environ.get("DATABASE_URL") or \
6
+ "sqlite:///" + os.path.join(os.path.abspath(os.path.dirname(__file__)), "app.db")
7
+ SQLALCHEMY_TRACK_MODIFICATIONS = False
8
+ GROQ_API_KEY = "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"
9
+
populate_db.py ADDED
@@ -0,0 +1,135 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from app import create_app, db
2
+ from app.models import Country, Case, InterrogationSession, GeneratedQuestion, InterrogationResponse, Report, CaseStatus
3
+ import random
4
+ from datetime import datetime, timedelta
5
+
6
+ app = create_app()
7
+
8
+ # --- Helper function to generate random names ---
9
+ def generate_random_name():
10
+ first_names = ["Aaliyah", "Aarav", "Beatrix", "Bodhi", "Cassian", "Clara", "Declan", "Elara", "Felix", "Fiona", "Gideon", "Hazel", "Jasper", "Juniper", "Kai", "Luna", "Milo", "Nora", "Orion", "Ophelia", "Phoenix", "Quinn", "Rowan", "Seraphina", "Silas", "Stella", "Theodore", "Violet", "Xavier", "Zara"]
11
+ last_names = ["Abe", "Chen", "Da Silva", "El-Sayed", "Fernandez", "Garcia", "Ivanov", "Jones", "Kim", "Kowalski", "Li", "Martinez", "Müller", "Nguyen", "Okafor", "Patel", "Popescu", "Rossi", "Santos", "Schmidt", "Singh", "Smith", "Tanaka", "Tremblay", "Van Der Berg", "Williams", "Wilson", "Yamamoto", "Zhang", "Zimmerman"]
12
+ return f"{random.choice(first_names)} {random.choice(last_names)}"
13
+
14
+ # --- Helper function to generate random text ---
15
+ def generate_random_text(length=100):
16
+ words = ["lorem", "ipsum", "dolor", "sit", "amet", "consectetur", "adipiscing", "elit", "sed", "do", "eiusmod", "tempor", "incididunt", "ut", "labore", "et", "dolore", "magna", "aliqua"]
17
+ return " ".join(random.choice(words) for _ in range(length // 5)).capitalize() + "."
18
+
19
+ # --- Function to populate the database ---
20
+ def populate_database():
21
+ with app.app_context():
22
+ db.drop_all() # Clear existing data
23
+ db.create_all() # Create tables
24
+
25
+ # 1. Populate Countries
26
+ countries_data = [
27
+ # GCC
28
+ {"name": "Saudi Arabia", "region": "GCC"},
29
+ {"name": "UAE", "region": "GCC"},
30
+ {"name": "Qatar", "region": "GCC"},
31
+ {"name": "Bahrain", "region": "GCC"},
32
+ {"name": "Oman", "region": "GCC"},
33
+ {"name": "Kuwait", "region": "GCC"},
34
+ # EU
35
+ {"name": "Germany", "region": "EU"},
36
+ {"name": "France", "region": "EU"},
37
+ {"name": "Italy", "region": "EU"},
38
+ {"name": "Spain", "region": "EU"},
39
+ # African Countries
40
+ {"name": "South Africa", "region": "Africa"},
41
+ {"name": "Nigeria", "region": "Africa"},
42
+ {"name": "Kenya", "region": "Africa"},
43
+ # North America
44
+ {"name": "USA", "region": "North America"},
45
+ {"name": "Canada", "region": "North America"},
46
+ # Indian Subcontinent
47
+ {"name": "India", "region": "Indian Subcontinent"},
48
+ {"name": "Pakistan", "region": "Indian Subcontinent"},
49
+ {"name": "Bangladesh", "region": "Indian Subcontinent"},
50
+ {"name": "Sri Lanka", "region": "Indian Subcontinent"},
51
+ # East Asia
52
+ {"name": "China", "region": "East Asia"},
53
+ {"name": "Japan", "region": "East Asia"},
54
+ ]
55
+
56
+ created_countries = {}
57
+ for country_data in countries_data:
58
+ country = Country(name=country_data["name"], region=country_data["region"])
59
+ db.session.add(country)
60
+ created_countries[country_data["name"]] = country
61
+ db.session.commit()
62
+ print("Countries populated.")
63
+
64
+ # 2. Populate Sample Cases
65
+ case_types = ["Fraud", "Theft", "Cybercrime", "Assault", "Homicide", "Drug Trafficking"]
66
+ all_countries = Country.query.all()
67
+ if not all_countries:
68
+ print("No countries found, cannot create cases.")
69
+ return
70
+
71
+ cases = []
72
+ for i in range(10): # Create 10 sample cases
73
+ case = Case(
74
+ case_id_display=f"C-2024{str(i+1).zfill(4)}",
75
+ case_type=random.choice(case_types),
76
+ suspect_name=generate_random_name(),
77
+ profile_details=generate_random_text(150),
78
+ evidence_summary=generate_random_text(200),
79
+ status=random.choice(list(CaseStatus)),
80
+ country_context=random.choice(all_countries) # Assign a random country for context
81
+ )
82
+ db.session.add(case)
83
+ cases.append(case)
84
+ db.session.commit()
85
+ print(f"{len(cases)} Cases populated.")
86
+
87
+ # 3. Populate Interrogation Sessions, Questions, Responses, and Reports for each case
88
+ for case_obj in cases:
89
+ # Create an interrogation session
90
+ session = InterrogationSession(
91
+ case_id=case_obj.id,
92
+ session_date=datetime.utcnow() - timedelta(days=random.randint(1, 30)),
93
+ summary_notes=generate_random_text(100)
94
+ )
95
+ db.session.add(session)
96
+ db.session.commit() # Commit session to get its ID
97
+
98
+ # Create generated questions for the session
99
+ question_categories = ["Identity & Timeline", "Evidence Confrontation", "Alibi Verification", "Psychological Pressure"]
100
+ for _ in range(random.randint(5, 12)): # 5 to 12 questions per session
101
+ question = GeneratedQuestion(
102
+ interrogation_session_id=session.id,
103
+ question_text=generate_random_text(50) + "?",
104
+ category=random.choice(question_categories)
105
+ )
106
+ db.session.add(question)
107
+ db.session.commit() # Commit question to get its ID
108
+
109
+ # Create a response for the question
110
+ response_tags = ["evasiveness", "contradiction", "alibi failure", "confession hint", "cooperative"]
111
+ response = InterrogationResponse(
112
+ generated_question_id=question.id,
113
+ response_text=generate_random_text(80),
114
+ tags=",".join(random.sample(response_tags, random.randint(0,2)))
115
+ )
116
+ db.session.add(response)
117
+ db.session.commit()
118
+
119
+ # Create a report for the case
120
+ report = Report(
121
+ case_id=case_obj.id,
122
+ llm_json_output='{"summary": "' + generate_random_text(100) + '", "findings": "' + generate_random_text(150) + '"}',
123
+ report_content_summary=generate_random_text(250),
124
+ recommendations=generate_random_text(120),
125
+ report_country_context=case_obj.country_context # Use the same country as the case for the report
126
+ )
127
+ db.session.add(report)
128
+ db.session.commit()
129
+ print("Interrogation Sessions, Questions, Responses, and Reports populated.")
130
+
131
+ print("Database populated successfully!")
132
+
133
+ if __name__ == "__main__":
134
+ populate_database()
135
+
requirements.txt ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ annotated-types==0.7.0
2
+ anyio==4.9.0
3
+ blinker==1.9.0
4
+ certifi==2025.4.26
5
+ click==8.1.8
6
+ distro==1.9.0
7
+ Flask==3.1.0
8
+ Flask-SQLAlchemy==3.1.1
9
+ greenlet==3.2.1
10
+ groq==0.24.0
11
+ h11==0.16.0
12
+ httpcore==1.0.9
13
+ httpx==0.28.1
14
+ idna==3.10
15
+ itsdangerous==2.2.0
16
+ Jinja2==3.1.6
17
+ MarkupSafe==3.0.2
18
+ pydantic==2.11.4
19
+ pydantic_core==2.33.2
20
+ sniffio==1.3.1
21
+ SQLAlchemy==2.0.40
22
+ typing-inspection==0.4.0
23
+ typing_extensions==4.13.2
24
+ Werkzeug==3.1.3
run.py ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ from app import create_app
2
+
3
+ app = create_app()
4
+
5
+ if __name__ == "__main__":
6
+ app.run(host="0.0.0.0", port=5000, debug=True)
7
+