Spaces:
Sleeping
Sleeping
Commit
·
a472d44
1
Parent(s):
529fcdf
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,6 +3,7 @@ import time
|
|
| 3 |
from langchain.schema import HumanMessage, SystemMessage, AIMessage
|
| 4 |
from langchain.chat_models import ChatOpenAI
|
| 5 |
|
|
|
|
| 6 |
def get_chatmodel_response(question):
|
| 7 |
# Retry logic
|
| 8 |
max_retries = 3
|
|
@@ -30,6 +31,8 @@ def get_chatmodel_response(question):
|
|
| 30 |
# Streamlit app setup
|
| 31 |
st.set_page_config(page_title="Doctor AI", page_icon="💊", layout="centered", initial_sidebar_state="collapsed")
|
| 32 |
|
|
|
|
|
|
|
| 33 |
st.header("Hello, I am Doctor AI. How can I help you?")
|
| 34 |
|
| 35 |
from dotenv import load_dotenv
|
|
@@ -37,7 +40,7 @@ load_dotenv()
|
|
| 37 |
import os
|
| 38 |
|
| 39 |
# ChatOpenAI class
|
| 40 |
-
chat = ChatOpenAI(temperature=0.
|
| 41 |
|
| 42 |
if 'flowmessages' not in st.session_state:
|
| 43 |
st.session_state['flowmessages'] = [
|
|
@@ -74,18 +77,18 @@ if 'flowmessages' not in st.session_state:
|
|
| 74 |
5 - The user should be able to understand it easily.
|
| 75 |
|
| 76 |
6 - Prescribe Medications:
|
| 77 |
-
|
| 78 |
-
|
| 79 |
7 - In the end, Express Empathy and Care, and you should also ask the user to consult a real doctor.
|
| 80 |
|
| 81 |
8 - If the user input is different from a body or health issue or any other medical issues,\
|
| 82 |
gently guide the user to provide appropriate health-related input,\
|
| 83 |
because you are a Doctor AI.
|
| 84 |
""")
|
|
|
|
| 85 |
]
|
| 86 |
|
| 87 |
# Streamlit UI
|
| 88 |
-
with st.form(key='my_form',
|
| 89 |
st.markdown(
|
| 90 |
"""
|
| 91 |
<style>
|
|
@@ -109,11 +112,23 @@ with st.form(key='my_form', clear_on_submit=True):
|
|
| 109 |
|
| 110 |
submit = st.form_submit_button("Submit")
|
| 111 |
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 115 |
st.header(":blue[You]", divider=True)
|
| 116 |
-
|
|
|
|
| 117 |
st.header("Doctor AI", divider=True)
|
| 118 |
-
|
| 119 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
from langchain.schema import HumanMessage, SystemMessage, AIMessage
|
| 4 |
from langchain.chat_models import ChatOpenAI
|
| 5 |
|
| 6 |
+
|
| 7 |
def get_chatmodel_response(question):
|
| 8 |
# Retry logic
|
| 9 |
max_retries = 3
|
|
|
|
| 31 |
# Streamlit app setup
|
| 32 |
st.set_page_config(page_title="Doctor AI", page_icon="💊", layout="centered", initial_sidebar_state="collapsed")
|
| 33 |
|
| 34 |
+
|
| 35 |
+
|
| 36 |
st.header("Hello, I am Doctor AI. How can I help you?")
|
| 37 |
|
| 38 |
from dotenv import load_dotenv
|
|
|
|
| 40 |
import os
|
| 41 |
|
| 42 |
# ChatOpenAI class
|
| 43 |
+
chat = ChatOpenAI(temperature=0.1)
|
| 44 |
|
| 45 |
if 'flowmessages' not in st.session_state:
|
| 46 |
st.session_state['flowmessages'] = [
|
|
|
|
| 77 |
5 - The user should be able to understand it easily.
|
| 78 |
|
| 79 |
6 - Prescribe Medications:
|
| 80 |
+
- Write the correct Medicine name below again, and Highlight the medicine name.
|
|
|
|
| 81 |
7 - In the end, Express Empathy and Care, and you should also ask the user to consult a real doctor.
|
| 82 |
|
| 83 |
8 - If the user input is different from a body or health issue or any other medical issues,\
|
| 84 |
gently guide the user to provide appropriate health-related input,\
|
| 85 |
because you are a Doctor AI.
|
| 86 |
""")
|
| 87 |
+
|
| 88 |
]
|
| 89 |
|
| 90 |
# Streamlit UI
|
| 91 |
+
with st.form(key='my_form',clear_on_submit=True):
|
| 92 |
st.markdown(
|
| 93 |
"""
|
| 94 |
<style>
|
|
|
|
| 112 |
|
| 113 |
submit = st.form_submit_button("Submit")
|
| 114 |
|
| 115 |
+
|
| 116 |
+
|
| 117 |
+
|
| 118 |
+
# If the "Submit" button is clicked
|
| 119 |
+
if submit:
|
| 120 |
+
|
| 121 |
+
|
| 122 |
+
# Display loading message while processing
|
| 123 |
+
with st.spinner("Analyzing..."):
|
| 124 |
st.header(":blue[You]", divider=True)
|
| 125 |
+
st.caption(input_question)
|
| 126 |
+
|
| 127 |
st.header("Doctor AI", divider=True)
|
| 128 |
+
response = get_chatmodel_response(input_question)
|
| 129 |
+
|
| 130 |
+
if response is not None:
|
| 131 |
+
|
| 132 |
+
st.write(response)
|
| 133 |
+
else:
|
| 134 |
+
st.subheader("Error: Unable to get response. Please try again later.")
|