Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -40,7 +40,7 @@ def format_glossary_html(glossary_text):
|
|
40 |
return html
|
41 |
|
42 |
# Analyze and summarize the document
|
43 |
-
def analyze_document(file
|
44 |
filename = os.path.basename(file.name)
|
45 |
text = extract_text(file)
|
46 |
|
@@ -49,8 +49,8 @@ def analyze_document(file, user_prompt):
|
|
49 |
|
50 |
short_text = text[:3000]
|
51 |
|
52 |
-
# Prompts
|
53 |
-
summary_prompt =
|
54 |
glossary_prompt = f"List and explain important legal sections and terms in this document:\n\n{short_text}"
|
55 |
verdict_prompt = f"Based on the following legal document, what could be the final verdict or likely judgment?\n\n{short_text}"
|
56 |
|
@@ -65,8 +65,6 @@ def analyze_document(file, user_prompt):
|
|
65 |
output_filename = f"LegalAnalysis_{timestamp}.txt"
|
66 |
with open(output_filename, "w", encoding="utf-8") as f:
|
67 |
f.write(f"π File: {filename}\nπ Time: {timestamp}\n\n")
|
68 |
-
f.write("=== π Custom Summary Prompt ===\n")
|
69 |
-
f.write(user_prompt + "\n\n")
|
70 |
f.write("=== π Summary ===\n")
|
71 |
f.write(summary + "\n\n")
|
72 |
f.write("=== π Glossary of Legal Terms ===\n")
|
@@ -81,32 +79,32 @@ with gr.Blocks(css="body { background-color: #f9f9f9; font-family: 'Segoe UI'; }
|
|
81 |
with gr.Row():
|
82 |
with gr.Column(scale=3):
|
83 |
gr.Markdown("## βοΈ AI Legal Assistant: Judgment Analyzer & Summarizer")
|
84 |
-
gr.Markdown("Upload your legal document and
|
85 |
file_input = gr.File(label="π Upload File (.pdf, .docx, .txt)", file_types=[".pdf", ".docx", ".txt"])
|
86 |
-
custom_prompt = gr.Textbox(label="π Your Custom Summary Prompt", placeholder="e.g., Summarize this legal judgment with key arguments...", lines=2)
|
87 |
submit_btn = gr.Button("π Analyze Document")
|
88 |
download_btn = gr.File(label="β¬οΈ Download Full Report")
|
89 |
|
90 |
with gr.Column(scale=1):
|
91 |
gr.Markdown("### π‘ Tips & Use Cases")
|
92 |
gr.Markdown("""
|
93 |
-
- βοΈ **Customize your summary to focus on any aspect**
|
94 |
- π **Quickly review court case files**
|
95 |
-
-
|
96 |
-
-
|
|
|
|
|
97 |
""")
|
98 |
|
99 |
with gr.Row():
|
100 |
extracted = gr.Textbox(label="π Extracted Text", lines=10, interactive=False)
|
101 |
|
102 |
with gr.Row():
|
103 |
-
summary = gr.Textbox(label="π Summary
|
104 |
glossary_raw = gr.Textbox(visible=False)
|
105 |
glossary_html = gr.HTML(label="π Glossary of Legal Terms")
|
106 |
|
107 |
final_verdict = gr.Textbox(label="βοΈ Final Verdict (AI Inferred)", lines=3, interactive=False)
|
108 |
|
109 |
-
submit_btn.click(fn=analyze_document, inputs=[file_input
|
110 |
extracted, summary, glossary_raw, glossary_html, final_verdict, download_btn
|
111 |
])
|
112 |
|
|
|
40 |
return html
|
41 |
|
42 |
# Analyze and summarize the document
|
43 |
+
def analyze_document(file):
|
44 |
filename = os.path.basename(file.name)
|
45 |
text = extract_text(file)
|
46 |
|
|
|
49 |
|
50 |
short_text = text[:3000]
|
51 |
|
52 |
+
# Prompts for LLM
|
53 |
+
summary_prompt = f"Summarize this legal document:\n\n{short_text}"
|
54 |
glossary_prompt = f"List and explain important legal sections and terms in this document:\n\n{short_text}"
|
55 |
verdict_prompt = f"Based on the following legal document, what could be the final verdict or likely judgment?\n\n{short_text}"
|
56 |
|
|
|
65 |
output_filename = f"LegalAnalysis_{timestamp}.txt"
|
66 |
with open(output_filename, "w", encoding="utf-8") as f:
|
67 |
f.write(f"π File: {filename}\nπ Time: {timestamp}\n\n")
|
|
|
|
|
68 |
f.write("=== π Summary ===\n")
|
69 |
f.write(summary + "\n\n")
|
70 |
f.write("=== π Glossary of Legal Terms ===\n")
|
|
|
79 |
with gr.Row():
|
80 |
with gr.Column(scale=3):
|
81 |
gr.Markdown("## βοΈ AI Legal Assistant: Judgment Analyzer & Summarizer")
|
82 |
+
gr.Markdown("Upload your legal document and let AI help you summarize, analyze legal terms, and suggest a possible judgment.")
|
83 |
file_input = gr.File(label="π Upload File (.pdf, .docx, .txt)", file_types=[".pdf", ".docx", ".txt"])
|
|
|
84 |
submit_btn = gr.Button("π Analyze Document")
|
85 |
download_btn = gr.File(label="β¬οΈ Download Full Report")
|
86 |
|
87 |
with gr.Column(scale=1):
|
88 |
gr.Markdown("### π‘ Tips & Use Cases")
|
89 |
gr.Markdown("""
|
|
|
90 |
- π **Quickly review court case files**
|
91 |
+
- π§ **Understand complex legal language**
|
92 |
+
- ποΈ **Get a summary for judgment history**
|
93 |
+
- π **Extract glossary for legal education**
|
94 |
+
- βοΈ **Get a rough idea of final judgment**
|
95 |
""")
|
96 |
|
97 |
with gr.Row():
|
98 |
extracted = gr.Textbox(label="π Extracted Text", lines=10, interactive=False)
|
99 |
|
100 |
with gr.Row():
|
101 |
+
summary = gr.Textbox(label="π Summary", lines=5, interactive=False)
|
102 |
glossary_raw = gr.Textbox(visible=False)
|
103 |
glossary_html = gr.HTML(label="π Glossary of Legal Terms")
|
104 |
|
105 |
final_verdict = gr.Textbox(label="βοΈ Final Verdict (AI Inferred)", lines=3, interactive=False)
|
106 |
|
107 |
+
submit_btn.click(fn=analyze_document, inputs=[file_input], outputs=[
|
108 |
extracted, summary, glossary_raw, glossary_html, final_verdict, download_btn
|
109 |
])
|
110 |
|