Pradeepthi30 commited on
Commit
013897b
Β·
verified Β·
1 Parent(s): 1191893

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -12
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, user_prompt):
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 = user_prompt if user_prompt.strip() else 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,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 give your own summary prompt for customized analysis.")
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
- - πŸ“˜ **Glossary for law students**
96
- - βš–οΈ **Get a rough final verdict suggestion**
 
 
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 (Based on Your Prompt)", lines=5, interactive=False)
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, custom_prompt], outputs=[
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