Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -94,23 +94,6 @@ st.set_page_config(
|
|
| 94 |
layout="centered"
|
| 95 |
)
|
| 96 |
|
| 97 |
-
# Custom CSS to style images and improve layout
|
| 98 |
-
st.markdown("""
|
| 99 |
-
<style>
|
| 100 |
-
.header-container {
|
| 101 |
-
display: flex;
|
| 102 |
-
align-items: center;
|
| 103 |
-
gap: 20px;
|
| 104 |
-
}
|
| 105 |
-
.header-image {
|
| 106 |
-
width: 80px;
|
| 107 |
-
}
|
| 108 |
-
.sidebar-image {
|
| 109 |
-
margin-bottom: 20px;
|
| 110 |
-
}
|
| 111 |
-
</style>
|
| 112 |
-
""", unsafe_allow_html=True)
|
| 113 |
-
|
| 114 |
# Initialize session state for chat history
|
| 115 |
if 'messages' not in st.session_state:
|
| 116 |
st.session_state.messages = []
|
|
@@ -118,25 +101,10 @@ if 'messages' not in st.session_state:
|
|
| 118 |
# Initialize rate limiting
|
| 119 |
init_rate_limiting()
|
| 120 |
|
| 121 |
-
#
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
st.write("This AI assistant is powered by First Aid USMLE Step 1 content and helps medical students prepare for their exams.")
|
| 126 |
-
|
| 127 |
-
# Display remaining queries
|
| 128 |
-
user_id = get_user_id()
|
| 129 |
-
remaining_queries = get_remaining_queries(user_id)
|
| 130 |
-
st.write(f"Remaining queries today: {remaining_queries}/{MAX_REQUESTS_PER_DAY}")
|
| 131 |
-
|
| 132 |
-
st.markdown("---")
|
| 133 |
-
st.markdown("### Tips for Better Results")
|
| 134 |
-
st.markdown("""
|
| 135 |
-
- Be specific with your questions
|
| 136 |
-
- Include relevant keywords
|
| 137 |
-
- Ask one concept at a time
|
| 138 |
-
- Mention the system or topic area
|
| 139 |
-
""")
|
| 140 |
|
| 141 |
# Check for API keys
|
| 142 |
PINECONE_API_KEY = os.environ.get('PINECONE_API_KEY')
|
|
@@ -166,7 +134,7 @@ def initialize_rag_chain():
|
|
| 166 |
retriever = docsearch.as_retriever(search_type="similarity", search_kwargs={"k": 3})
|
| 167 |
|
| 168 |
st.sidebar.write("Initializing OpenAI...")
|
| 169 |
-
llm = OpenAI(
|
| 170 |
|
| 171 |
prompt = ChatPromptTemplate.from_messages([
|
| 172 |
("system", system_prompt),
|
|
@@ -184,14 +152,8 @@ def initialize_rag_chain():
|
|
| 184 |
st.sidebar.text(traceback.format_exc())
|
| 185 |
return None
|
| 186 |
|
| 187 |
-
# Main app
|
| 188 |
-
st.
|
| 189 |
-
<div class="header-container">
|
| 190 |
-
<img src="https://med.stanford.edu/content/dam/sm-news/images/2014/09/first-aid-logo.gif" class="header-image">
|
| 191 |
-
<h1>First AID USMLE Step 1</h1>
|
| 192 |
-
</div>
|
| 193 |
-
""", unsafe_allow_html=True)
|
| 194 |
-
|
| 195 |
st.write("Ask me any question from First AID USMLE Step 1 book, and I'll try to help!")
|
| 196 |
|
| 197 |
# Initialize the RAG chain
|
|
@@ -240,14 +202,5 @@ if prompt := st.chat_input("Ask a question..."):
|
|
| 240 |
|
| 241 |
# Footer
|
| 242 |
st.markdown("---")
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
with cols[1]:
|
| 246 |
-
st.image("https://i.pinimg.com/originals/ec/81/1c/ec811c4588d10f8286aad7e3ed33e478.png", width=80)
|
| 247 |
-
|
| 248 |
-
st.markdown("""
|
| 249 |
-
<div style="text-align: center; margin-top: 10px;">
|
| 250 |
-
<p style="font-size: 0.8rem;">This AI assistant uses retrieval augmented generation to provide information from First Aid USMLE Step 1 content.
|
| 251 |
-
It's designed to help with studying, but should not replace professional medical advice.</p>
|
| 252 |
-
</div>
|
| 253 |
-
""", unsafe_allow_html=True)
|
|
|
|
| 94 |
layout="centered"
|
| 95 |
)
|
| 96 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 97 |
# Initialize session state for chat history
|
| 98 |
if 'messages' not in st.session_state:
|
| 99 |
st.session_state.messages = []
|
|
|
|
| 101 |
# Initialize rate limiting
|
| 102 |
init_rate_limiting()
|
| 103 |
|
| 104 |
+
# Display remaining queries
|
| 105 |
+
user_id = get_user_id()
|
| 106 |
+
remaining_queries = get_remaining_queries(user_id)
|
| 107 |
+
st.sidebar.write(f"Remaining queries today: {remaining_queries}/{MAX_REQUESTS_PER_DAY}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 108 |
|
| 109 |
# Check for API keys
|
| 110 |
PINECONE_API_KEY = os.environ.get('PINECONE_API_KEY')
|
|
|
|
| 134 |
retriever = docsearch.as_retriever(search_type="similarity", search_kwargs={"k": 3})
|
| 135 |
|
| 136 |
st.sidebar.write("Initializing OpenAI...")
|
| 137 |
+
llm = OpenAI(temperature=0.4, max_tokens=500)
|
| 138 |
|
| 139 |
prompt = ChatPromptTemplate.from_messages([
|
| 140 |
("system", system_prompt),
|
|
|
|
| 152 |
st.sidebar.text(traceback.format_exc())
|
| 153 |
return None
|
| 154 |
|
| 155 |
+
# Main app title
|
| 156 |
+
st.title("First AID USMLE Step 1")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 157 |
st.write("Ask me any question from First AID USMLE Step 1 book, and I'll try to help!")
|
| 158 |
|
| 159 |
# Initialize the RAG chain
|
|
|
|
| 202 |
|
| 203 |
# Footer
|
| 204 |
st.markdown("---")
|
| 205 |
+
st.markdown("*This AI assistant uses retrieval augmented generation to provide information from First Aid USMLE Step 1 content.
|
| 206 |
+
It's designed to help with studying, but should not replace professional medical advice..*")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|