Ashar086 commited on
Commit
1eb4de2
·
verified ·
1 Parent(s): 12f6869

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +64 -4
app.py CHANGED
@@ -13,6 +13,10 @@ agents = {
13
  # Define states for patients (health conditions)
14
  patient_conditions = ["Healthy", "Mild Illness", "Chronic Illness", "Emergency"]
15
 
 
 
 
 
16
  # Define the actions doctors can take
17
  doctor_actions = ["Prescribe Medication", "Recommend Tests", "Consult Clinician", "Schedule Surgery"]
18
 
@@ -37,9 +41,19 @@ rewards = {
37
  penalties = {
38
  "Wrong Medication": -10,
39
  "Missed Diagnosis": -20,
40
- "Incorrect Test Recommendation": -5
 
 
 
 
 
 
 
41
  }
42
 
 
 
 
43
  # Define Reinforcement Learning algorithm (basic Q-learning approach)
44
  class Agent:
45
  def __init__(self, agent_type):
@@ -64,16 +78,31 @@ doctor_agent = Agent("Doctor")
64
  nurse_agent = Agent("Nurse")
65
 
66
  # Streamlit UI
67
- st.title("Healthcare Civilization - Multi-Agent Simulation")
68
 
69
  st.write(f"Current number of agents in the system:")
70
  for agent, count in agents.items():
71
  st.write(f"{agent}: {count}")
72
 
 
 
 
 
 
 
 
 
 
73
  # Patient Condition Simulation
74
  patient_state = random.choice(patient_conditions)
75
  st.write(f"Simulated Patient Condition: {patient_state}")
76
 
 
 
 
 
 
 
77
  # Doctor Action Simulation
78
  doctor_action = doctor_agent.choose_action()
79
  st.write(f"Doctor's Chosen Action: {doctor_actions[doctor_action]}")
@@ -82,18 +111,49 @@ st.write(f"Doctor's Chosen Action: {doctor_actions[doctor_action]}")
82
  nurse_action = nurse_agent.choose_action()
83
  st.write(f"Nurse's Chosen Action: {nurse_actions[nurse_action]}")
84
 
85
- # Reward or penalty based on action
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
86
  reward = rewards.get(doctor_actions[doctor_action], 0)
87
- penalty = penalties.get("Wrong Medication" if doctor_action == 0 and patient_state == "Healthy" else "", 0)
 
88
 
89
  # Update Q-values
90
  doctor_agent.update_q_value(patient_conditions.index(patient_state), doctor_action, reward if penalty == 0 else penalty)
91
 
92
  st.write(f"Doctor's Reward: {reward if penalty == 0 else penalty}")
 
93
 
94
  # Simulated patient feedback and next steps
95
  next_step = random.choice(["Recovery", "Further Treatment Needed", "Complication"])
96
  st.write(f"Patient Status after treatment: {next_step}")
97
 
 
 
 
 
 
 
 
 
98
  st.write("Simulation completed! Run again to simulate different actions and outcomes.")
99
 
 
 
 
 
 
 
 
13
  # Define states for patients (health conditions)
14
  patient_conditions = ["Healthy", "Mild Illness", "Chronic Illness", "Emergency"]
15
 
16
+ # Define emotions for healthcare agents (stress, focus, etc.)
17
+ doctor_emotions = ["Calm", "Stressed", "Overwhelmed"]
18
+ nurse_emotions = ["Focused", "Fatigued", "Panicked"]
19
+
20
  # Define the actions doctors can take
21
  doctor_actions = ["Prescribe Medication", "Recommend Tests", "Consult Clinician", "Schedule Surgery"]
22
 
 
41
  penalties = {
42
  "Wrong Medication": -10,
43
  "Missed Diagnosis": -20,
44
+ "Incorrect Test Recommendation": -5,
45
+ "Stress-Induced Mistake": -15
46
+ }
47
+
48
+ # Track doctor and nurse performance metrics
49
+ performance_metrics = {
50
+ "Doctor": {"successful_treatments": 0, "failed_treatments": 0},
51
+ "Nurse": {"successful_assists": 0, "failed_assists": 0}
52
  }
53
 
54
+ # Track patient satisfaction (out of 100)
55
+ patient_satisfaction = 100
56
+
57
  # Define Reinforcement Learning algorithm (basic Q-learning approach)
58
  class Agent:
59
  def __init__(self, agent_type):
 
78
  nurse_agent = Agent("Nurse")
79
 
80
  # Streamlit UI
81
+ st.title("Enhanced Healthcare Civilization - Multi-Agent Simulation")
82
 
83
  st.write(f"Current number of agents in the system:")
84
  for agent, count in agents.items():
85
  st.write(f"{agent}: {count}")
86
 
87
+ # Simulate special event (disease outbreak or resource shortage)
88
+ special_event = random.choice([None, "Disease Outbreak", "Resource Shortage"])
89
+ if special_event:
90
+ st.subheader(f"Special Event: {special_event}")
91
+ if special_event == "Disease Outbreak":
92
+ st.write("A sudden disease outbreak has flooded the hospital with new patients. Resources are limited!")
93
+ elif special_event == "Resource Shortage":
94
+ st.write("A medical supply shortage is impacting the hospital. Staff must prioritize high-risk patients.")
95
+
96
  # Patient Condition Simulation
97
  patient_state = random.choice(patient_conditions)
98
  st.write(f"Simulated Patient Condition: {patient_state}")
99
 
100
+ # Random doctor and nurse emotions (affects performance)
101
+ doctor_emotion = random.choice(doctor_emotions)
102
+ nurse_emotion = random.choice(nurse_emotions)
103
+ st.write(f"Doctor's Emotional State: {doctor_emotion}")
104
+ st.write(f"Nurse's Emotional State: {nurse_emotion}")
105
+
106
  # Doctor Action Simulation
107
  doctor_action = doctor_agent.choose_action()
108
  st.write(f"Doctor's Chosen Action: {doctor_actions[doctor_action]}")
 
111
  nurse_action = nurse_agent.choose_action()
112
  st.write(f"Nurse's Chosen Action: {nurse_actions[nurse_action]}")
113
 
114
+ # Complications that can arise during treatment
115
+ complication = random.choice([None, "Allergic Reaction", "Unexpected Complication"])
116
+ if complication:
117
+ st.subheader(f"Complication: {complication}")
118
+ if complication == "Allergic Reaction":
119
+ st.write("The patient has developed an allergic reaction to the prescribed medication!")
120
+ penalty = penalties.get("Wrong Medication", 0)
121
+ patient_satisfaction -= 10
122
+ elif complication == "Unexpected Complication":
123
+ st.write("An unexpected complication occurred during surgery!")
124
+ penalty = penalties.get("Stress-Induced Mistake", 0)
125
+ patient_satisfaction -= 15
126
+ else:
127
+ penalty = 0
128
+
129
+ # Reward or penalty based on action and emotional state
130
  reward = rewards.get(doctor_actions[doctor_action], 0)
131
+ if doctor_emotion in ["Stressed", "Overwhelmed"]:
132
+ penalty += penalties.get("Stress-Induced Mistake", 0)
133
 
134
  # Update Q-values
135
  doctor_agent.update_q_value(patient_conditions.index(patient_state), doctor_action, reward if penalty == 0 else penalty)
136
 
137
  st.write(f"Doctor's Reward: {reward if penalty == 0 else penalty}")
138
+ st.write(f"Patient Satisfaction: {patient_satisfaction}")
139
 
140
  # Simulated patient feedback and next steps
141
  next_step = random.choice(["Recovery", "Further Treatment Needed", "Complication"])
142
  st.write(f"Patient Status after treatment: {next_step}")
143
 
144
+ # Performance tracking
145
+ if next_step == "Recovery":
146
+ performance_metrics["Doctor"]["successful_treatments"] += 1
147
+ performance_metrics["Nurse"]["successful_assists"] += 1
148
+ else:
149
+ performance_metrics["Doctor"]["failed_treatments"] += 1
150
+ performance_metrics["Nurse"]["failed_assists"] += 1
151
+
152
  st.write("Simulation completed! Run again to simulate different actions and outcomes.")
153
 
154
+ # Display performance metrics
155
+ st.subheader("Performance Metrics:")
156
+ st.write(f"Doctor's Successful Treatments: {performance_metrics['Doctor']['successful_treatments']}")
157
+ st.write(f"Doctor's Failed Treatments: {performance_metrics['Doctor']['failed_treatments']}")
158
+ st.write(f"Nurse's Successful Assists: {performance_metrics['Nurse']['successful_assists']}")
159
+ st.write(f"Nurse's Failed Assists: {performance_metrics['Nurse']['failed_assists']}")