Update app.py
Browse files
app.py
CHANGED
|
@@ -213,11 +213,18 @@ def generate_response(db, query_text, previous_context):
|
|
| 213 |
|
| 214 |
return full_response
|
| 215 |
|
|
|
|
|
|
|
| 216 |
def streamlit_app():
|
| 217 |
st.title("BioModelsRAG")
|
| 218 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 219 |
search_str = st.text_input("Enter search query:")
|
| 220 |
-
|
| 221 |
if search_str:
|
| 222 |
cached_data = fetch_github_json()
|
| 223 |
models = search_models(search_str, cached_data)
|
|
@@ -245,13 +252,11 @@ def streamlit_app():
|
|
| 245 |
final_items.extend(split_biomodels(antimony_file_path))
|
| 246 |
|
| 247 |
if final_items:
|
| 248 |
-
db = create_vector_db(final_items)
|
| 249 |
st.write("Models have been processed and added to the database.")
|
| 250 |
else:
|
| 251 |
st.error("No items found in the models. Check if the Antimony files were generated correctly.")
|
| 252 |
|
| 253 |
-
st.write("Models have been processed and written to the database.")
|
| 254 |
-
|
| 255 |
# Avoid caching the database initialization, or ensure it's properly updated.
|
| 256 |
@st.cache_resource
|
| 257 |
def get_messages():
|
|
@@ -264,15 +269,16 @@ def streamlit_app():
|
|
| 264 |
for message in st.session_state.messages:
|
| 265 |
with st.chat_message(message["role"]):
|
| 266 |
st.markdown(message["content"])
|
| 267 |
-
|
|
|
|
| 268 |
if prompt := st.chat_input("Ask a question about the models:"):
|
| 269 |
st.chat_message("user").markdown(prompt)
|
| 270 |
st.session_state.messages.append({"role": "user", "content": prompt})
|
| 271 |
-
|
| 272 |
-
if db is None:
|
| 273 |
st.error("Database is not initialized. Please process the models first.")
|
| 274 |
else:
|
| 275 |
-
response = generate_response(db, prompt, st.session_state.messages)
|
| 276 |
|
| 277 |
with st.chat_message("assistant"):
|
| 278 |
st.markdown(response)
|
|
|
|
| 213 |
|
| 214 |
return full_response
|
| 215 |
|
| 216 |
+
import streamlit as st
|
| 217 |
+
|
| 218 |
def streamlit_app():
|
| 219 |
st.title("BioModelsRAG")
|
| 220 |
|
| 221 |
+
# Initialize db in session state if not already present
|
| 222 |
+
if "db" not in st.session_state:
|
| 223 |
+
st.session_state.db = None
|
| 224 |
+
|
| 225 |
+
# Search query input
|
| 226 |
search_str = st.text_input("Enter search query:")
|
| 227 |
+
|
| 228 |
if search_str:
|
| 229 |
cached_data = fetch_github_json()
|
| 230 |
models = search_models(search_str, cached_data)
|
|
|
|
| 252 |
final_items.extend(split_biomodels(antimony_file_path))
|
| 253 |
|
| 254 |
if final_items:
|
| 255 |
+
st.session_state.db = create_vector_db(final_items)
|
| 256 |
st.write("Models have been processed and added to the database.")
|
| 257 |
else:
|
| 258 |
st.error("No items found in the models. Check if the Antimony files were generated correctly.")
|
| 259 |
|
|
|
|
|
|
|
| 260 |
# Avoid caching the database initialization, or ensure it's properly updated.
|
| 261 |
@st.cache_resource
|
| 262 |
def get_messages():
|
|
|
|
| 269 |
for message in st.session_state.messages:
|
| 270 |
with st.chat_message(message["role"]):
|
| 271 |
st.markdown(message["content"])
|
| 272 |
+
|
| 273 |
+
# Chat input section
|
| 274 |
if prompt := st.chat_input("Ask a question about the models:"):
|
| 275 |
st.chat_message("user").markdown(prompt)
|
| 276 |
st.session_state.messages.append({"role": "user", "content": prompt})
|
| 277 |
+
|
| 278 |
+
if st.session_state.db is None:
|
| 279 |
st.error("Database is not initialized. Please process the models first.")
|
| 280 |
else:
|
| 281 |
+
response = generate_response(st.session_state.db, prompt, st.session_state.messages)
|
| 282 |
|
| 283 |
with st.chat_message("assistant"):
|
| 284 |
st.markdown(response)
|