Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -94,7 +94,7 @@ def page1():
|
|
| 94 |
|
| 95 |
with col1:
|
| 96 |
st.title('Welcome to MediMetrics!')
|
| 97 |
-
st.subheader('powered by :
|
| 98 |
|
| 99 |
with col2:
|
| 100 |
# Load and display the image in the right column
|
|
@@ -113,43 +113,57 @@ def page1():
|
|
| 113 |
|
| 114 |
# Function to process the question
|
| 115 |
def process_question(question):
|
| 116 |
-
# Clear the previous run status
|
| 117 |
st.session_state.run = None
|
| 118 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 119 |
# Add message to the thread
|
| 120 |
client.beta.threads.messages.create(
|
| 121 |
thread_id=st.session_state.thread.id,
|
| 122 |
role="user",
|
| 123 |
content=question
|
| 124 |
)
|
| 125 |
-
|
| 126 |
# Create a new run to process the messages in the thread
|
| 127 |
st.session_state.run = client.beta.threads.runs.create(
|
| 128 |
thread_id=st.session_state.thread.id,
|
| 129 |
assistant_id=st.session_state.assistant.id,
|
| 130 |
)
|
| 131 |
-
|
| 132 |
-
# Wait for the run to complete
|
| 133 |
while not hasattr(st.session_state.run, 'status') or st.session_state.run.status not in ["completed", "failed"]:
|
| 134 |
time.sleep(1)
|
| 135 |
st.session_state.run = client.beta.threads.runs.retrieve(
|
| 136 |
thread_id=st.session_state.thread.id,
|
| 137 |
run_id=st.session_state.run.id,
|
| 138 |
)
|
| 139 |
-
|
| 140 |
if st.session_state.run.status == "completed":
|
| 141 |
# Retrieve the list of messages
|
| 142 |
st.session_state.messages = client.beta.threads.messages.list(
|
| 143 |
thread_id=st.session_state.thread.id
|
| 144 |
)
|
| 145 |
-
|
| 146 |
-
#
|
| 147 |
last_assistant_message = next((message for message in reversed(st.session_state.messages.data) if message.role == "assistant"), None)
|
| 148 |
if last_assistant_message:
|
| 149 |
-
#
|
| 150 |
st.session_state.chat_history.append(("Assistant", last_assistant_message.content[0].text.value))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 151 |
|
| 152 |
|
|
|
|
| 153 |
# Example query buttons
|
| 154 |
col3, col4 = st.columns(2) # Create two columns for buttons
|
| 155 |
|
|
|
|
| 94 |
|
| 95 |
with col1:
|
| 96 |
st.title('Welcome to MediMetrics!')
|
| 97 |
+
st.subheader('powered by :orange_heart:[BinDoc GmbH] ')
|
| 98 |
|
| 99 |
with col2:
|
| 100 |
# Load and display the image in the right column
|
|
|
|
| 113 |
|
| 114 |
# Function to process the question
|
| 115 |
def process_question(question):
|
| 116 |
+
# Clear the previous run status and messages
|
| 117 |
st.session_state.run = None
|
| 118 |
+
st.session_state.messages = []
|
| 119 |
+
|
| 120 |
+
# Start with the current user question in chat history
|
| 121 |
+
st.session_state.chat_history = [("User", question)]
|
| 122 |
+
|
| 123 |
# Add message to the thread
|
| 124 |
client.beta.threads.messages.create(
|
| 125 |
thread_id=st.session_state.thread.id,
|
| 126 |
role="user",
|
| 127 |
content=question
|
| 128 |
)
|
| 129 |
+
|
| 130 |
# Create a new run to process the messages in the thread
|
| 131 |
st.session_state.run = client.beta.threads.runs.create(
|
| 132 |
thread_id=st.session_state.thread.id,
|
| 133 |
assistant_id=st.session_state.assistant.id,
|
| 134 |
)
|
| 135 |
+
|
| 136 |
+
# Wait for the run to complete
|
| 137 |
while not hasattr(st.session_state.run, 'status') or st.session_state.run.status not in ["completed", "failed"]:
|
| 138 |
time.sleep(1)
|
| 139 |
st.session_state.run = client.beta.threads.runs.retrieve(
|
| 140 |
thread_id=st.session_state.thread.id,
|
| 141 |
run_id=st.session_state.run.id,
|
| 142 |
)
|
| 143 |
+
|
| 144 |
if st.session_state.run.status == "completed":
|
| 145 |
# Retrieve the list of messages
|
| 146 |
st.session_state.messages = client.beta.threads.messages.list(
|
| 147 |
thread_id=st.session_state.thread.id
|
| 148 |
)
|
| 149 |
+
|
| 150 |
+
# Find the last assistant message
|
| 151 |
last_assistant_message = next((message for message in reversed(st.session_state.messages.data) if message.role == "assistant"), None)
|
| 152 |
if last_assistant_message:
|
| 153 |
+
# Update chat history with the assistant's response
|
| 154 |
st.session_state.chat_history.append(("Assistant", last_assistant_message.content[0].text.value))
|
| 155 |
+
|
| 156 |
+
# Display the updated chat history
|
| 157 |
+
for role, message in st.session_state.chat_history:
|
| 158 |
+
if role == "User":
|
| 159 |
+
with st.chat_message("User"):
|
| 160 |
+
st.markdown(message)
|
| 161 |
+
elif role == "Assistant":
|
| 162 |
+
with st.chat_message("Assistant"):
|
| 163 |
+
st.markdown(message)
|
| 164 |
|
| 165 |
|
| 166 |
+
|
| 167 |
# Example query buttons
|
| 168 |
col3, col4 = st.columns(2) # Create two columns for buttons
|
| 169 |
|