Devmujeeb-commits commited on
Commit
4f96476
·
0 Parent(s):
Files changed (5) hide show
  1. .gradio/certificate.pem +31 -0
  2. README.md +27 -0
  3. dowlnload_mini.py +4 -0
  4. main.py +66 -0
  5. requirements.txt +3 -0
.gradio/certificate.pem ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ -----BEGIN CERTIFICATE-----
2
+ MIIFazCCA1OgAwIBAgIRAIIQz7DSQONZRGPgu2OCiwAwDQYJKoZIhvcNAQELBQAw
3
+ TzELMAkGA1UEBhMCVVMxKTAnBgNVBAoTIEludGVybmV0IFNlY3VyaXR5IFJlc2Vh
4
+ cmNoIEdyb3VwMRUwEwYDVQQDEwxJU1JHIFJvb3QgWDEwHhcNMTUwNjA0MTEwNDM4
5
+ WhcNMzUwNjA0MTEwNDM4WjBPMQswCQYDVQQGEwJVUzEpMCcGA1UEChMgSW50ZXJu
6
+ ZXQgU2VjdXJpdHkgUmVzZWFyY2ggR3JvdXAxFTATBgNVBAMTDElTUkcgUm9vdCBY
7
+ MTCCAiIwDQYJKoZIhvcNAQEBBQADggIPADCCAgoCggIBAK3oJHP0FDfzm54rVygc
8
+ h77ct984kIxuPOZXoHj3dcKi/vVqbvYATyjb3miGbESTtrFj/RQSa78f0uoxmyF+
9
+ 0TM8ukj13Xnfs7j/EvEhmkvBioZxaUpmZmyPfjxwv60pIgbz5MDmgK7iS4+3mX6U
10
+ A5/TR5d8mUgjU+g4rk8Kb4Mu0UlXjIB0ttov0DiNewNwIRt18jA8+o+u3dpjq+sW
11
+ T8KOEUt+zwvo/7V3LvSye0rgTBIlDHCNAymg4VMk7BPZ7hm/ELNKjD+Jo2FR3qyH
12
+ B5T0Y3HsLuJvW5iB4YlcNHlsdu87kGJ55tukmi8mxdAQ4Q7e2RCOFvu396j3x+UC
13
+ B5iPNgiV5+I3lg02dZ77DnKxHZu8A/lJBdiB3QW0KtZB6aw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UHBcnWEvgJBQl9nJEiU0Zsnvgc/ubhPgXRR4Xq37Z0j4r7g1SgEEzwxA57d
30
+ emyPxgcYxn/eR44/KJ4EBs+lVDR3veyJm+kXQ99b21/+jh5Xos1AnX5iItreGCc=
31
+ -----END CERTIFICATE-----
README.md ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
dowlnload_mini.py ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ from transformers import AutoModelForTokenClassification, AutoTokenizer
2
+
3
+ AutoTokenizer.from_pretrained("dslim/bert-base-NER")
4
+ AutoModelForTokenClassification.from_pretrained("dslim/bert-base-NER")
main.py ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import pipeline
2
+ import gradio as gr
3
+
4
+ # Load pre-trained pipelines
5
+ try:
6
+ summarizer = pipeline("summarization", model="sshleifer/distilbart-cnn-12-6")
7
+ ner = pipeline("ner", model="Davlan/bert-base-multilingual-cased-ner-hrl", aggregation_strategy="simple")
8
+ except Exception as e:
9
+ summarizer = None
10
+ ner = None
11
+ print("Error loading models:", e)
12
+
13
+ # Nigerian law reference (basic keyword-to-punishment mapping)
14
+ crime_punishment_map = {
15
+ "theft": {"law": "Criminal Code Act, Section 390", "punishment": "Up to 3 years imprisonment"},
16
+ "armed robbery": {"law": "Robbery and Firearms Act, Section 1", "punishment": "Death penalty or life imprisonment"},
17
+ "internet fraud": {"law": "Cybercrime Act, 2015", "punishment": "Minimum of 7 years imprisonment"},
18
+ "rape": {"law": "Criminal Law of Lagos State, Section 260", "punishment": "Life imprisonment"},
19
+ "murder": {"law": "Criminal Code Act, Section 319", "punishment": "Death penalty"},
20
+ "assault": {"law": "Criminal Code Act, Section 351", "punishment": "1 year imprisonment"}
21
+ }
22
+
23
+ def classify_crime(text):
24
+ text = text.lower()
25
+ for crime in crime_punishment_map:
26
+ if crime in text:
27
+ return crime, crime_punishment_map[crime]
28
+ return "unknown", {
29
+ "law": "N/A",
30
+ "punishment": "No specific punishment found. Manual review required."
31
+ }
32
+
33
+ # Main analysis function with full error handling
34
+ def analyze_text(text):
35
+ try:
36
+ if not text.strip():
37
+ return "No text provided.", [], {"Crime Type": "N/A", "Applicable Law": "N/A", "Recommended Punishment": "N/A"}
38
+
39
+ summary = summarizer(text, max_length=80, min_length=30, do_sample=False)[0].get("summary_text", "Summary failed.")
40
+ entities = ner(text)
41
+ crime_type, law_info = classify_crime(text)
42
+
43
+ return summary, entities, {
44
+ "Crime Type": crime_type.title() if crime_type != "unknown" else "Unknown",
45
+ "Applicable Law": law_info["law"],
46
+ "Recommended Punishment": law_info["punishment"]
47
+ }
48
+ except Exception as e:
49
+ return f"⚠️ An error occurred: {str(e)}", [], {
50
+ "Crime Type": "Error",
51
+ "Applicable Law": "Error",
52
+ "Recommended Punishment": "Error"
53
+ }
54
+
55
+ # Launch app
56
+ gr.Interface(
57
+ fn=analyze_text,
58
+ inputs=gr.Textbox(lines=12, label="Paste Criminal Case Text"),
59
+ outputs=[
60
+ gr.Textbox(label="Summary"),
61
+ gr.JSON(label="Extracted Entities"),
62
+ gr.JSON(label="Legal Analysis / Recommended Punishment")
63
+ ],
64
+ title="JusticeAI - Legal Case Analyzer",
65
+ description="Paste any criminal case report. This AI will summarize it, extract important entities, and recommend the legal punishment based on Nigerian law."
66
+ ).launch()
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ transformers
2
+ torch
3
+ gradio