Johan713 commited on
Commit
dba9928
·
verified ·
1 Parent(s): a6da302

Update app2.py

Browse files
Files changed (1) hide show
  1. app2.py +191 -69
app2.py CHANGED
@@ -1811,11 +1811,6 @@ 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
- 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"""
@@ -1851,17 +1846,25 @@ def analyze_policy(policy_text: str) -> Dict[str, Any]:
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:
@@ -1874,56 +1877,147 @@ def policy_analysis_ui():
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]:
@@ -1957,20 +2051,29 @@ def draft_contract(contract_details: str) -> Dict[str, Any]:
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:
@@ -1991,8 +2094,7 @@ def contract_drafting_ui():
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."""
@@ -2025,21 +2127,22 @@ def analyze_case_for_prediction(case_details: str) -> Dict[str, Any]:
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:
@@ -2057,6 +2160,25 @@ def predictive_analysis_ui():
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
 
@@ -2112,7 +2234,7 @@ with st.sidebar:
2112
 
2113
  feature = st.selectbox(
2114
  "Select a feature",
2115
- ["Legal Chatbot", "Document Analysis", "Case Precedent Finder", "Legal Cost Estimator", "Contract Analysis", "Case Trend Visualizer", "Case Information Retrieval", "Automated Legal Brief Generation", "Find the Lawyers", "Find the Lawyers", "Policy Analysis & Impact", "Legal Consultant", "Contract Drafting Assistant", "Predictive Case Analysis"]
2116
  )
2117
  if feature == "Legal Chatbot":
2118
  st.subheader("Legal Chatbot")
 
1811
  else:
1812
  st.warning(f"No lawyers found in {city}, {state}. Try selecting a different city or state.")
1813
 
 
 
 
 
 
1814
  def analyze_policy(policy_text: str) -> Dict[str, Any]:
1815
  """Analyzes the given policy text for its potential impact and benefits."""
1816
  analysis_prompt = f"""
 
1846
 
1847
  def policy_analysis_ui():
1848
  st.subheader("Policy Analysis & Impact")
1849
+ st.write('''
1850
+ Enter the US policy text you want to analyze or upload a document.
1851
+ LexAI will provide a comprehensive analysis of the policy's potential impact, benefits, drawbacks, and more.
1852
+ ''')
1853
+
1854
+ st.warning("Please do not upload files larger than 5MB as it may cause issues and consume all available tokens.")
1855
 
1856
  if 'policy_history' not in st.session_state:
1857
  st.session_state.policy_history = []
1858
 
1859
+ input_method = st.radio("Choose input method:", ("Text Input", "Document Upload"))
1860
+
1861
+ policy_text = ""
1862
+ if input_method == "Text Input":
1863
+ policy_text = st.text_area("Enter the US policy text:", height=200)
1864
+ else:
1865
+ uploaded_file = st.file_uploader("Upload a document containing policy text (PDF, DOCX, or TXT)", type=["pdf", "docx", "txt"])
1866
+ if uploaded_file is not None:
1867
+ policy_text = extract_text_from_document(uploaded_file)
1868
 
1869
  if st.button("Analyze Policy"):
1870
  if policy_text:
 
1877
  st.write("### Policy Analysis")
1878
  st.write(analysis_results.get("analysis", "No analysis available."))
1879
 
1880
+ # Add download button for analysis
1881
+ analysis_text = analysis_results.get("analysis", "No analysis available.")
1882
+ st.download_button(
1883
+ label="Download Analysis",
1884
+ data=analysis_text,
1885
+ file_name="policy_analysis.txt",
1886
+ mime="text/plain"
1887
+ )
1888
+
1889
  # Perform and display Wikipedia search
1890
  wiki_result = search_wikipedia(policy_text)
1891
+ st.write("### Wikipedia Summary")
1892
+ st.write(wiki_result.get("summary", "No summary available."))
1893
+ if wiki_result.get("url"):
1894
+ st.write(f"[Read more on Wikipedia]({wiki_result.get('url')})")
 
1895
 
1896
  # Perform and display web search
1897
  web_results = search_web_duckduckgo(policy_text)
1898
+ st.write("### Web Search Results")
1899
+ for result in web_results:
1900
+ st.write(f"**{result.get('title', 'No title')}**")
1901
+ st.write(result.get('snippet', 'No snippet available.'))
1902
+ st.write(f"[Read more]({result.get('link', '#')})")
1903
+ st.write("---")
1904
+
1905
  st.session_state.policy_history.append({
1906
+ 'type': 'analysis',
1907
+ 'text': policy_text,
1908
+ 'analysis': analysis_results.get("analysis", "No analysis available."),
1909
+ 'wikipedia': wiki_result,
1910
+ 'web_results': web_results
1911
  })
1912
 
1913
+ st.rerun()
1914
  else:
1915
+ st.warning("Please enter policy text or upload a document to analyze.")
1916
 
1917
+ display_chat_history()
1918
 
1919
+ def provide_legal_advice(user_input: str) -> Dict[str, Any]:
1920
+ """Provides legal advice based on the user input and performs web searches."""
1921
+ advice_prompt = f"""
1922
+ Provide legal advice based on US law for the following situation or question:
 
 
1923
 
1924
+ User Input:
1925
+ ```
1926
+ {user_input}
1927
+ ```
1928
 
1929
+ Please include:
1930
+ 1. A summary of the legal issue or question
1931
+ 2. Relevant US laws or regulations that apply
1932
+ 3. Possible legal implications or consequences
1933
+ 4. General advice or next steps (without constituting specific legal counsel)
1934
+ 5. Any important disclaimers or limitations of this advice
1935
 
1936
+ Remember to maintain a professional and objective tone throughout your response.
1937
+ """
1938
 
1939
+ try:
1940
+ legal_advice = get_ai_response(advice_prompt)
1941
+ web_results = search_web_duckduckgo(user_input, num_results=3)
1942
+
1943
+ return {
1944
+ "advice": legal_advice,
1945
+ "web_results": web_results
1946
+ }
1947
+ except Exception as e:
1948
+ return {"error": f"Error providing legal advice: {str(e)}"}
1949
 
1950
+ def legal_consultant_ui():
1951
+ st.subheader("Legal Consultant")
1952
+
1953
+ if 'chat_history' not in st.session_state:
1954
+ st.session_state.chat_history = []
1955
+
1956
+ if 'uploaded_document' not in st.session_state:
1957
+ st.session_state.uploaded_document = None
1958
+
1959
+ st.write('''
1960
+ Describe your legal situation or ask your legal question related to US law.
1961
+ LexAI will provide information and guidance based on its understanding of the US legal system.
1962
+ Please remember that this is not a substitute for real legal advice from a qualified attorney.
1963
+ ''')
1964
 
1965
+ st.warning("Please do not upload files larger than 5MB as it may cause issues and consume all available tokens.")
1966
+
1967
+ # Document upload
1968
+ uploaded_file = st.file_uploader("Upload a legal document (PDF, DOCX, or TXT)", type=["pdf", "docx", "txt"])
1969
+
1970
+ if uploaded_file:
1971
+ st.session_state.uploaded_document = extract_text_from_document(uploaded_file)
1972
+ st.success("Document uploaded successfully!")
1973
+
1974
+ display_chat_history_legal_advise()
1975
+
1976
+ user_input = st.text_input("Your legal question:")
1977
+
1978
+ if user_input and st.button("Send"):
1979
+ with st.spinner("Processing your question..."):
1980
+ if st.session_state.uploaded_document:
1981
+ # If a document is uploaded, use it as context
1982
+ full_input = f"Document context: {st.session_state.uploaded_document}\n\nUser question: {user_input}"
1983
+ else:
1984
+ full_input = user_input
1985
+
1986
+ result = provide_legal_advice(full_input)
1987
+
1988
+ if "error" in result:
1989
+ st.error(result["error"])
1990
+ else:
1991
+ st.session_state.chat_history.append(("User", user_input))
1992
+ st.session_state.chat_history.append(("Lex AI", result["advice"]))
1993
+
1994
+ st.write("### Web Search Results")
1995
+ for web_result in result["web_results"]:
1996
+ st.write(f"**{web_result.get('title', 'No title')}**")
1997
+ st.write(web_result.get('snippet', 'No snippet available.'))
1998
+ st.write(f"[Read more]({web_result.get('link', '#')})")
1999
+ st.write("---")
2000
+
2001
+ st.rerun()
2002
+
2003
+ def display_chat_history_legal_advise():
2004
+ for entry in st.session_state.chat_history:
2005
+ if isinstance(entry, tuple):
2006
+ sender, message = entry
2007
+ if sender == "User":
2008
+ st.write(f"**You:** {message}")
2009
+ else:
2010
+ st.write(f"**AI:** {message}")
2011
+ elif isinstance(entry, dict):
2012
+ if entry.get('type') == 'web_search':
2013
+ st.write("### Web Search Results")
2014
+ for result in entry.get('results', []):
2015
+ st.write(f"**{result.get('title', 'No title')}**")
2016
+ st.write(result.get('snippet', 'No snippet available.'))
2017
+ st.write(f"[Read more]({result.get('link', '#')})")
2018
+ st.write("---")
2019
+
2020
+ # Make sure to include the extract_text_from_document function as previously defined
2021
 
2022
 
2023
  def draft_contract(contract_details: str) -> Dict[str, Any]:
 
2051
 
2052
  def contract_drafting_ui():
2053
  st.subheader("Contract Drafting Assistant")
2054
+ st.write('''
2055
+ Provide details about the contract you need drafted, including:
 
2056
 
2057
+ * Parties: Names and addresses of all parties.
2058
+ * Subject Matter: Clearly describe the goods, services, or purpose of the contract.
2059
+ * Key Terms: Specify payment amounts, deadlines, delivery terms, or other crucial details.
2060
+ * Governing Law: State the US state whose laws will govern the contract.
2061
+ * Additional Provisions: Include any specific clauses, conditions, or requirements.
2062
 
2063
+ Be as clear and thorough as possible to ensure the drafted contract meets your needs.
2064
+ ''')
2065
 
2066
+ st.warning("Please do not upload files larger than 5MB as it may cause issues and consume all available tokens.")
2067
+
2068
+ input_method = st.radio("Choose input method:", ("Text Input", "Document Upload"))
2069
+
2070
+ contract_details = ""
2071
+ if input_method == "Text Input":
2072
+ contract_details = st.text_area("Enter contract details:", height=200)
2073
+ else:
2074
+ uploaded_file = st.file_uploader("Upload a document containing contract details (PDF, DOCX, or TXT)", type=["pdf", "docx", "txt"])
2075
+ if uploaded_file is not None:
2076
+ contract_details = extract_text_from_document(uploaded_file)
2077
 
2078
  if st.button("Draft Contract"):
2079
  if contract_details:
 
2094
  mime="text/plain"
2095
  )
2096
  else:
2097
+ st.warning("Please enter contract details or upload a document to proceed.")
 
2098
 
2099
  def analyze_case_for_prediction(case_details: str) -> Dict[str, Any]:
2100
  """Analyzes the case details to provide a predictive analysis."""
 
2127
 
2128
  def predictive_analysis_ui():
2129
  st.subheader("Predictive Case Analysis")
2130
+ st.write('''
2131
+ Enter the details of your case, including:
2132
+
2133
+ * Facts: Briefly describe the key events that led to the legal dispute.
2134
+ * Legal Issues: State the specific legal questions or claims in the case.
2135
+ * Relevant Law: Identify any relevant US laws, statutes, or regulations.
2136
+ * Jurisdiction: Specify the US state where the case is filed.
2137
 
2138
+ LexAI will provide a predictive analysis, outlining potential outcomes, strengths and weaknesses of the case, and relevant US case law.
2139
+ ''')
 
 
2140
 
2141
+ st.warning("Please do not upload files larger than 5MB as it may cause issues and consume all available tokens.")
 
 
2142
 
2143
  input_method = st.radio("Choose input method:", ("Text Input", "Document Upload"))
2144
+
2145
  case_details = ""
 
2146
  if input_method == "Text Input":
2147
  case_details = st.text_area("Enter case details:", height=200)
2148
  else:
 
2160
  st.error(analysis_results["error"])
2161
  else:
2162
  st.write(analysis_results.get("analysis", "No analysis available."))
2163
+
2164
+ # Add download button for analysis
2165
+ analysis_text = analysis_results.get("analysis", "No analysis available.")
2166
+ st.download_button(
2167
+ label="Download Analysis",
2168
+ data=analysis_text,
2169
+ file_name="case_analysis.txt",
2170
+ mime="text/plain"
2171
+ )
2172
+
2173
+ # Perform and display web search
2174
+ web_results = search_web_duckduckgo(case_details)
2175
+ st.write("### Related Web Resources")
2176
+ for result in web_results:
2177
+ st.write(f"**{result.get('title', 'No title')}**")
2178
+ st.write(result.get('snippet', 'No snippet available.'))
2179
+ st.write(f"[Read more]({result.get('link', '#')})")
2180
+ st.write("---")
2181
+
2182
  else:
2183
  st.warning("Please enter case details or upload a document to analyze.")
2184
 
 
2234
 
2235
  feature = st.selectbox(
2236
  "Select a feature",
2237
+ ["Legal Chatbot", "Document Analysis", "Case Precedent Finder", "Legal Cost Estimator", "Contract Analysis", "Case Trend Visualizer", "Case Information Retrieval", "Automated Legal Brief Generation", "Find the Lawyers", "Policy Analysis & Impact", "Legal Consultant", "Contract Drafting Assistant", "Predictive Case Analysis"]
2238
  )
2239
  if feature == "Legal Chatbot":
2240
  st.subheader("Legal Chatbot")