Update app.py
Browse files
app.py
CHANGED
|
@@ -201,7 +201,7 @@ def create_vector_db(final_items):
|
|
| 201 |
def generate_response(db, query_text, previous_context):
|
| 202 |
query_results = db.query(
|
| 203 |
query_texts=query_text,
|
| 204 |
-
n_results=
|
| 205 |
)
|
| 206 |
|
| 207 |
if not query_results.get('documents'):
|
|
@@ -263,8 +263,7 @@ def streamlit_app():
|
|
| 263 |
st.title("BioModelsRAG")
|
| 264 |
|
| 265 |
search_str = st.text_input("Enter search query:")
|
| 266 |
-
|
| 267 |
-
# Keep the search input field visible even after submission
|
| 268 |
if search_str:
|
| 269 |
models = search_models(search_str)
|
| 270 |
|
|
@@ -277,7 +276,7 @@ def streamlit_app():
|
|
| 277 |
)
|
| 278 |
|
| 279 |
if st.button("Analyze Selected Models"):
|
| 280 |
-
|
| 281 |
for model_id in selected_models:
|
| 282 |
model_data = models[model_id]
|
| 283 |
|
|
@@ -289,35 +288,39 @@ def streamlit_app():
|
|
| 289 |
|
| 290 |
convert_sbml_to_antimony(model_file_path, antimony_file_path)
|
| 291 |
|
| 292 |
-
|
| 293 |
if not final_items:
|
| 294 |
st.write("No content found in the biomodel.")
|
| 295 |
continue
|
| 296 |
|
| 297 |
-
|
| 298 |
|
| 299 |
-
|
| 300 |
-
db = create_vector_db(all_final_items)
|
| 301 |
|
| 302 |
if db:
|
| 303 |
st.write("Models have been processed and added to the database.")
|
| 304 |
|
| 305 |
-
# Check if the database is created before showing the query input
|
| 306 |
if db:
|
| 307 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 308 |
|
| 309 |
-
|
| 310 |
-
|
| 311 |
-
st.
|
| 312 |
-
|
| 313 |
-
# Placeholder for indicating that response generation has started
|
| 314 |
-
response_placeholder = st.empty()
|
| 315 |
-
response_placeholder.write("Response generation is beginning...")
|
| 316 |
|
| 317 |
-
|
| 318 |
-
|
| 319 |
-
st.
|
| 320 |
-
|
| 321 |
-
|
| 322 |
-
|
| 323 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 201 |
def generate_response(db, query_text, previous_context):
|
| 202 |
query_results = db.query(
|
| 203 |
query_texts=query_text,
|
| 204 |
+
n_results=7,
|
| 205 |
)
|
| 206 |
|
| 207 |
if not query_results.get('documents'):
|
|
|
|
| 263 |
st.title("BioModelsRAG")
|
| 264 |
|
| 265 |
search_str = st.text_input("Enter search query:")
|
| 266 |
+
|
|
|
|
| 267 |
if search_str:
|
| 268 |
models = search_models(search_str)
|
| 269 |
|
|
|
|
| 276 |
)
|
| 277 |
|
| 278 |
if st.button("Analyze Selected Models"):
|
| 279 |
+
final_items = []
|
| 280 |
for model_id in selected_models:
|
| 281 |
model_data = models[model_id]
|
| 282 |
|
|
|
|
| 288 |
|
| 289 |
convert_sbml_to_antimony(model_file_path, antimony_file_path)
|
| 290 |
|
| 291 |
+
items = split_biomodels(antimony_file_path)
|
| 292 |
if not final_items:
|
| 293 |
st.write("No content found in the biomodel.")
|
| 294 |
continue
|
| 295 |
|
| 296 |
+
final_items.extend(items)
|
| 297 |
|
| 298 |
+
db = create_vector_db(final_items)
|
|
|
|
| 299 |
|
| 300 |
if db:
|
| 301 |
st.write("Models have been processed and added to the database.")
|
| 302 |
|
|
|
|
| 303 |
if db:
|
| 304 |
+
@st.cache_resource
|
| 305 |
+
def get_messages():
|
| 306 |
+
if "messages" not in st.session_state:
|
| 307 |
+
st.session_state.messages = []
|
| 308 |
+
return st.session_state.messages
|
| 309 |
+
st.session_state.messages = get_messages()
|
| 310 |
|
| 311 |
+
for message in st.session_state.messages:
|
| 312 |
+
with st.chat_message(message["role"]):
|
| 313 |
+
st.markdown(message["content"])
|
|
|
|
|
|
|
|
|
|
|
|
|
| 314 |
|
| 315 |
+
if prompt := st.chat_input(query_text):
|
| 316 |
+
st.chat_message("user").markdown(prompt)
|
| 317 |
+
st.session_state.messages.append({"role": "user", "content":prompt})
|
| 318 |
+
response = generate_response(db, query_text, st.session_state)
|
| 319 |
+
|
| 320 |
+
with st.chat_message("assistant"):
|
| 321 |
+
st.markdown(response)
|
| 322 |
+
|
| 323 |
+
st.session_state.messages.append({"role":"assistant","content":response})
|
| 324 |
+
|
| 325 |
+
if __name__ == "__main__":
|
| 326 |
+
streamlit_app()
|