Nahiyan14 commited on
Commit
2cb5514
·
verified ·
1 Parent(s): 1aab1d1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -25
app.py CHANGED
@@ -10,7 +10,6 @@ from langchain.chains.combine_documents import create_stuff_documents_chain
10
  from langchain_core.prompts import ChatPromptTemplate
11
  from dotenv import load_dotenv
12
  from src.prompt import system_prompt
13
- import base64
14
 
15
  # Set up cache directories
16
  os.environ['TRANSFORMERS_CACHE'] = '/tmp/model_cache'
@@ -202,7 +201,8 @@ init_rate_limiting()
202
 
203
  # Sidebar content
204
  with st.sidebar:
205
- st.image("https://online.flipbuilder.com/clinical-library/vxes/files/shot.png", width=200)
 
206
  st.title("MedPrep AI")
207
 
208
  st.markdown("### About")
@@ -269,7 +269,7 @@ def initialize_rag_chain():
269
 
270
  retriever = docsearch.as_retriever(search_type="similarity", search_kwargs={"k": 3})
271
 
272
- llm = OpenAI(temperature=0.4, max_tokens=500)
273
 
274
  prompt = ChatPromptTemplate.from_messages([
275
  ("system", system_prompt),
@@ -351,37 +351,21 @@ with st.container():
351
  try:
352
  result = rag_chain.invoke({"input": prompt})
353
  response = result.get("answer", "Sorry, I couldn't find an answer to that in First Aid.")
354
- remaining = MAX_REQUESTS_PER_DAY - count
355
- response_with_footer = response
356
 
357
  # Display response without footer
358
  display_message(response)
359
 
360
- # Update sidebar with new remaining queries
361
- remaining_queries = get_remaining_queries(user_id)
362
- used_queries = MAX_REQUESTS_PER_DAY - remaining_queries
363
- percentage = (used_queries / MAX_REQUESTS_PER_DAY) * 100
364
-
365
- # Need to rerun to update the sidebar
366
- st.sidebar.markdown("### Daily Query Limit")
367
- st.sidebar.markdown(
368
- f"""
369
- <div class="progress-container">
370
- <div class="progress-bar" style="width: {percentage}%;"></div>
371
- </div>
372
- <p class="queries-text">{remaining_queries} of {MAX_REQUESTS_PER_DAY} queries remaining today</p>
373
- """,
374
- unsafe_allow_html=True
375
- )
376
-
377
  except Exception as e:
378
- response_with_footer = f"Error processing your request: {str(e)}"
379
- display_message(response_with_footer)
 
 
380
 
381
  # Add assistant response to chat history
382
  st.session_state.messages.append({"role": "assistant", "content": response})
383
 
384
- # Clear the input box
 
385
  st.experimental_rerun()
386
 
387
  # Footer
 
10
  from langchain_core.prompts import ChatPromptTemplate
11
  from dotenv import load_dotenv
12
  from src.prompt import system_prompt
 
13
 
14
  # Set up cache directories
15
  os.environ['TRANSFORMERS_CACHE'] = '/tmp/model_cache'
 
201
 
202
  # Sidebar content
203
  with st.sidebar:
204
+ # Using a more reliable image URL - or you can upload an image to your Space
205
+ st.image("https://img.freepik.com/free-vector/online-doctor-concept_23-2148522199.jpg", width=200)
206
  st.title("MedPrep AI")
207
 
208
  st.markdown("### About")
 
269
 
270
  retriever = docsearch.as_retriever(search_type="similarity", search_kwargs={"k": 3})
271
 
272
+ llm = OpenAI(model="gpt-3.5-turbo", temperature=0.4, max_tokens=500)
273
 
274
  prompt = ChatPromptTemplate.from_messages([
275
  ("system", system_prompt),
 
351
  try:
352
  result = rag_chain.invoke({"input": prompt})
353
  response = result.get("answer", "Sorry, I couldn't find an answer to that in First Aid.")
 
 
354
 
355
  # Display response without footer
356
  display_message(response)
357
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
358
  except Exception as e:
359
+ error_response = f"Error processing your request: {str(e)}"
360
+ display_message(error_response)
361
+ st.session_state.messages.append({"role": "assistant", "content": error_response})
362
+ st.experimental_rerun()
363
 
364
  # Add assistant response to chat history
365
  st.session_state.messages.append({"role": "assistant", "content": response})
366
 
367
+ # Clear the input box - using a different approach that's more reliable
368
+ st.session_state.user_input = ""
369
  st.experimental_rerun()
370
 
371
  # Footer