Ashar086 commited on
Commit
51fc905
·
verified ·
1 Parent(s): 569a8bc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +94 -43
app.py CHANGED
@@ -1,52 +1,103 @@
 
1
  import plotly.graph_objects as go
 
 
2
 
3
- def create_animation(successful_treatments, failed_treatments):
4
- # Create initial figure
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  fig = go.Figure()
6
 
7
- # Add bar traces
8
- fig.add_trace(go.Bar(x=['Doctor', 'Nurse'],
9
- y=[successful_treatments['Doctor'], successful_treatments['Nurse']],
10
- name='Successful Treatments',
11
- marker_color='green'))
12
-
13
- fig.add_trace(go.Bar(x=['Doctor', 'Nurse'],
14
- y=[failed_treatments['Doctor'], failed_treatments['Nurse']],
15
- name='Failed Treatments',
16
- marker_color='red'))
17
-
18
- # Add animation frames (if needed for more dynamic changes over time)
19
- frames = [go.Frame(data=[go.Bar(x=['Doctor', 'Nurse'],
20
- y=[s, f])],
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="Doctor and Nurse Performance Metrics",
27
- barmode='group',
28
- xaxis_title="Personnel",
29
- yaxis_title="Number of Treatments",
30
- updatemenus=[{
31
- 'buttons': [
32
- {'args': [None, {'frame': {'duration': 500, 'redraw': True}, 'fromcurrent': True}],
33
- 'label': 'Play',
34
- 'method': 'animate'},
35
- {'args': [[None], {'frame': {'duration': 0, 'redraw': True}, 'mode': 'immediate'}],
36
- 'label': 'Pause',
37
- 'method': 'animate'}
38
- ],
39
- 'type': 'buttons'
40
- }]
 
 
 
 
 
 
41
  )
42
-
43
- # Add frames to the figure for the animation
44
- fig.frames = frames
45
 
46
  return fig
47
 
48
- # Example call
49
- successful_treatments = {'Doctor': [10, 20, 30], 'Nurse': [5, 15, 25]}
50
- failed_treatments = {'Doctor': [2, 5, 10], 'Nurse': [1, 3, 6]}
51
- fig = create_animation(successful_treatments, failed_treatments)
52
- fig.show()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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.**")