Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -184,19 +184,27 @@ with tab1:
|
|
184 |
# ------------------ Technical Tab ------------------
|
185 |
with tab2:
|
186 |
ASSISTANT_ID = "asst_DjvuWBc7tCvMbAhY7n1em4BZ"
|
|
|
|
|
187 |
if "tech_messages" not in st.session_state:
|
188 |
st.session_state.tech_messages = []
|
189 |
if "tech_thread_id" not in st.session_state:
|
190 |
st.session_state.tech_thread_id = None
|
191 |
if "tech_results" not in st.session_state:
|
192 |
st.session_state.tech_results = []
|
193 |
-
st.session_state
|
|
|
|
|
|
|
194 |
|
|
|
195 |
tech_input = st.chat_input("Ask about plans, drawings or components")
|
196 |
if tech_input:
|
197 |
st.session_state.tech_messages.append({"role": "user", "content": tech_input})
|
|
|
198 |
|
199 |
-
if
|
|
|
200 |
try:
|
201 |
if st.session_state.tech_thread_id is None:
|
202 |
thread = client.beta.threads.create()
|
@@ -234,15 +242,21 @@ with tab2:
|
|
234 |
except:
|
235 |
st.session_state.tech_results = []
|
236 |
break
|
|
|
|
|
237 |
except Exception as e:
|
238 |
st.error(f"β Technical Assistant Error: {e}")
|
|
|
|
|
239 |
|
|
|
240 |
with st.expander("π§ Options (Filter + Pagination)", expanded=False):
|
241 |
disciplines = sorted(set(d.get("discipline", "") for d in st.session_state.tech_results))
|
242 |
selected = st.selectbox("π Filter by discipline", ["All"] + disciplines)
|
243 |
page_size = 8
|
244 |
page = st.number_input("Page", min_value=1, step=1, value=1)
|
245 |
|
|
|
246 |
if st.session_state.tech_results:
|
247 |
st.subheader("π Results")
|
248 |
results = [r for r in st.session_state.tech_results if selected == "All" or r.get("discipline") == selected]
|
@@ -265,4 +279,4 @@ with tab2:
|
|
265 |
else:
|
266 |
for msg in st.session_state.tech_messages:
|
267 |
with st.chat_message(msg["role"]):
|
268 |
-
st.markdown(msg["content"], unsafe_allow_html=True)
|
|
|
184 |
# ------------------ Technical Tab ------------------
|
185 |
with tab2:
|
186 |
ASSISTANT_ID = "asst_DjvuWBc7tCvMbAhY7n1em4BZ"
|
187 |
+
|
188 |
+
# Initialize session state variables
|
189 |
if "tech_messages" not in st.session_state:
|
190 |
st.session_state.tech_messages = []
|
191 |
if "tech_thread_id" not in st.session_state:
|
192 |
st.session_state.tech_thread_id = None
|
193 |
if "tech_results" not in st.session_state:
|
194 |
st.session_state.tech_results = []
|
195 |
+
if "tech_new_input" not in st.session_state:
|
196 |
+
st.session_state.tech_new_input = False
|
197 |
+
if "tech_lightbox" not in st.session_state:
|
198 |
+
st.session_state.tech_lightbox = None
|
199 |
|
200 |
+
# Input box
|
201 |
tech_input = st.chat_input("Ask about plans, drawings or components")
|
202 |
if tech_input:
|
203 |
st.session_state.tech_messages.append({"role": "user", "content": tech_input})
|
204 |
+
st.session_state.tech_new_input = True # Flag to process this new input
|
205 |
|
206 |
+
# Run assistant only if new input was entered
|
207 |
+
if st.session_state.tech_new_input:
|
208 |
try:
|
209 |
if st.session_state.tech_thread_id is None:
|
210 |
thread = client.beta.threads.create()
|
|
|
242 |
except:
|
243 |
st.session_state.tech_results = []
|
244 |
break
|
245 |
+
else:
|
246 |
+
st.error("β Assistant run failed.")
|
247 |
except Exception as e:
|
248 |
st.error(f"β Technical Assistant Error: {e}")
|
249 |
+
finally:
|
250 |
+
st.session_state.tech_new_input = False # Reset the flag
|
251 |
|
252 |
+
# Filtering & Pagination UI
|
253 |
with st.expander("π§ Options (Filter + Pagination)", expanded=False):
|
254 |
disciplines = sorted(set(d.get("discipline", "") for d in st.session_state.tech_results))
|
255 |
selected = st.selectbox("π Filter by discipline", ["All"] + disciplines)
|
256 |
page_size = 8
|
257 |
page = st.number_input("Page", min_value=1, step=1, value=1)
|
258 |
|
259 |
+
# Results display
|
260 |
if st.session_state.tech_results:
|
261 |
st.subheader("π Results")
|
262 |
results = [r for r in st.session_state.tech_results if selected == "All" or r.get("discipline") == selected]
|
|
|
279 |
else:
|
280 |
for msg in st.session_state.tech_messages:
|
281 |
with st.chat_message(msg["role"]):
|
282 |
+
st.markdown(msg["content"], unsafe_allow_html=True)
|