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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +91 -21
app.py CHANGED
@@ -1,29 +1,99 @@
1
- import json
2
  import streamlit as st
 
 
3
 
4
- # Load the JSON file
5
- with open('prompt_configure.json', 'r') as file:
6
- role_data = json.load(file)
 
 
 
 
7
 
8
- st.title("PrecisionCare Agent Interaction System")
 
9
 
10
- # Select agent type
11
- agent_type = st.selectbox("Select an agent type:", role_data['roles'].keys())
12
 
13
- # Get the selected agent's data
14
- agent_info = role_data['roles'][agent_type]
15
- st.write(f"Interacting with {agent_info['name']}")
16
 
17
- # Multiple prompt options
18
- prompt_options = st.multiselect("Select tasks to perform:", [task['task'] for task in agent_info['prompts']])
19
 
20
- # Display input fields for selected tasks
21
- for prompt in prompt_options:
22
- task_info = next(item for item in agent_info['prompts'] if item['task'] == prompt)
23
- if task_info['input_type'] == 'textarea':
24
- user_input = st.text_area(task_info['input_label'])
25
- st.write(f"{agent_info['name']} - {task_info['task']}: {user_input}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26
 
27
- # Submit the interaction
28
- if st.button("Submit"):
29
- st.write(f"Interactions for {agent_type} have been submitted.")
 
 
1
  import streamlit as st
2
+ import numpy as np
3
+ import random
4
 
5
+ # Initialize agents (doctors, nurses, clinicians, patients)
6
+ agents = {
7
+ "Doctors": 5,
8
+ "Nurses": 10,
9
+ "Clinicians": 8,
10
+ "Patients": 200
11
+ }
12
 
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
 
19
+ # Define the actions nurses can take
20
+ nurse_actions = ["Monitor Vitals", "Administer Medication", "Report to Doctor", "Assist Surgery"]
 
21
 
22
+ # Define the actions clinicians can take
23
+ clinician_actions = ["Review Diagnostic Test", "Consult with Doctor", "Recommend Additional Tests"]
24
 
25
+ # Reward and penalty system (simplified for Reinforcement Learning concept)
26
+ rewards = {
27
+ "Prescribe Medication": 10,
28
+ "Recommend Tests": 5,
29
+ "Consult Clinician": 7,
30
+ "Schedule Surgery": 15,
31
+ "Monitor Vitals": 3,
32
+ "Administer Medication": 10,
33
+ "Review Diagnostic Test": 6,
34
+ "Recommend Additional Tests": 4
35
+ }
36
+
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):
46
+ self.agent_type = agent_type
47
+ self.q_table = np.zeros((len(patient_conditions), len(doctor_actions if agent_type == "Doctor" else nurse_actions)))
48
+ self.state = random.choice(patient_conditions)
49
+
50
+ def choose_action(self, exploration_rate=0.1):
51
+ if random.uniform(0, 1) < exploration_rate: # Explore
52
+ return random.randint(0, len(doctor_actions)-1 if self.agent_type == "Doctor" else len(nurse_actions)-1)
53
+ else: # Exploit (choose the best action based on Q-values)
54
+ return np.argmax(self.q_table)
55
+
56
+ def update_q_value(self, state, action, reward, learning_rate=0.1, discount_factor=0.95):
57
+ old_q_value = self.q_table[state, action]
58
+ best_future_q_value = np.max(self.q_table)
59
+ new_q_value = old_q_value + learning_rate * (reward + discount_factor * best_future_q_value - old_q_value)
60
+ self.q_table[state, action] = new_q_value
61
+
62
+ # Instantiate agents
63
+ 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]}")
80
+
81
+ # Nurse Action Simulation
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