Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -63,8 +63,11 @@ tab1, tab2 = st.tabs(["💬 Chat Assistant", "🖼️ Visual Reference Search"])
|
|
63 |
|
64 |
# ------------------ Tab 1: Chat Assistant ------------------
|
65 |
with tab1:
|
66 |
-
|
67 |
-
|
|
|
|
|
|
|
68 |
if st.button("🧹 Clear Chat"):
|
69 |
st.session_state.messages = []
|
70 |
st.session_state.thread_id = None
|
@@ -78,25 +81,21 @@ with tab1:
|
|
78 |
st.session_state.pending_prompt = f"Find clauses or references related to: {keyword}"
|
79 |
|
80 |
section = st.text_input("Section Lookup", placeholder="e.g. Connective Tissue")
|
81 |
-
if section:
|
82 |
st.session_state.pending_prompt = f"Summarize or list key points from section: {section}"
|
83 |
|
84 |
-
|
85 |
"Select an action...",
|
86 |
"List histological features of inflammation",
|
87 |
"Summarize features of carcinoma",
|
88 |
"List muscle types and features",
|
89 |
"Extract diagnostic markers",
|
90 |
"Summarize embryology stages"
|
91 |
-
]
|
92 |
-
action
|
93 |
-
if action != actions[0]:
|
94 |
st.session_state.pending_prompt = action
|
95 |
|
96 |
-
|
97 |
-
|
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})
|
@@ -133,16 +132,9 @@ with tab1:
|
|
133 |
for m in reversed(messages.data):
|
134 |
if m.role == "assistant":
|
135 |
reply = m.content[0].text.value.strip()
|
136 |
-
|
137 |
-
reply in msg["content"] or msg["content"] in reply
|
138 |
-
for msg in st.session_state.messages if msg["role"] == "assistant"
|
139 |
-
)
|
140 |
-
if not is_duplicate:
|
141 |
st.session_state.messages.append({"role": "assistant", "content": reply})
|
142 |
-
image_matches = re.findall(
|
143 |
-
r'https://raw\.githubusercontent\.com/AndrewLORTech/witspathologai/main/[^\s\n"]+\.png',
|
144 |
-
reply
|
145 |
-
)
|
146 |
st.session_state.image_urls = image_matches
|
147 |
break
|
148 |
else:
|
@@ -155,9 +147,8 @@ with tab1:
|
|
155 |
with st.chat_message(msg["role"]):
|
156 |
st.markdown(msg["content"], unsafe_allow_html=True)
|
157 |
|
158 |
-
|
159 |
-
|
160 |
-
st.markdown("### 🖼️ Image(s)")
|
161 |
for raw_url in st.session_state.image_urls:
|
162 |
try:
|
163 |
r = requests.get(raw_url, timeout=5)
|
|
|
63 |
|
64 |
# ------------------ Tab 1: Chat Assistant ------------------
|
65 |
with tab1:
|
66 |
+
st.markdown("## 💬 Ask a Pathology-Specific Question")
|
67 |
+
col1, col2 = st.columns([2, 1])
|
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
|
|
|
81 |
st.session_state.pending_prompt = f"Find clauses or references related to: {keyword}"
|
82 |
|
83 |
section = st.text_input("Section Lookup", placeholder="e.g. Connective Tissue")
|
84 |
+
if st.button("📑 Lookup") and section:
|
85 |
st.session_state.pending_prompt = f"Summarize or list key points from section: {section}"
|
86 |
|
87 |
+
action = st.selectbox("📂 Common Pathology Queries", [
|
88 |
"Select an action...",
|
89 |
"List histological features of inflammation",
|
90 |
"Summarize features of carcinoma",
|
91 |
"List muscle types and features",
|
92 |
"Extract diagnostic markers",
|
93 |
"Summarize embryology stages"
|
94 |
+
])
|
95 |
+
if action != "Select an action...":
|
|
|
96 |
st.session_state.pending_prompt = action
|
97 |
|
98 |
+
with col1:
|
|
|
|
|
|
|
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})
|
|
|
132 |
for m in reversed(messages.data):
|
133 |
if m.role == "assistant":
|
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 |
st.session_state.image_urls = image_matches
|
139 |
break
|
140 |
else:
|
|
|
147 |
with st.chat_message(msg["role"]):
|
148 |
st.markdown(msg["content"], unsafe_allow_html=True)
|
149 |
|
150 |
+
if show_image and st.session_state.image_urls:
|
151 |
+
with st.expander("🖼️ Referenced Image(s)", expanded=True):
|
|
|
152 |
for raw_url in st.session_state.image_urls:
|
153 |
try:
|
154 |
r = requests.get(raw_url, timeout=5)
|