CodCodingCode commited on
Commit
ee5d942
·
1 Parent(s): c0ef450

switched to new model name

Browse files
Files changed (1) hide show
  1. app.py +68 -11
app.py CHANGED
@@ -5,8 +5,8 @@ from transformers import AutoTokenizer, AutoModelForCausalLM
5
  import gradio as gr
6
 
7
  # ——— CONFIG ———
8
- REPO_ID = "CodCodingCode/llama-3.1-8b-clinical"
9
- SUBFOLDER = "checkpoint-45000"
10
  HF_TOKEN = os.getenv("HUGGINGFACE_HUB_TOKEN")
11
  if not HF_TOKEN:
12
  raise RuntimeError("Missing HUGGINGFACE_HUB_TOKEN in env")
@@ -179,23 +179,80 @@ class RoleAgent:
179
 
180
 
181
  # === Agents ===
 
 
182
  summarizer = RoleAgent(
183
- role_instruction="You are a clinical summarizer trained to extract structured vignettes from doctor–patient dialogues.",
 
 
 
 
184
  tokenizer=tokenizer,
185
  model=model,
186
  )
187
- diagnoser = RoleAgent(
188
- role_instruction="You are a board-certified diagnostician that diagnoses patients.",
 
 
 
 
 
189
  tokenizer=tokenizer,
190
  model=model,
191
  )
192
- questioner = RoleAgent(
193
- role_instruction="You are a physician asking questions to diagnose a patient.",
 
 
 
 
 
194
  tokenizer=tokenizer,
195
  model=model,
196
  )
197
- treatment_agent = RoleAgent(
198
- role_instruction="You are a board-certified clinician. Based on the diagnosis and patient vignette provided below, suggest a concise treatment plan that could realistically be initiated by a primary care physician or psychiatrist.",
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
199
  tokenizer=tokenizer,
200
  model=model,
201
  )
@@ -235,12 +292,12 @@ def simulate_interaction(user_input, conversation_history=None):
235
  summary = sum_out["output"]
236
 
237
  # Diagnose based on summary
238
- diag_out = diagnoser.act(summary)
239
  diagnosis = diag_out["output"]
240
 
241
  # Generate next question based on current understanding
242
  q_in = f"Vignette: {summary}\nCurrent Estimated Diagnosis: {diagnosis}"
243
- q_out = questioner.act(q_in)
244
 
245
  # Add doctor's response to history
246
  history.append(f"Doctor: {q_out['output']}")
 
5
  import gradio as gr
6
 
7
  # ——— CONFIG ———
8
+ REPO_ID = "CodCodingCode/llama-3.1-8b-clinical-v1.1"
9
+ SUBFOLDER = "checkpoint-2250"
10
  HF_TOKEN = os.getenv("HUGGINGFACE_HUB_TOKEN")
11
  if not HF_TOKEN:
12
  raise RuntimeError("Missing HUGGINGFACE_HUB_TOKEN in env")
 
179
 
180
 
181
  # === Agents ===
182
+ # ——— Instantiate RoleAgents for each of your eight roles ———
183
+
184
  summarizer = RoleAgent(
185
+ role_instruction=(
186
+ "“You are a clinical summarizer. Given a transcript of a doctor–patient dialogue, "
187
+ "extract a structured clinical vignette summarizing the key symptoms, relevant history, "
188
+ "and any diagnostic clues.”"
189
+ ),
190
  tokenizer=tokenizer,
191
  model=model,
192
  )
193
+
194
+ treatment_agent = RoleAgent(
195
+ role_instruction=(
196
+ "You are a board-certified clinician. Based on the provided diagnosis and patient vignette, "
197
+ "propose a realistic, evidence-based treatment plan suitable for initiation by a primary care "
198
+ "physician or psychiatrist."
199
+ ),
200
  tokenizer=tokenizer,
201
  model=model,
202
  )
203
+
204
+ diagnoser_early = RoleAgent(
205
+ role_instruction=(
206
+ "You are a diagnostic reasoning model (Early Stage). Based on the patient vignette and "
207
+ "early-stage observations, generate a list of plausible diagnoses with reasoning. Focus on "
208
+ "broad differentials, considering common and uncommon conditions."
209
+ ),
210
  tokenizer=tokenizer,
211
  model=model,
212
  )
213
+
214
+ diagnoser_middle = RoleAgent(
215
+ role_instruction=(
216
+ "You are a diagnostic reasoning model (Middle Stage). Given the current vignette, prior dialogue, "
217
+ "and diagnostic hypothesis, refine the list of possible diagnoses with concise justifications for each. "
218
+ "Aim to reduce diagnostic uncertainty."
219
+ ),
220
+ tokenizer=tokenizer,
221
+ model=model,
222
+ )
223
+
224
+ diagnoser_late = RoleAgent(
225
+ role_instruction=(
226
+ "You are a diagnostic reasoning model (Late Stage). Based on the final patient vignette summary and full conversation, "
227
+ "provide the most likely diagnosis with structured reasoning. Confirm diagnostic certainty and include END if no more questioning is necessary."
228
+ ),
229
+ tokenizer=tokenizer,
230
+ model=model,
231
+ )
232
+
233
+ questioner_early = RoleAgent(
234
+ role_instruction=(
235
+ "You are a questioning agent (Early Stage). Your task is to propose highly relevant early-stage questions "
236
+ "that can open the differential diagnosis widely. Use epidemiology, demographics, and vague presenting symptoms as guides."
237
+ ),
238
+ tokenizer=tokenizer,
239
+ model=model,
240
+ )
241
+
242
+ questioner_middle = RoleAgent(
243
+ role_instruction=(
244
+ "You are a questioning agent (Middle Stage). Using the current diagnosis, past questions, and patient vignette, "
245
+ "generate a specific question to refine the current differential diagnosis. Return your reasoning and next question."
246
+ ),
247
+ tokenizer=tokenizer,
248
+ model=model,
249
+ )
250
+
251
+ questioner_late = RoleAgent(
252
+ role_instruction=(
253
+ "You are a questioning agent (Late Stage). Based on narrowed differentials and previous dialogue, "
254
+ "generate a focused question that would help confirm or eliminate the final 1-2 suspected diagnoses."
255
+ ),
256
  tokenizer=tokenizer,
257
  model=model,
258
  )
 
292
  summary = sum_out["output"]
293
 
294
  # Diagnose based on summary
295
+ diag_out = diagnoser_middle.act(summary)
296
  diagnosis = diag_out["output"]
297
 
298
  # Generate next question based on current understanding
299
  q_in = f"Vignette: {summary}\nCurrent Estimated Diagnosis: {diagnosis}"
300
+ q_out = questioner_middle.act(q_in)
301
 
302
  # Add doctor's response to history
303
  history.append(f"Doctor: {q_out['output']}")