Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -61,17 +61,15 @@ if "pending_prompt" not in st.session_state:
|
|
61 |
# ------------------ Tabs ------------------
|
62 |
tab1, tab2 = st.tabs(["💬 Chat Assistant", "🖼️ Visual Reference Search"])
|
63 |
|
64 |
-
# ------------------ Tab 1
|
65 |
with tab1:
|
66 |
-
st.
|
67 |
-
|
68 |
-
|
69 |
-
with col2:
|
70 |
-
st.markdown("### 🔧 Tools")
|
71 |
if st.button("🧹 Clear Chat"):
|
72 |
st.session_state.messages = []
|
73 |
st.session_state.thread_id = None
|
74 |
-
st.session_state.
|
|
|
75 |
st.session_state.pending_prompt = None
|
76 |
st.rerun()
|
77 |
|
@@ -92,10 +90,13 @@ with tab1:
|
|
92 |
"Extract diagnostic markers",
|
93 |
"Summarize embryology stages"
|
94 |
])
|
95 |
-
if action != "Select an action...":
|
96 |
st.session_state.pending_prompt = action
|
|
|
97 |
|
98 |
-
|
|
|
|
|
99 |
user_input = st.chat_input("Example: What are features of squamous cell carcinoma?")
|
100 |
if user_input:
|
101 |
st.session_state.messages.append({"role": "user", "content": user_input})
|
@@ -134,8 +135,11 @@ with tab1:
|
|
134 |
reply = m.content[0].text.value.strip()
|
135 |
if not any(reply in msg["content"] or msg["content"] in reply for msg in st.session_state.messages if msg["role"] == "assistant"):
|
136 |
st.session_state.messages.append({"role": "assistant", "content": reply})
|
|
|
137 |
image_matches = re.findall(r'https://raw\.githubusercontent\.com/AndrewLORTech/witspathologai/main/[^\s\n"]+\.png', reply)
|
138 |
-
|
|
|
|
|
139 |
break
|
140 |
else:
|
141 |
st.error("❌ Assistant failed to respond.")
|
@@ -147,17 +151,16 @@ with tab1:
|
|
147 |
with st.chat_message(msg["role"]):
|
148 |
st.markdown(msg["content"], unsafe_allow_html=True)
|
149 |
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
# ------------------ Tab 2: Visual Reference Search ------------------
|
162 |
with tab2:
|
163 |
ASSISTANT_ID = "asst_9v09zgizdcuuhNdcFQpRo9RO"
|
|
|
61 |
# ------------------ Tabs ------------------
|
62 |
tab1, tab2 = st.tabs(["💬 Chat Assistant", "🖼️ Visual Reference Search"])
|
63 |
|
64 |
+
# ------------------ Tab 1 ------------------
|
65 |
with tab1:
|
66 |
+
with st.sidebar:
|
67 |
+
st.header("🔧 Tools")
|
|
|
|
|
|
|
68 |
if st.button("🧹 Clear Chat"):
|
69 |
st.session_state.messages = []
|
70 |
st.session_state.thread_id = None
|
71 |
+
st.session_state.image_url = None
|
72 |
+
st.session_state.image_updated = False
|
73 |
st.session_state.pending_prompt = None
|
74 |
st.rerun()
|
75 |
|
|
|
90 |
"Extract diagnostic markers",
|
91 |
"Summarize embryology stages"
|
92 |
])
|
93 |
+
if action and action != "Select an action...":
|
94 |
st.session_state.pending_prompt = action
|
95 |
+
st.rerun()
|
96 |
|
97 |
+
chat_col, image_col = st.columns([2, 1])
|
98 |
+
with chat_col:
|
99 |
+
st.markdown("### 💬 Ask a Pathology-Specific Question")
|
100 |
user_input = st.chat_input("Example: What are features of squamous cell carcinoma?")
|
101 |
if user_input:
|
102 |
st.session_state.messages.append({"role": "user", "content": user_input})
|
|
|
135 |
reply = m.content[0].text.value.strip()
|
136 |
if not any(reply in msg["content"] or msg["content"] in reply for msg in st.session_state.messages if msg["role"] == "assistant"):
|
137 |
st.session_state.messages.append({"role": "assistant", "content": reply})
|
138 |
+
|
139 |
image_matches = re.findall(r'https://raw\.githubusercontent\.com/AndrewLORTech/witspathologai/main/[^\s\n"]+\.png', reply)
|
140 |
+
if image_matches:
|
141 |
+
st.session_state.image_url = image_matches[0]
|
142 |
+
st.session_state.image_updated = True
|
143 |
break
|
144 |
else:
|
145 |
st.error("❌ Assistant failed to respond.")
|
|
|
151 |
with st.chat_message(msg["role"]):
|
152 |
st.markdown(msg["content"], unsafe_allow_html=True)
|
153 |
|
154 |
+
with image_col:
|
155 |
+
if show_image and st.session_state.image_url:
|
156 |
+
try:
|
157 |
+
r = requests.get(st.session_state.image_url)
|
158 |
+
r.raise_for_status()
|
159 |
+
img = Image.open(BytesIO(r.content))
|
160 |
+
st.image(img, caption="📄 Referenced Image", use_container_width=True)
|
161 |
+
except Exception as e:
|
162 |
+
st.error(f"🖼️ Failed to load image: {e}")
|
163 |
+
|
|
|
164 |
# ------------------ Tab 2: Visual Reference Search ------------------
|
165 |
with tab2:
|
166 |
ASSISTANT_ID = "asst_9v09zgizdcuuhNdcFQpRo9RO"
|