Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -116,13 +116,17 @@ with tab1:
|
|
116 |
|
117 |
with st.spinner("π¬ Analyzing..."):
|
118 |
while True:
|
119 |
-
status = client.beta.threads.runs.retrieve(
|
|
|
|
|
120 |
if status.status in ("completed", "failed", "cancelled"):
|
121 |
break
|
122 |
time.sleep(1)
|
123 |
|
124 |
if status.status == "completed":
|
125 |
-
responses = client.beta.threads.messages.list(
|
|
|
|
|
126 |
for m in reversed(responses):
|
127 |
if m.role == "assistant":
|
128 |
reply = m.content[0].text.value.strip()
|
@@ -130,6 +134,7 @@ with tab1:
|
|
130 |
for msg in st.session_state.messages if msg["role"] == "assistant"):
|
131 |
st.session_state.messages.append({"role": "assistant", "content": reply})
|
132 |
|
|
|
133 |
images = re.findall(
|
134 |
r'https://raw\.githubusercontent\.com/AndrewLORTech/witspathologai/main/[^\s\n"]+\.png',
|
135 |
reply
|
@@ -142,20 +147,27 @@ with tab1:
|
|
142 |
except Exception as e:
|
143 |
st.error(f"β Error: {e}")
|
144 |
|
|
|
145 |
for msg in st.session_state.messages:
|
146 |
with st.chat_message(msg["role"]):
|
147 |
st.markdown(msg["content"], unsafe_allow_html=True)
|
148 |
|
|
|
149 |
if st.session_state.messages and st.session_state.messages[-1]["role"] == "assistant":
|
150 |
last = st.session_state.messages[-1]["content"]
|
151 |
if "Some Possible Questions:" in last:
|
152 |
-
|
|
|
|
|
|
|
153 |
if questions:
|
154 |
st.markdown("#### π‘ Follow-Up Suggestions")
|
155 |
for q in questions:
|
156 |
if st.button(f"π {q}"):
|
157 |
st.session_state.pending_prompt = q
|
158 |
st.rerun()
|
|
|
|
|
159 |
|
160 |
with image_col:
|
161 |
if show_image and st.session_state.image_urls:
|
@@ -167,7 +179,6 @@ with tab1:
|
|
167 |
except Exception:
|
168 |
st.warning(f"β οΈ Failed to load image: {url}")
|
169 |
|
170 |
-
|
171 |
# ------------------ Tab 2: Visual Reference Search ------------------
|
172 |
with tab2:
|
173 |
ASSISTANT_ID = "asst_9v09zgizdcuuhNdcFQpRo9RO"
|
|
|
116 |
|
117 |
with st.spinner("π¬ Analyzing..."):
|
118 |
while True:
|
119 |
+
status = client.beta.threads.runs.retrieve(
|
120 |
+
thread_id=st.session_state.thread_id, run_id=run.id
|
121 |
+
)
|
122 |
if status.status in ("completed", "failed", "cancelled"):
|
123 |
break
|
124 |
time.sleep(1)
|
125 |
|
126 |
if status.status == "completed":
|
127 |
+
responses = client.beta.threads.messages.list(
|
128 |
+
thread_id=st.session_state.thread_id
|
129 |
+
).data
|
130 |
for m in reversed(responses):
|
131 |
if m.role == "assistant":
|
132 |
reply = m.content[0].text.value.strip()
|
|
|
134 |
for msg in st.session_state.messages if msg["role"] == "assistant"):
|
135 |
st.session_state.messages.append({"role": "assistant", "content": reply})
|
136 |
|
137 |
+
# Extract image URLs from response
|
138 |
images = re.findall(
|
139 |
r'https://raw\.githubusercontent\.com/AndrewLORTech/witspathologai/main/[^\s\n"]+\.png',
|
140 |
reply
|
|
|
147 |
except Exception as e:
|
148 |
st.error(f"β Error: {e}")
|
149 |
|
150 |
+
# Display messages
|
151 |
for msg in st.session_state.messages:
|
152 |
with st.chat_message(msg["role"]):
|
153 |
st.markdown(msg["content"], unsafe_allow_html=True)
|
154 |
|
155 |
+
# Display follow-up questions
|
156 |
if st.session_state.messages and st.session_state.messages[-1]["role"] == "assistant":
|
157 |
last = st.session_state.messages[-1]["content"]
|
158 |
if "Some Possible Questions:" in last:
|
159 |
+
# Filter only lines that are actual questions
|
160 |
+
all_lines = re.findall(r"[-β’]\s*(.*)", last)
|
161 |
+
questions = [line for line in all_lines if line.strip().endswith("?")]
|
162 |
+
|
163 |
if questions:
|
164 |
st.markdown("#### π‘ Follow-Up Suggestions")
|
165 |
for q in questions:
|
166 |
if st.button(f"π {q}"):
|
167 |
st.session_state.pending_prompt = q
|
168 |
st.rerun()
|
169 |
+
else:
|
170 |
+
st.markdown("#### π‘ No follow-up questions detected in the assistant's response.")
|
171 |
|
172 |
with image_col:
|
173 |
if show_image and st.session_state.image_urls:
|
|
|
179 |
except Exception:
|
180 |
st.warning(f"β οΈ Failed to load image: {url}")
|
181 |
|
|
|
182 |
# ------------------ Tab 2: Visual Reference Search ------------------
|
183 |
with tab2:
|
184 |
ASSISTANT_ID = "asst_9v09zgizdcuuhNdcFQpRo9RO"
|