VortexNode commited on
Commit
6a156c2
·
verified ·
1 Parent(s): 20f65e3

Upload 3 files

Browse files
Files changed (3) hide show
  1. README.md +27 -13
  2. main.py +80 -0
  3. requirements.txt +3 -0
README.md CHANGED
@@ -1,13 +1,27 @@
1
- ---
2
- title: Justiceai Analyzer
3
- emoji: 😻
4
- colorFrom: blue
5
- colorTo: indigo
6
- sdk: gradio
7
- sdk_version: 5.44.1
8
- app_file: app.py
9
- pinned: false
10
- license: cc-by-4.0
11
- ---
12
-
13
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # JusticeAI – Criminal Record Analyzer
2
+
3
+ JusticeAI is an AI-powered legal assistant designed to analyze and summarize criminal case records. It extracts key information such as names, crimes, locations, and judgments, then provides legal insights including applicable laws and recommended punishments based on Nigerian criminal law.
4
+
5
+ ## What It Does
6
+
7
+ - Accepts pasted or uploaded criminal case text
8
+ - Automatically summarizes long legal reports
9
+ - Extracts named entities such as people, dates, crimes, courts, and locations
10
+ - Classifies crime type based on Nigerian law
11
+ - Recommends appropriate punishment according to legal sections
12
+
13
+ ## Technologies Used
14
+
15
+ - Python
16
+ - Hugging Face Transformers (`transformers`, `pipeline`)
17
+ - PyTorch
18
+ - Gradio (UI interface)
19
+
20
+ ## Getting Started
21
+
22
+ To run locally:
23
+
24
+ 1. Clone the repository or upload files to your Hugging Face Space.
25
+ 2. Install dependencies:
26
+ ```bash
27
+ pip install -r requirements.txt
main.py ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import pipeline
2
+ import gradio as gr
3
+
4
+ # Load pre-trained pipelines
5
+ summarizer = pipeline("summarization", model="sshleifer/distilbart-cnn-12-6")
6
+ ner = pipeline("ner", model="Davlan/bert-base-multilingual-cased-ner-hrl", aggregation_strategy="simple")
7
+
8
+ # Basic crime-to-punishment mapping (based on Nigerian laws)
9
+ crime_punishment_map = {
10
+ "theft": {
11
+ "law": "Criminal Code Act, Section 390",
12
+ "punishment": "Up to 3 years imprisonment"
13
+ },
14
+ "armed robbery": {
15
+ "law": "Robbery and Firearms Act, Section 1",
16
+ "punishment": "Death penalty or life imprisonment"
17
+ },
18
+ "internet fraud": {
19
+ "law": "Cybercrime Act, 2015",
20
+ "punishment": "Minimum of 7 years imprisonment"
21
+ },
22
+ "rape": {
23
+ "law": "Criminal Law of Lagos State, Section 260",
24
+ "punishment": "Life imprisonment"
25
+ },
26
+ "murder": {
27
+ "law": "Criminal Code Act, Section 319",
28
+ "punishment": "Death penalty"
29
+ },
30
+ "assault": {
31
+ "law": "Criminal Code Act, Section 351",
32
+ "punishment": "1 year imprisonment"
33
+ }
34
+ }
35
+
36
+ # Basic keyword-based classification
37
+ def classify_crime(text):
38
+ text = text.lower()
39
+ for crime in crime_punishment_map:
40
+ if crime in text:
41
+ return crime, crime_punishment_map[crime]
42
+ return "unknown", {
43
+ "law": "N/A",
44
+ "punishment": "No specific punishment found. Manual review required."
45
+ }
46
+
47
+ # Main function
48
+ def analyze_text(text):
49
+ # Step 1: Run summarization
50
+ summary = summarizer(text, max_length=80, min_length=30, do_sample=False)[0]["summary_text"]
51
+
52
+ # Step 2: Named Entity Recognition
53
+ entities = ner(text)
54
+
55
+ # Step 3: Crime classification and punishment recommendation
56
+ crime_type, recommendation = classify_crime(text)
57
+
58
+ # Final output
59
+ return {
60
+ "Summary": summary,
61
+ "Extracted Entities": entities,
62
+ "Legal Analysis": {
63
+ "Crime Type": crime_type.title() if crime_type != "unknown" else "Unknown",
64
+ "Applicable Law": recommendation["law"],
65
+ "Recommended Punishment": recommendation["punishment"]
66
+ }
67
+ }
68
+
69
+ # Gradio Interface
70
+ gr.Interface(
71
+ fn=analyze_text,
72
+ inputs=gr.Textbox(lines=12, label="Paste Criminal Case Text"),
73
+ outputs=[
74
+ gr.Textbox(label="Summary"),
75
+ gr.JSON(label="Extracted Entities"),
76
+ gr.JSON(label="Legal Analysis / Recommended Punishment")
77
+ ],
78
+ title="JusticeAI - Legal Case Analyzer",
79
+ description="Paste any criminal case report. This AI will summarize it, extract important entities, and recommend the legal punishment based on Nigerian law."
80
+ ).launch()
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ transformers
2
+ torch
3
+ gradio