Johan713 commited on
Commit
ed33401
·
verified ·
1 Parent(s): 60feff1

Update app2.py

Browse files
Files changed (1) hide show
  1. app2.py +69 -266
app2.py CHANGED
@@ -557,211 +557,85 @@ def extract_cost_estimates(text: str) -> List[str]:
557
 
558
  return estimates
559
 
560
- def generate_legal_form(form_type: str, user_details: Dict[str, str], nation: str, state: str = None) -> Dict[str, Any]:
561
- """
562
- Generates a legal form based on user input, nation, and state (if applicable).
563
- Creates downloadable .txt and .docx files.
564
- """
565
- current_date = datetime.now().strftime("%B %d, %Y")
566
 
567
- # Helper function to get jurisdiction-specific clauses
568
- def get_jurisdiction_clauses(form_type, nation, state):
569
- # This would ideally be a comprehensive database of clauses for different jurisdictions
570
- # For demonstration, we'll use a simplified version
571
- clauses = {
572
- "USA": {
573
- "Power of Attorney": "This Power of Attorney is governed by the laws of the State of {state}.",
574
- "Non-Disclosure Agreement": "This Agreement shall be governed by and construed in accordance with the laws of the State of {state}.",
575
- "Simple Will": "This Will shall be construed in accordance with the laws of the State of {state}.",
576
- "Lease Agreement": "This Lease Agreement is subject to the landlord-tenant laws of the State of {state}.",
577
- "Employment Contract": "This Employment Contract is governed by the labor laws of the State of {state}."
578
- },
579
- "UK": {
580
- "Power of Attorney": "This Power of Attorney is governed by the laws of England and Wales.",
581
- "Non-Disclosure Agreement": "This Agreement shall be governed by and construed in accordance with the laws of England and Wales.",
582
- "Simple Will": "This Will shall be construed in accordance with the laws of England and Wales.",
583
- "Lease Agreement": "This Lease Agreement is subject to the landlord and tenant laws of England and Wales.",
584
- "Employment Contract": "This Employment Contract is governed by the employment laws of England and Wales."
585
- },
586
- # Add more countries as needed
587
- }
588
- return clauses.get(nation, {}).get(form_type, "").format(state=state)
589
-
590
- jurisdiction_clause = get_jurisdiction_clauses(form_type, nation, state)
591
 
592
- if form_type == "Power of Attorney":
593
- form_content = f"""
594
- POWER OF ATTORNEY
595
-
596
- This Power of Attorney is made on {current_date}.
597
-
598
- I, {user_details['principal_name']}, hereby appoint {user_details['agent_name']} as my Attorney-in-Fact ("Agent").
599
-
600
- My Agent shall have full power and authority to act on my behalf. This power and authority shall authorize my Agent to manage and conduct all of my affairs and to exercise all of my legal rights and powers, including all rights and powers that I may acquire in the future. My Agent's powers shall include, but not be limited to:
601
-
602
- 1. {', '.join(user_details['powers'])}
603
-
604
- This Power of Attorney shall become effective immediately and shall continue until it is revoked by me.
605
-
606
- {jurisdiction_clause}
607
-
608
- Signed this {current_date}.
609
-
610
- ______________________
611
- {user_details['principal_name']} (Principal)
612
-
613
- ______________________
614
- {user_details['agent_name']} (Agent)
615
-
616
- ______________________
617
- Witness
618
-
619
- ______________________
620
- Witness
621
- """
622
-
623
- elif form_type == "Non-Disclosure Agreement":
624
- form_content = f"""
625
- NON-DISCLOSURE AGREEMENT
626
-
627
- This Non-Disclosure Agreement (the "Agreement") is entered into on {current_date} by and between:
628
-
629
- {user_details['party_a']} ("Party A")
630
- and
631
- {user_details['party_b']} ("Party B")
632
-
633
- 1. Purpose: This Agreement is entered into for the purpose of {user_details['purpose']}.
634
-
635
- 2. Confidential Information: Both parties may disclose certain confidential and proprietary information to each other in connection with the Purpose.
636
-
637
- 3. Non-Disclosure: Both parties agree to keep all Confidential Information strictly confidential and not to disclose such information to any third parties for a period of {user_details['duration']} years from the date of this Agreement.
638
-
639
- {jurisdiction_clause}
640
-
641
- IN WITNESS WHEREOF, the parties hereto have executed this Non-Disclosure Agreement as of the date first above written.
642
-
643
- ______________________
644
- {user_details['party_a']}
645
-
646
- ______________________
647
- {user_details['party_b']}
648
- """
649
-
650
- elif form_type == "Simple Will":
651
- beneficiaries = user_details['beneficiaries'].split('\n')
652
- beneficiary_clauses = "\n".join([f"{i+1}. I give, devise, and bequeath to {b.strip()} [insert specific bequest or share of estate]." for i, b in enumerate(beneficiaries)])
653
 
654
- form_content = f"""
655
- LAST WILL AND TESTAMENT
656
-
657
- I, {user_details['testator_name']}, being of sound mind, do hereby make, publish, and declare this to be my Last Will and Testament, hereby revoking all previous wills and codicils made by me.
658
-
659
- 1. EXECUTOR: I appoint {user_details['executor_name']} to be the Executor of this, my Last Will and Testament.
660
-
661
- 2. BEQUESTS:
662
- {beneficiary_clauses}
663
-
664
- 3. RESIDUARY ESTATE: I give, devise, and bequeath all the rest, residue, and remainder of my estate to [insert beneficiary or beneficiaries].
665
-
666
- 4. POWERS OF EXECUTOR: I grant to my Executor full power and authority to sell, lease, mortgage, or otherwise dispose of the whole or any part of my estate.
667
-
668
- {jurisdiction_clause}
669
-
670
- IN WITNESS WHEREOF, I have hereunto set my hand to this my Last Will and Testament on {current_date}.
671
-
672
- ______________________
673
- {user_details['testator_name']} (Testator)
674
-
675
- WITNESSES:
676
- On the date last above written, {user_details['testator_name']}, known to us to be the Testator, signed this Will in our presence and declared it to be their Last Will and Testament. At the Testator's request, in the Testator's presence, and in the presence of each other, we have signed our names as witnesses:
677
-
678
- ______________________
679
- Witness 1
680
-
681
- ______________________
682
- Witness 2
683
- """
684
-
685
- elif form_type == "Lease Agreement":
686
- form_content = f"""
687
- LEASE AGREEMENT
688
-
689
- This Lease Agreement (the "Lease") is made on {current_date} by and between:
690
-
691
- {user_details['landlord_name']} ("Landlord")
692
- and
693
- {user_details['tenant_name']} ("Tenant")
694
-
695
- 1. PREMISES: The Landlord hereby leases to the Tenant the property located at {user_details['property_address']}.
696
-
697
- 2. TERM: The term of this Lease shall be for {user_details['lease_term']} months, beginning on {user_details['start_date']} and ending on {user_details['end_date']}.
698
-
699
- 3. RENT: The Tenant shall pay rent in the amount of {user_details['rent_amount']} per month, due on the {user_details['rent_due_day']} day of each month.
700
-
701
- 4. SECURITY DEPOSIT: The Tenant shall pay a security deposit of {user_details['security_deposit']} upon signing this Lease.
702
-
703
- {jurisdiction_clause}
704
-
705
- IN WITNESS WHEREOF, the parties hereto have executed this Lease Agreement as of the date first above written.
706
-
707
- ______________________
708
- {user_details['landlord_name']} (Landlord)
709
-
710
- ______________________
711
- {user_details['tenant_name']} (Tenant)
712
- """
713
-
714
- elif form_type == "Employment Contract":
715
- form_content = f"""
716
- EMPLOYMENT CONTRACT
717
-
718
- This Employment Contract (the "Contract") is made on {current_date} by and between:
719
-
720
- {user_details['employer_name']} ("Employer")
721
- and
722
- {user_details['employee_name']} ("Employee")
723
-
724
- 1. POSITION: The Employee is hired for the position of {user_details['job_title']}.
725
-
726
- 2. DUTIES: The Employee's duties shall include, but are not limited to: {user_details['job_duties']}.
727
-
728
- 3. COMPENSATION: The Employee shall be paid a {user_details['pay_frequency']} salary of {user_details['salary_amount']}.
729
 
730
- 4. TERM: This Contract shall commence on {user_details['start_date']} and continue until terminated by either party.
 
731
 
732
- 5. BENEFITS: The Employee shall be entitled to the following benefits: {user_details['benefits']}.
 
 
 
733
 
734
- {jurisdiction_clause}
 
 
735
 
736
- IN WITNESS WHEREOF, the parties hereto have executed this Employment Contract as of the date first above written.
 
737
 
738
- ______________________
739
- {user_details['employer_name']} (Employer)
740
 
741
- ______________________
742
- {user_details['employee_name']} (Employee)
743
- """
744
 
745
- else:
746
- return {"error": "Unsupported form type"}
 
 
747
 
748
- # Generate .txt file
749
- txt_file = io.StringIO()
750
- txt_file.write(form_content)
751
- txt_file.seek(0)
752
 
753
- # Generate .docx file
754
- docx_file = io.BytesIO()
755
- doc = Document()
756
- doc.add_paragraph(form_content)
757
- doc.save(docx_file)
758
- docx_file.seek(0)
759
 
760
- return {
761
- "form_content": form_content,
762
- "txt_file": txt_file,
763
- "docx_file": docx_file
764
- }
765
 
766
  CASE_TYPES = [
767
  "Civil Rights", "Contract", "Real Property", "Tort", "Labor", "Intellectual Property",
@@ -883,7 +757,7 @@ with st.sidebar:
883
 
884
  feature = st.selectbox(
885
  "Select a feature",
886
- ["Legal Chatbot", "Document Analysis", "Case Precedent Finder", "Legal Cost Estimator", "Legal Form Generator", "Case Trend Visualizer"]
887
  )
888
  if feature == "Legal Chatbot":
889
  st.subheader("Legal Chatbot")
@@ -1088,79 +962,8 @@ elif feature == "Legal Cost Estimator":
1088
  else:
1089
  st.write("Click 'Estimate Costs' to see the results.")
1090
 
1091
- elif feature == "Legal Form Generator":
1092
- st.subheader("Legal Form Generator")
1093
-
1094
- form_type = st.selectbox("Select form type", ["Power of Attorney", "Non-Disclosure Agreement", "Simple Will", "Lease Agreement", "Employment Contract"], key="form_generator_type")
1095
-
1096
- nation = st.selectbox("Select nation", ["USA", "UK"], key="form_generator_nation")
1097
- if nation == "USA":
1098
- state = st.selectbox("Select state", ["California", "New York", "Texas", "Florida"], key="form_generator_state")
1099
- else:
1100
- state = None
1101
-
1102
- user_details = {}
1103
- if form_type == "Power of Attorney":
1104
- user_details["principal_name"] = st.text_input("Principal's Full Name:")
1105
- user_details["agent_name"] = st.text_input("Agent's Full Name:")
1106
- user_details["powers"] = st.multiselect("Select powers to grant", ["Financial Decisions", "Healthcare Decisions", "Real Estate Transactions"])
1107
- elif form_type == "Non-Disclosure Agreement":
1108
- user_details["party_a"] = st.text_input("First Party's Name:")
1109
- user_details["party_b"] = st.text_input("Second Party's Name:")
1110
- user_details["purpose"] = st.text_input("Purpose of Disclosure:")
1111
- user_details["duration"] = st.number_input("Duration of Agreement (in years):", min_value=1, max_value=10)
1112
- elif form_type == "Simple Will":
1113
- user_details["testator_name"] = st.text_input("Testator's Full Name:")
1114
- user_details["beneficiaries"] = st.text_area("List Beneficiaries (one per line):")
1115
- user_details["executor_name"] = st.text_input("Executor's Full Name:")
1116
- elif form_type == "Lease Agreement":
1117
- user_details["landlord_name"] = st.text_input("Landlord's Full Name:")
1118
- user_details["tenant_name"] = st.text_input("Tenant's Full Name:")
1119
- user_details["property_address"] = st.text_input("Property Address:")
1120
- user_details["lease_term"] = st.number_input("Lease Term (in months):", min_value=1, max_value=60)
1121
- user_details["start_date"] = st.date_input("Lease Start Date:")
1122
- user_details["end_date"] = st.date_input("Lease End Date:")
1123
- user_details["rent_amount"] = st.number_input("Monthly Rent Amount:", min_value=0)
1124
- user_details["rent_due_day"] = st.number_input("Rent Due Day of Month:", min_value=1, max_value=31)
1125
- user_details["security_deposit"] = st.number_input("Security Deposit Amount:", min_value=0)
1126
- elif form_type == "Employment Contract":
1127
- user_details["employer_name"] = st.text_input("Employer's Full Name:")
1128
- user_details["employee_name"] = st.text_input("Employee's Full Name:")
1129
- user_details["job_title"] = st.text_input("Job Title:")
1130
- user_details["job_duties"] = st.text_area("Job Duties:")
1131
- user_details["pay_frequency"] = st.selectbox("Pay Frequency:", ["Weekly", "Bi-weekly", "Monthly"])
1132
- user_details["salary_amount"] = st.number_input("Salary Amount:", min_value=0)
1133
- user_details["start_date"] = st.date_input("Employment Start Date:")
1134
- user_details["benefits"] = st.text_area("Employee Benefits:")
1135
-
1136
- if st.button("Generate Form"):
1137
- generated_form = generate_legal_form(form_type, user_details, nation, state)
1138
-
1139
- if "error" in generated_form:
1140
- st.error(generated_form["error"])
1141
- else:
1142
- st.write("### Generated Legal Form:")
1143
- st.text(generated_form["form_content"])
1144
-
1145
- # Provide download buttons for .txt and .docx files
1146
- txt_download = generated_form["txt_file"].getvalue()
1147
- docx_download = generated_form["docx_file"].getvalue()
1148
-
1149
- st.download_button(
1150
- label="Download as .txt",
1151
- data=txt_download,
1152
- file_name=f"{form_type.lower().replace(' ', '_')}_{nation}{'_' + state if state else ''}.txt",
1153
- mime="text/plain"
1154
- )
1155
-
1156
- st.download_button(
1157
- label="Download as .docx",
1158
- data=docx_download,
1159
- file_name=f"{form_type.lower().replace(' ', '_')}_{nation}{'_' + state if state else ''}.docx",
1160
- mime="application/vnd.openxmlformats-officedocument.wordprocessingml.document"
1161
- )
1162
-
1163
- st.warning("Please note: This generated form is a template based on general principles of the selected jurisdiction. It should be reviewed by a legal professional licensed in the relevant jurisdiction before use.")
1164
 
1165
  elif feature == "Case Trend Visualizer":
1166
  st.subheader("Case Trend Visualizer")
 
557
 
558
  return estimates
559
 
560
+ def legal_cost_estimator_ui():
561
+ st.subheader("Legal Cost Estimator")
 
 
 
 
562
 
563
+ case_type = st.selectbox("Select case type", ["Civil Litigation", "Criminal Defense", "Family Law", "Corporate Law"])
564
+ complexity = st.selectbox("Select case complexity", ["Simple", "Moderate", "Complex"])
565
+ country = st.selectbox("Select country", ["USA", "UK", "Canada"])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
566
 
567
+ if country == "USA":
568
+ state = st.selectbox("Select state", ["California", "New York", "Texas", "Florida"])
569
+ else:
570
+ state = None
571
+
572
+ if st.button("Estimate Costs"):
573
+ with st.spinner("Estimating costs and performing web search..."):
574
+ cost_estimate = estimate_legal_costs(case_type, complexity, country, state)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
575
 
576
+ st.write("### Estimated Legal Costs")
577
+ for key, value in cost_estimate["cost_breakdown"].items():
578
+ if key != "Web search estimates":
579
+ st.write(f"**{key}:** {value}")
580
+
581
+ st.write("### Web Search Estimates")
582
+ if cost_estimate["cost_breakdown"]["Web search estimates"]:
583
+ for result in cost_estimate["cost_breakdown"]["Web search estimates"]:
584
+ st.write(f"**Source:** [{result['source']}]({result['link']})")
585
+ st.write("**Estimated Costs:**")
586
+ for estimate in result['estimates']:
587
+ st.write(f"- {estimate}")
588
+ st.write("---")
589
+ else:
590
+ st.write("No specific cost estimates found from web search.")
591
+
592
+ st.write("### Potential High-Cost Areas")
593
+ for area in cost_estimate["high_cost_areas"]:
594
+ st.write(f"- {area}")
595
+
596
+ st.write("### Cost-Saving Tips")
597
+ for tip in cost_estimate["cost_saving_tips"]:
598
+ st.write(f"- {tip}")
599
+
600
+ st.write("### Recommended Lawyers/Law Firms")
601
+ for lawyer in cost_estimate["lawyer_recommendations"][:5]: # Display top 5 recommendations
602
+ st.write(f"**[{lawyer['title']}]({lawyer['link']})**")
603
+ st.write(lawyer["snippet"])
604
+ st.write("---")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
605
 
606
+ def analyze_contract(contract_text: str) -> Dict[str, Any]:
607
+ """Analyzes the contract text for clauses, benefits, and potential exploits."""
608
 
609
+ analysis_prompt = f"""
610
+ Analyze the following contract, identifying clauses that are favorable and unfavorable to each party involved.
611
+ Highlight potential areas of concern or clauses that could be exploited.
612
+ Provide specific examples within the contract to support your analysis.
613
 
614
+ **Contract Text:**
615
+ {contract_text}
616
+ """
617
 
618
+ analysis = get_ai_response(analysis_prompt)
619
+ return {"analysis": analysis}
620
 
 
 
621
 
622
+ def contract_analysis_ui():
623
+ st.subheader("Contract Analyzer")
 
624
 
625
+ uploaded_file = st.file_uploader(
626
+ "Upload a contract document (PDF, DOCX, or TXT)",
627
+ type=["pdf", "docx", "txt"],
628
+ )
629
 
630
+ if uploaded_file:
631
+ contract_text = analyze_document(uploaded_file)
 
 
632
 
633
+ if st.button("Analyze Contract"):
634
+ with st.spinner("Analyzing contract..."):
635
+ analysis_results = analyze_contract(contract_text)
 
 
 
636
 
637
+ st.write("### Contract Analysis")
638
+ st.write(analysis_results.get("analysis", "No analysis available."))
 
 
 
639
 
640
  CASE_TYPES = [
641
  "Civil Rights", "Contract", "Real Property", "Tort", "Labor", "Intellectual Property",
 
757
 
758
  feature = st.selectbox(
759
  "Select a feature",
760
+ ["Legal Chatbot", "Document Analysis", "Case Precedent Finder", "Legal Cost Estimator", "Contract Analysis", "Case Trend Visualizer"]
761
  )
762
  if feature == "Legal Chatbot":
763
  st.subheader("Legal Chatbot")
 
962
  else:
963
  st.write("Click 'Estimate Costs' to see the results.")
964
 
965
+ elif feature == "Contract Analysis":
966
+ contract_analysis_ui()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
967
 
968
  elif feature == "Case Trend Visualizer":
969
  st.subheader("Case Trend Visualizer")