Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,52 +1,103 @@
|
|
|
|
|
| 1 |
import plotly.graph_objects as go
|
|
|
|
|
|
|
| 2 |
|
| 3 |
-
|
| 4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
fig = go.Figure()
|
| 6 |
|
| 7 |
-
#
|
| 8 |
-
fig.add_trace(go.Bar(
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
name=f'Frame {i}')
|
| 22 |
-
for i, (s, f) in enumerate(zip(successful_treatments.values(), failed_treatments.values()))]
|
| 23 |
-
|
| 24 |
-
# Set the layout for the plot
|
| 25 |
fig.update_layout(
|
| 26 |
-
title=
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
)
|
| 42 |
-
|
| 43 |
-
# Add frames to the figure for the animation
|
| 44 |
-
fig.frames = frames
|
| 45 |
|
| 46 |
return fig
|
| 47 |
|
| 48 |
-
#
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
import plotly.graph_objects as go
|
| 3 |
+
import time
|
| 4 |
+
import random
|
| 5 |
|
| 6 |
+
# Define the data
|
| 7 |
+
agents = {
|
| 8 |
+
"Doctors": 5,
|
| 9 |
+
"Nurses": 10,
|
| 10 |
+
"Clinicians": 8,
|
| 11 |
+
"Patients": 200
|
| 12 |
+
}
|
| 13 |
+
|
| 14 |
+
patient_conditions = ["Healthy", "Mild Illness", "Chronic Illness", "Emergency"]
|
| 15 |
+
doctor_emotions = ["Calm", "Stressed", "Overwhelmed"]
|
| 16 |
+
nurse_emotions = ["Focused", "Fatigued", "Panicked"]
|
| 17 |
+
doctor_actions = ["Prescribe Medication", "Recommend Tests", "Consult Clinician", "Schedule Surgery"]
|
| 18 |
+
nurse_actions = ["Monitor Vitals", "Administer Medication", "Report to Doctor", "Assist Surgery"]
|
| 19 |
+
|
| 20 |
+
# Initial values for successful and unsuccessful treatments
|
| 21 |
+
doctor_successful_treatments = random.randint(0, 10)
|
| 22 |
+
doctor_unsuccessful_treatments = random.randint(0, 10)
|
| 23 |
+
|
| 24 |
+
# Streamlit setup
|
| 25 |
+
st.title("Interactive Healthcare Animation")
|
| 26 |
+
|
| 27 |
+
# Function to create interactive graph
|
| 28 |
+
def create_health_graph(agents, patient_condition, doctor_emotion, nurse_emotion, doctor_action, nurse_action, success, failure):
|
| 29 |
fig = go.Figure()
|
| 30 |
|
| 31 |
+
# Agents count graph
|
| 32 |
+
fig.add_trace(go.Bar(
|
| 33 |
+
x=list(agents.keys()),
|
| 34 |
+
y=list(agents.values()),
|
| 35 |
+
name='Agents Count'
|
| 36 |
+
))
|
| 37 |
+
|
| 38 |
+
# Patient condition as a pie chart
|
| 39 |
+
fig.add_trace(go.Pie(
|
| 40 |
+
labels=['Healthy', 'Mild Illness', 'Chronic Illness', 'Emergency'],
|
| 41 |
+
values=[agents['Patients'] * 0.5, agents['Patients'] * 0.2, agents['Patients'] * 0.2, agents['Patients'] * 0.1],
|
| 42 |
+
title='Patient Conditions'
|
| 43 |
+
))
|
| 44 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
fig.update_layout(
|
| 46 |
+
title='Healthcare Agents Status',
|
| 47 |
+
template='plotly_dark',
|
| 48 |
+
barmode='group'
|
| 49 |
+
)
|
| 50 |
+
|
| 51 |
+
# Display emotions and actions as text
|
| 52 |
+
fig.add_annotation(
|
| 53 |
+
text=f"Doctor Emotion: {doctor_emotion}\nNurse Emotion: {nurse_emotion}\nDoctor Action: {doctor_action}\nNurse Action: {nurse_action}",
|
| 54 |
+
xref='paper', yref='paper',
|
| 55 |
+
x=0.5, y=-0.2,
|
| 56 |
+
showarrow=False,
|
| 57 |
+
font=dict(size=14)
|
| 58 |
+
)
|
| 59 |
+
|
| 60 |
+
# Display successful and unsuccessful treatments
|
| 61 |
+
fig.add_annotation(
|
| 62 |
+
text=f"Successful Treatments: {success}\nUnsuccessful Treatments: {failure}",
|
| 63 |
+
xref='paper', yref='paper',
|
| 64 |
+
x=0.5, y=-0.35,
|
| 65 |
+
showarrow=False,
|
| 66 |
+
font=dict(size=14)
|
| 67 |
)
|
|
|
|
|
|
|
|
|
|
| 68 |
|
| 69 |
return fig
|
| 70 |
|
| 71 |
+
# Button to start the animation
|
| 72 |
+
start_button = st.button("Start Animation")
|
| 73 |
+
|
| 74 |
+
# Check if the start button is pressed
|
| 75 |
+
if start_button:
|
| 76 |
+
# Placeholder for dynamic updates
|
| 77 |
+
placeholder = st.empty()
|
| 78 |
+
|
| 79 |
+
# Loop through each frame
|
| 80 |
+
for i in range(20): # 20 frames for the animation
|
| 81 |
+
with placeholder.container():
|
| 82 |
+
# Randomly select conditions, emotions, and actions
|
| 83 |
+
patient_condition = random.choice(patient_conditions)
|
| 84 |
+
doctor_emotion = random.choice(doctor_emotions)
|
| 85 |
+
nurse_emotion = random.choice(nurse_emotions)
|
| 86 |
+
doctor_action = random.choice(doctor_actions)
|
| 87 |
+
nurse_action = random.choice(nurse_actions)
|
| 88 |
+
|
| 89 |
+
# Randomly adjust successful and unsuccessful treatments
|
| 90 |
+
if random.choice([True, False]):
|
| 91 |
+
doctor_successful_treatments += 1
|
| 92 |
+
else:
|
| 93 |
+
doctor_unsuccessful_treatments += 1
|
| 94 |
+
|
| 95 |
+
# Create and display the graph
|
| 96 |
+
fig = create_health_graph(agents, patient_condition, doctor_emotion, nurse_emotion, doctor_action, nurse_action, doctor_successful_treatments, doctor_unsuccessful_treatments)
|
| 97 |
+
st.plotly_chart(fig, use_container_width=True)
|
| 98 |
+
|
| 99 |
+
# Pause for 2 seconds before moving to the next frame
|
| 100 |
+
time.sleep(2)
|
| 101 |
+
|
| 102 |
+
# Display a final summary
|
| 103 |
+
st.write("**Animation Complete: Healthcare agents' statuses have been updated.**")
|