Johan713 commited on
Commit
c7a4da1
·
verified ·
1 Parent(s): 5df8fec

Update app2.py

Browse files
Files changed (1) hide show
  1. app2.py +20 -16
app2.py CHANGED
@@ -1953,6 +1953,9 @@ def legal_consultant_ui():
1953
  if 'uploaded_document' not in st.session_state:
1954
  st.session_state.uploaded_document = None
1955
 
 
 
 
1956
  st.write('''
1957
  Describe your legal situation or ask your legal question related to US law.
1958
  LexAI will provide information and guidance based on its understanding of the US legal system.
@@ -1967,6 +1970,14 @@ def legal_consultant_ui():
1967
  st.session_state.uploaded_document = extract_text_from_document(uploaded_file)
1968
  st.success("Document uploaded successfully!")
1969
 
 
 
 
 
 
 
 
 
1970
  for message in st.session_state.consultant_chat_history:
1971
  if isinstance(message, tuple):
1972
  user_msg, bot_msg = message
@@ -1977,32 +1988,25 @@ def legal_consultant_ui():
1977
  web_results_msg = "Web Search Results:\n"
1978
  for result in message.get('results', []):
1979
  web_results_msg += f"[{result.get('title', 'No title')}]({result.get('link', '#')})\n{result.get('snippet', 'No snippet available.')}\n\n"
1980
- st.success(f"**Lex AI:** {web_results_msg}")
1981
 
1982
  user_input = st.text_input("Your legal question:")
1983
 
1984
  if user_input and st.button("Send"):
1985
  with st.spinner("Processing your question..."):
1986
- if st.session_state.uploaded_document:
1987
- full_input = f"Document context: {st.session_state.uploaded_document}\n\nUser question: {user_input}"
 
1988
  else:
1989
- full_input = user_input
1990
-
1991
- result = provide_legal_advice(full_input)
1992
-
1993
- if "error" in result:
1994
- st.error(result["error"])
1995
- else:
1996
- st.session_state.consultant_chat_history.append((user_input, result["advice"]))
1997
-
1998
- # Generate web search query and perform search
1999
- search_query = generate_web_search_query(user_input)
2000
- web_results = search_web_duckduckgo(search_query)
2001
 
 
 
2002
  st.session_state.consultant_chat_history.append({
2003
  'type': 'web_search',
2004
  'results': web_results
2005
- })
2006
 
2007
  st.rerun()
2008
 
 
1953
  if 'uploaded_document' not in st.session_state:
1954
  st.session_state.uploaded_document = None
1955
 
1956
+ if 'consultant_chat_mode' not in st.session_state: # New variable for consultant chat mode
1957
+ st.session_state.consultant_chat_mode = "normal"
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.
 
1970
  st.session_state.uploaded_document = extract_text_from_document(uploaded_file)
1971
  st.success("Document uploaded successfully!")
1972
 
1973
+ # Chat mode toggle for Legal Consultant
1974
+ if st.session_state.uploaded_document:
1975
+ if st.button("Switch Chat Mode"):
1976
+ st.session_state.consultant_chat_mode = "document" if st.session_state.consultant_chat_mode == "normal" else "normal"
1977
+
1978
+ st.write(f"Current mode: {'Document-based' if st.session_state.consultant_chat_mode == 'document' else 'Normal'} chat")
1979
+
1980
+ # Display chat history (similar to Legal Chatbot)
1981
  for message in st.session_state.consultant_chat_history:
1982
  if isinstance(message, tuple):
1983
  user_msg, bot_msg = message
 
1988
  web_results_msg = "Web Search Results:\n"
1989
  for result in message.get('results', []):
1990
  web_results_msg += f"[{result.get('title', 'No title')}]({result.get('link', '#')})\n{result.get('snippet', 'No snippet available.')}\n\n"
1991
+ st.success(f"**Lex AI:** {web_results_msg}")
1992
 
1993
  user_input = st.text_input("Your legal question:")
1994
 
1995
  if user_input and st.button("Send"):
1996
  with st.spinner("Processing your question..."):
1997
+ if st.session_state.consultant_chat_mode == "document" and st.session_state.uploaded_document:
1998
+ ai_response = get_document_based_response(user_input, st.session_state.uploaded_document) # Assuming you have this function
1999
+ st.session_state.consultant_chat_history.append((user_input, ai_response))
2000
  else:
2001
+ ai_response = provide_legal_advice(user_input)
2002
+ st.session_state.consultant_chat_history.append((user_input, ai_response))
 
 
 
 
 
 
 
 
 
 
2003
 
2004
+ # Perform web search (same as Legal Chatbot)
2005
+ web_results = search_web_duckduckgo(user_input) # Using user_input directly here
2006
  st.session_state.consultant_chat_history.append({
2007
  'type': 'web_search',
2008
  'results': web_results
2009
+ })
2010
 
2011
  st.rerun()
2012