IAMTFRMZA commited on
Commit
df99638
ยท
verified ยท
1 Parent(s): 42e0794

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -6
app.py CHANGED
@@ -55,18 +55,31 @@ tab1, tab2 = st.tabs(["๐Ÿ“‘ Contract", "๐Ÿ“ Technical"])
55
  with tab1:
56
  ASSISTANT_ID = "asst_KsQRedoJUnEeStzfox1o06lO"
57
 
58
- for key in ["messages", "thread_id", "image_url", "image_updated", "pending_prompt"]:
59
- if key not in st.session_state:
60
- st.session_state[key] = None if "url" in key else []
61
-
 
 
 
 
 
 
 
 
 
62
  with st.sidebar:
63
  st.header("โ„น๏ธ Contract Tools")
64
  if st.button("๐Ÿงน Clear Chat"):
65
- for k in ["messages", "thread_id", "image_url", "image_updated", "pending_prompt"]:
66
- st.session_state[k] = None if "url" in k else []
 
 
 
67
  st.rerun()
68
 
69
  show_image = st.toggle("๐Ÿ“‘ Show Page Image", value=True)
 
70
  keyword = st.text_input("Search by Keyword", placeholder="e.g. defects, WHS, delay")
71
  if st.button("๐Ÿ”Ž Search Keyword") and keyword:
72
  st.session_state.pending_prompt = f"Find clauses or references related to: {keyword}"
@@ -99,6 +112,7 @@ with tab1:
99
  if action != actions[0]:
100
  st.session_state.pending_prompt = action
101
 
 
102
  chat_col, image_col = st.columns([2, 1])
103
  with chat_col:
104
  st.markdown("### ๐Ÿง  Ask a Document-Specific Question")
 
55
  with tab1:
56
  ASSISTANT_ID = "asst_KsQRedoJUnEeStzfox1o06lO"
57
 
58
+ # Correct session state initialization
59
+ if "messages" not in st.session_state:
60
+ st.session_state.messages = []
61
+ if "thread_id" not in st.session_state:
62
+ st.session_state.thread_id = None
63
+ if "image_url" not in st.session_state:
64
+ st.session_state.image_url = None
65
+ if "image_updated" not in st.session_state:
66
+ st.session_state.image_updated = False
67
+ if "pending_prompt" not in st.session_state:
68
+ st.session_state.pending_prompt = None
69
+
70
+ # Sidebar tools
71
  with st.sidebar:
72
  st.header("โ„น๏ธ Contract Tools")
73
  if st.button("๐Ÿงน Clear Chat"):
74
+ st.session_state.messages = []
75
+ st.session_state.thread_id = None
76
+ st.session_state.image_url = None
77
+ st.session_state.image_updated = False
78
+ st.session_state.pending_prompt = None
79
  st.rerun()
80
 
81
  show_image = st.toggle("๐Ÿ“‘ Show Page Image", value=True)
82
+
83
  keyword = st.text_input("Search by Keyword", placeholder="e.g. defects, WHS, delay")
84
  if st.button("๐Ÿ”Ž Search Keyword") and keyword:
85
  st.session_state.pending_prompt = f"Find clauses or references related to: {keyword}"
 
112
  if action != actions[0]:
113
  st.session_state.pending_prompt = action
114
 
115
+ # Chat + Image layout
116
  chat_col, image_col = st.columns([2, 1])
117
  with chat_col:
118
  st.markdown("### ๐Ÿง  Ask a Document-Specific Question")