Update app2.py
Browse files
app2.py
CHANGED
@@ -1811,6 +1811,255 @@ def lawyer_finder_ui():
|
|
1811 |
else:
|
1812 |
st.warning(f"No lawyers found in {city}, {state}. Try selecting a different city or state.")
|
1813 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1814 |
# Streamlit App
|
1815 |
st.markdown("""
|
1816 |
<style>
|
|
|
1811 |
else:
|
1812 |
st.warning(f"No lawyers found in {city}, {state}. Try selecting a different city or state.")
|
1813 |
|
1814 |
+
import streamlit as st
|
1815 |
+
import pandas as pd
|
1816 |
+
import plotly.express as px
|
1817 |
+
# ... other imports ...
|
1818 |
+
|
1819 |
+
def analyze_policy(policy_text: str) -> Dict[str, Any]:
|
1820 |
+
"""Analyzes the given policy text for its potential impact and benefits."""
|
1821 |
+
analysis_prompt = f"""
|
1822 |
+
Analyze the following policy text, taking into account US legal and societal contexts:
|
1823 |
+
|
1824 |
+
Policy Text:
|
1825 |
+
```
|
1826 |
+
{policy_text}
|
1827 |
+
```
|
1828 |
+
|
1829 |
+
Provide a comprehensive analysis that includes:
|
1830 |
+
|
1831 |
+
* **Summary:** Briefly summarize the key points of the policy.
|
1832 |
+
* **Large-Scale Impact:** Discuss the potential impact of this policy on a national or state level. Consider economic, social, and legal implications.
|
1833 |
+
* **Small-Scale Impact:** Analyze how this policy might affect individuals, families, or specific communities within the US.
|
1834 |
+
* **Long-Term Benefits:** What are the potential advantages of this policy in the long run (5-10 years or more)?
|
1835 |
+
* **Short-Term Benefits:** What benefits might be observed within the first few years of implementing this policy?
|
1836 |
+
* **Potential Drawbacks:** Are there any possible negative consequences or challenges in implementing this policy?
|
1837 |
+
* **Legal Considerations:** Are there any existing US laws or regulations that this policy might conflict with or be affected by?
|
1838 |
+
* **Historical Context:** Are there any historical parallels or past US policies that might inform the potential outcomes of this policy?
|
1839 |
+
* **Suggestions for Improvement:** Offer specific recommendations on how the policy could be modified to enhance its effectiveness or mitigate potential drawbacks.
|
1840 |
+
* **Stakeholder Perspectives:** Identify different groups or entities in the US that might have an interest in this policy (e.g., businesses, consumers, government agencies), and how they might view it.
|
1841 |
+
|
1842 |
+
Support your analysis with relevant examples, statistics, or legal precedents from the US, where applicable.
|
1843 |
+
Maintain a neutral and objective tone, presenting both potential advantages and disadvantages of the policy.
|
1844 |
+
"""
|
1845 |
+
|
1846 |
+
try:
|
1847 |
+
analysis = get_ai_response(analysis_prompt)
|
1848 |
+
return {"analysis": analysis}
|
1849 |
+
except Exception as e:
|
1850 |
+
return {"error": f"Error analyzing policy: {str(e)}"}
|
1851 |
+
|
1852 |
+
def policy_analysis_ui():
|
1853 |
+
st.subheader("Policy Analysis & Impact")
|
1854 |
+
with st.expander("How to use"):
|
1855 |
+
st.write('''Enter the US policy text you want to analyze.
|
1856 |
+
LexAI will provide a comprehensive analysis of the policy's potential impact, benefits, drawbacks, and more.
|
1857 |
+
''')
|
1858 |
+
|
1859 |
+
if 'policy_history' not in st.session_state:
|
1860 |
+
st.session_state.policy_history = []
|
1861 |
+
|
1862 |
+
display_chat_history()
|
1863 |
+
|
1864 |
+
policy_text = st.text_area("Enter the US policy text:", height=200)
|
1865 |
+
|
1866 |
+
if st.button("Analyze Policy"):
|
1867 |
+
if policy_text:
|
1868 |
+
with st.spinner("Analyzing policy..."):
|
1869 |
+
analysis_results = analyze_policy(policy_text)
|
1870 |
+
|
1871 |
+
if "error" in analysis_results:
|
1872 |
+
st.error(analysis_results["error"])
|
1873 |
+
else:
|
1874 |
+
st.write("### Policy Analysis")
|
1875 |
+
st.write(analysis_results.get("analysis", "No analysis available."))
|
1876 |
+
|
1877 |
+
# Perform and display Wikipedia search
|
1878 |
+
wiki_result = search_wikipedia(policy_text)
|
1879 |
+
st.session_state.policy_history.append({
|
1880 |
+
'type': 'wikipedia',
|
1881 |
+
'summary': wiki_result.get("summary", "No summary available."),
|
1882 |
+
'url': wiki_result.get("url", "")
|
1883 |
+
})
|
1884 |
+
|
1885 |
+
# Perform and display web search
|
1886 |
+
web_results = search_web_duckduckgo(policy_text)
|
1887 |
+
st.session_state.policy_history.append({
|
1888 |
+
'type': 'web_search',
|
1889 |
+
'results': web_results
|
1890 |
+
})
|
1891 |
+
|
1892 |
+
st.rerun()
|
1893 |
+
else:
|
1894 |
+
st.warning("Please enter policy text to analyze.")
|
1895 |
+
|
1896 |
+
|
1897 |
+
def legal_consultant_ui():
|
1898 |
+
st.subheader("Legal Consultant")
|
1899 |
+
with st.expander("How to use"):
|
1900 |
+
st.write('''Describe your legal situation or ask your legal question related to US law.
|
1901 |
+
LexAI will provide information and guidance based on its understanding of the US legal system.
|
1902 |
+
Please remember that this is not a substitute for real legal advice from a qualified attorney.''')
|
1903 |
+
|
1904 |
+
if 'consultant_history' not in st.session_state:
|
1905 |
+
st.session_state.consultant_history = []
|
1906 |
+
|
1907 |
+
display_chat_history()
|
1908 |
+
|
1909 |
+
user_input = st.text_area("Describe your legal situation or ask your question (US Law):", height=150)
|
1910 |
+
|
1911 |
+
if st.button("Get Legal Guidance"):
|
1912 |
+
if user_input:
|
1913 |
+
with st.spinner("Processing your request..."):
|
1914 |
+
ai_response = get_ai_response(user_input)
|
1915 |
+
st.session_state.consultant_history.append((user_input, ai_response))
|
1916 |
+
|
1917 |
+
# Web search for additional resources
|
1918 |
+
web_results = search_web_duckduckgo(user_input, num_results=3)
|
1919 |
+
st.session_state.consultant_history.append({
|
1920 |
+
'type': 'web_search',
|
1921 |
+
'results': web_results
|
1922 |
+
})
|
1923 |
+
|
1924 |
+
st.rerun()
|
1925 |
+
else:
|
1926 |
+
st.warning("Please enter your legal situation or question.")
|
1927 |
+
|
1928 |
+
|
1929 |
+
def draft_contract(contract_details: str) -> Dict[str, Any]:
|
1930 |
+
"""Drafts a contract based on the provided details."""
|
1931 |
+
drafting_prompt = f"""
|
1932 |
+
Draft a legally sound and comprehensive contract based on the following details, ensuring compliance with US law.
|
1933 |
+
|
1934 |
+
Contract Details:
|
1935 |
+
```
|
1936 |
+
{contract_details}
|
1937 |
+
```
|
1938 |
+
|
1939 |
+
Output Format:
|
1940 |
+
Present the drafted contract in a clear and organized manner, using sections and headings.
|
1941 |
+
Include the following essential clauses (and any others relevant to the provided details):
|
1942 |
+
|
1943 |
+
* Parties: Clearly identify the names and addresses of all parties entering into the contract.
|
1944 |
+
* Term and Termination: Specify the duration of the contract and conditions for renewal or termination.
|
1945 |
+
* Payment Terms: Outline payment details, including amounts, schedule, and methods.
|
1946 |
+
* Governing Law: State that the contract shall be governed by the laws of the state specified in the details.
|
1947 |
+
* Dispute Resolution: Include a clause outlining how disputes will be handled (e.g., mediation, arbitration).
|
1948 |
+
* Entire Agreement: State that the written contract represents the entire agreement between the parties.
|
1949 |
+
* Signatures: Leave space for the dated signatures of all parties involved.
|
1950 |
+
"""
|
1951 |
+
|
1952 |
+
try:
|
1953 |
+
contract_draft = get_ai_response(drafting_prompt)
|
1954 |
+
return {"draft": contract_draft}
|
1955 |
+
except Exception as e:
|
1956 |
+
return {"error": f"Error drafting contract: {str(e)}"}
|
1957 |
+
|
1958 |
+
def contract_drafting_ui():
|
1959 |
+
st.subheader("Contract Drafting Assistant")
|
1960 |
+
with st.expander("How to use"):
|
1961 |
+
st.write('''
|
1962 |
+
Provide details about the contract you need drafted, including:
|
1963 |
+
|
1964 |
+
* **Parties:** Names and addresses of all parties.
|
1965 |
+
* **Subject Matter:** Clearly describe the goods, services, or purpose of the contract.
|
1966 |
+
* **Key Terms:** Specify payment amounts, deadlines, delivery terms, or other crucial details.
|
1967 |
+
* **Governing Law:** State the US state whose laws will govern the contract.
|
1968 |
+
* **Additional Provisions:** Include any specific clauses, conditions, or requirements.
|
1969 |
+
|
1970 |
+
Be as clear and thorough as possible to ensure the drafted contract meets your needs.
|
1971 |
+
''')
|
1972 |
+
|
1973 |
+
contract_details = st.text_area("Enter contract details:", height=200)
|
1974 |
+
|
1975 |
+
if st.button("Draft Contract"):
|
1976 |
+
if contract_details:
|
1977 |
+
with st.spinner("Drafting your contract..."):
|
1978 |
+
draft_results = draft_contract(contract_details)
|
1979 |
+
|
1980 |
+
if "error" in draft_results:
|
1981 |
+
st.error(draft_results["error"])
|
1982 |
+
else:
|
1983 |
+
st.write("### Drafted Contract")
|
1984 |
+
contract_draft = draft_results.get("draft", "No draft available.")
|
1985 |
+
st.text_area("Contract Draft", contract_draft, height=300)
|
1986 |
+
|
1987 |
+
st.download_button(
|
1988 |
+
label="Download Contract",
|
1989 |
+
data=contract_draft,
|
1990 |
+
file_name="drafted_contract.txt",
|
1991 |
+
mime="text/plain"
|
1992 |
+
)
|
1993 |
+
else:
|
1994 |
+
st.warning("Please enter contract details to proceed.")
|
1995 |
+
|
1996 |
+
|
1997 |
+
def analyze_case_for_prediction(case_details: str) -> Dict[str, Any]:
|
1998 |
+
"""Analyzes the case details to provide a predictive analysis."""
|
1999 |
+
analysis_prompt = f"""
|
2000 |
+
Analyze the following case details in the context of the US legal system and provide a predictive analysis.
|
2001 |
+
|
2002 |
+
Case Details:
|
2003 |
+
```
|
2004 |
+
{case_details}
|
2005 |
+
```
|
2006 |
+
|
2007 |
+
Your analysis should address the following:
|
2008 |
+
|
2009 |
+
* **Case Summary:** Briefly summarize the key facts, legal claims, and parties involved in the case.
|
2010 |
+
* **Predicted Outcome:** What is the most likely outcome of this case based on the provided information, US legal precedents, and similar cases? Explain your reasoning.
|
2011 |
+
* **Strengths of the Case:** Identify the most compelling arguments and evidence that support a favorable outcome.
|
2012 |
+
* **Weaknesses of the Case:** What are potential weaknesses in the case, or areas where the opposing party might have strong arguments?
|
2013 |
+
* **Areas of Caution:** What potential pitfalls or challenges should be considered? What strategies could the opposing party use?
|
2014 |
+
* **Relevant US Case Law:** Cite specific US legal precedents and similar cases that support your analysis and predicted outcome.
|
2015 |
+
* **Recommended Strategies:** Offer specific, actionable recommendations on how to strengthen the case and increase the likelihood of a positive result.
|
2016 |
+
|
2017 |
+
Please maintain a neutral and objective tone throughout your analysis. The goal is to provide a realistic assessment of the case, not to advocate for a particular side.
|
2018 |
+
"""
|
2019 |
+
|
2020 |
+
try:
|
2021 |
+
analysis = get_ai_response(analysis_prompt)
|
2022 |
+
return {"analysis": analysis}
|
2023 |
+
except Exception as e:
|
2024 |
+
return {"error": f"Error analyzing case: {str(e)}"}
|
2025 |
+
|
2026 |
+
def predictive_analysis_ui():
|
2027 |
+
st.subheader("Predictive Case Analysis")
|
2028 |
+
with st.expander("How to use"):
|
2029 |
+
st.write('''Enter the details of your case, including:
|
2030 |
+
|
2031 |
+
* Facts: Briefly describe the key events that led to the legal dispute.
|
2032 |
+
* Legal Issues: State the specific legal questions or claims in the case.
|
2033 |
+
* Relevant Law: Identify any relevant US laws, statutes, or regulations.
|
2034 |
+
* Jurisdiction: Specify the US state where the case is filed.
|
2035 |
+
|
2036 |
+
You can also upload a document with this information.
|
2037 |
+
LexAI will provide a predictive analysis, outlining potential outcomes, strengths and weaknesses of the case, and relevant US case law.
|
2038 |
+
''')
|
2039 |
+
|
2040 |
+
input_method = st.radio("Choose input method:", ("Text Input", "Document Upload"))
|
2041 |
+
case_details = ""
|
2042 |
+
|
2043 |
+
if input_method == "Text Input":
|
2044 |
+
case_details = st.text_area("Enter case details:", height=200)
|
2045 |
+
else:
|
2046 |
+
uploaded_file = st.file_uploader("Upload a document containing case details (PDF, DOCX, or TXT)", type=["pdf", "docx", "txt"])
|
2047 |
+
if uploaded_file is not None:
|
2048 |
+
case_details = extract_text_from_document(uploaded_file)
|
2049 |
+
|
2050 |
+
if st.button("Analyze Case"):
|
2051 |
+
if case_details:
|
2052 |
+
with st.spinner("Analyzing your case..."):
|
2053 |
+
analysis_results = analyze_case_for_prediction(case_details)
|
2054 |
+
|
2055 |
+
st.write("### Case Analysis")
|
2056 |
+
if "error" in analysis_results:
|
2057 |
+
st.error(analysis_results["error"])
|
2058 |
+
else:
|
2059 |
+
st.write(analysis_results.get("analysis", "No analysis available."))
|
2060 |
+
else:
|
2061 |
+
st.warning("Please enter case details or upload a document to analyze.")
|
2062 |
+
|
2063 |
# Streamlit App
|
2064 |
st.markdown("""
|
2065 |
<style>
|