Ashar086 commited on
Commit
f4f73fd
·
verified ·
1 Parent(s): 1d81696

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -48
app.py CHANGED
@@ -1,7 +1,6 @@
1
  import streamlit as st
2
  import plotly.graph_objects as go
3
  import random
4
- import time
5
 
6
  # Initialize session state
7
  if 'initialized' not in st.session_state:
@@ -88,60 +87,50 @@ if st.button("Run Animations"):
88
  st.session_state.initialized = True
89
 
90
  if st.session_state.initialized:
 
 
 
91
  # Animation 1: Patient Conditions
92
- placeholder1 = st.empty()
93
- st.subheader("Patients by Condition")
94
- for condition, count in st.session_state.condition_counts.items():
95
- fig = create_gauge(f"Patients with {condition}", count, 200, {'x': [0, 1], 'y': [0, 1]}, 'blue')
96
- placeholder1.plotly_chart(fig, use_container_width=True)
97
- time.sleep(3) # Wait for 3 seconds before showing the next frame
98
- placeholder1.empty() # Clear the previous frame
99
- time.sleep(3) # Additional pause before moving to the next animation
100
 
101
  # Animation 2: Treatment Metrics
102
- placeholder2 = st.empty()
103
- st.subheader("Treatment Metrics")
104
- fig1 = create_gauge("Total Patients", 200, 200, {'x': [0, 0.5], 'y': [0, 1]}, 'green')
105
- fig2 = create_gauge("Successful Treatments", st.session_state.successful_treatments, st.session_state.total_treatments, {'x': [0.5, 1], 'y': [0, 0.5]}, 'orange')
106
- fig3 = create_gauge("Unsuccessful Treatments", st.session_state.unsuccessful_treatments, st.session_state.total_treatments, {'x': [0.5, 1], 'y': [0.5, 1]}, 'red')
107
- placeholder2.plotly_chart(fig1, use_container_width=True)
108
- time.sleep(3) # Wait for 3 seconds before showing the next frame
109
- placeholder2.empty() # Clear the previous frame
110
- placeholder2.plotly_chart(fig2, use_container_width=True)
111
- time.sleep(3) # Wait for 3 seconds before showing the next frame
112
- placeholder2.empty() # Clear the previous frame
113
- placeholder2.plotly_chart(fig3, use_container_width=True)
114
- time.sleep(3) # Additional pause before moving to the next animation
115
 
116
  # Animation 3: Doctor Actions
117
- placeholder3 = st.empty()
118
- st.subheader("Doctor Actions")
119
- for action, count in st.session_state.doctor_actions.items():
120
- fig = create_gauge(f"Doctor Action: {action}", count, st.session_state.total_treatments, {'x': [0, 1], 'y': [0, 1]}, 'purple')
121
- placeholder3.plotly_chart(fig, use_container_width=True)
122
- time.sleep(3) # Wait for 3 seconds before showing the next frame
123
- placeholder3.empty() # Clear the previous frame
124
- time.sleep(3) # Additional pause before moving to the next animation
125
 
126
  # Animation 4: Penalties
127
- placeholder4 = st.empty()
128
- st.subheader("Penalties")
129
- for penalty, count in st.session_state.penalties.items():
130
- fig = create_gauge(f"Penalty: {penalty}", count, st.session_state.total_treatments // 6, {'x': [0, 1], 'y': [0, 1]}, 'red')
131
- placeholder4.plotly_chart(fig, use_container_width=True)
132
- time.sleep(3) # Wait for 3 seconds before showing the next frame
133
- placeholder4.empty() # Clear the previous frame
134
- time.sleep(3) # Additional pause before moving to the next animation
135
 
136
  # Animation 5: Patient Feedback
137
- placeholder5 = st.empty()
138
- st.subheader("Patient Feedback")
139
- for fb, count in st.session_state.feedback.items():
140
- fig = create_gauge(f"Feedback: {fb}", count, st.session_state.total_treatments, {'x': [0, 1], 'y': [0, 1]}, 'blue')
141
- placeholder5.plotly_chart(fig, use_container_width=True)
142
- time.sleep(3) # Wait for 3 seconds before showing the next frame
143
- placeholder5.empty() # Clear the previous frame
144
- st.write("**End of Animations.**")
145
 
146
- # Reset session state to allow re-running the animations if needed
147
- st.session_state.initialized = False
 
1
  import streamlit as st
2
  import plotly.graph_objects as go
3
  import random
 
4
 
5
  # Initialize session state
6
  if 'initialized' not in st.session_state:
 
87
  st.session_state.initialized = True
88
 
89
  if st.session_state.initialized:
90
+ # Slider to choose the animation
91
+ animation_index = st.slider("Select Animation", min_value=1, max_value=5, value=1)
92
+
93
  # Animation 1: Patient Conditions
94
+ if animation_index == 1:
95
+ st.subheader("Patients by Condition")
96
+ for condition, count in st.session_state.condition_counts.items():
97
+ fig = create_gauge(f"Patients with {condition}", count, 200, {'x': [0, 1], 'y': [0, 1]}, 'blue')
98
+ st.plotly_chart(fig, use_container_width=True)
99
+ st.markdown("---")
 
 
100
 
101
  # Animation 2: Treatment Metrics
102
+ elif animation_index == 2:
103
+ st.subheader("Treatment Metrics")
104
+ fig1 = create_gauge("Total Patients", 200, 200, {'x': [0, 0.5], 'y': [0, 1]}, 'green')
105
+ fig2 = create_gauge("Successful Treatments", st.session_state.successful_treatments, st.session_state.total_treatments, {'x': [0.5, 1], 'y': [0, 0.5]}, 'orange')
106
+ fig3 = create_gauge("Unsuccessful Treatments", st.session_state.unsuccessful_treatments, st.session_state.total_treatments, {'x': [0.5, 1], 'y': [0.5, 1]}, 'red')
107
+ st.plotly_chart(fig1, use_container_width=True)
108
+ st.plotly_chart(fig2, use_container_width=True)
109
+ st.plotly_chart(fig3, use_container_width=True)
110
+ st.markdown("---")
 
 
 
 
111
 
112
  # Animation 3: Doctor Actions
113
+ elif animation_index == 3:
114
+ st.subheader("Doctor Actions")
115
+ for action, count in st.session_state.doctor_actions.items():
116
+ fig = create_gauge(f"Doctor Action: {action}", count, st.session_state.total_treatments, {'x': [0, 1], 'y': [0, 1]}, 'purple')
117
+ st.plotly_chart(fig, use_container_width=True)
118
+ st.markdown("---")
 
 
119
 
120
  # Animation 4: Penalties
121
+ elif animation_index == 4:
122
+ st.subheader("Penalties")
123
+ for penalty, count in st.session_state.penalties.items():
124
+ fig = create_gauge(f"Penalty: {penalty}", count, st.session_state.total_treatments // 6, {'x': [0, 1], 'y': [0, 1]}, 'red')
125
+ st.plotly_chart(fig, use_container_width=True)
126
+ st.markdown("---")
 
 
127
 
128
  # Animation 5: Patient Feedback
129
+ elif animation_index == 5:
130
+ st.subheader("Patient Feedback")
131
+ for fb, count in st.session_state.feedback.items():
132
+ fig = create_gauge(f"Feedback: {fb}", count, st.session_state.total_treatments, {'x': [0, 1], 'y': [0, 1]}, 'blue')
133
+ st.plotly_chart(fig, use_container_width=True)
134
+ st.markdown("---")
 
 
135
 
136
+ st.write("**End of Animations.**")