Spaces:
Paused
Paused
Commit
·
d1e0ac0
1
Parent(s):
01e6a62
fixed local running bug
Browse files
app.py
CHANGED
@@ -42,7 +42,7 @@ model.eval()
|
|
42 |
|
43 |
# === Role Agent with instruction/input/output format ===
|
44 |
class RoleAgent:
|
45 |
-
def __init__(self, role_instruction, tokenizer, model):
|
46 |
self.tokenizer = tokenizer
|
47 |
self.model = model
|
48 |
self.role_instruction = role_instruction
|
@@ -53,18 +53,18 @@ class RoleAgent:
|
|
53 |
f"Input: {input_text}\n"
|
54 |
f"Output:"
|
55 |
)
|
56 |
-
print("tokenizer is:", tokenizer, "— type:", type(tokenizer))
|
57 |
-
encoding = tokenizer(prompt, return_tensors="pt")
|
58 |
-
inputs = {k: v.to(model.device) for k, v in encoding.items()}
|
59 |
|
60 |
-
outputs = model.generate(
|
61 |
**inputs,
|
62 |
max_new_tokens=256,
|
63 |
do_sample=True,
|
64 |
temperature=0.7,
|
65 |
-
pad_token_id=tokenizer.eos_token_id,
|
66 |
)
|
67 |
-
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
68 |
|
69 |
thinking = ""
|
70 |
answer = response
|
@@ -78,20 +78,24 @@ class RoleAgent:
|
|
78 |
|
79 |
# === Agents ===
|
80 |
summarizer = RoleAgent(
|
81 |
-
"You are a clinical summarizer trained to extract structured vignettes from doctor–patient dialogues.",
|
82 |
-
tokenizer,
|
83 |
-
model,
|
84 |
)
|
85 |
diagnoser = RoleAgent(
|
86 |
-
"You are a board-certified diagnostician that diagnoses patients.",
|
|
|
|
|
87 |
)
|
88 |
questioner = RoleAgent(
|
89 |
-
"You are a physician asking questions to diagnose a patient.",
|
|
|
|
|
90 |
)
|
91 |
treatment_agent = RoleAgent(
|
92 |
-
"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.",
|
93 |
-
tokenizer,
|
94 |
-
model,
|
95 |
)
|
96 |
|
97 |
|
|
|
42 |
|
43 |
# === Role Agent with instruction/input/output format ===
|
44 |
class RoleAgent:
|
45 |
+
def __init__(self, role_instruction, tokenizer=tokenizer, model=model):
|
46 |
self.tokenizer = tokenizer
|
47 |
self.model = model
|
48 |
self.role_instruction = role_instruction
|
|
|
53 |
f"Input: {input_text}\n"
|
54 |
f"Output:"
|
55 |
)
|
56 |
+
print("tokenizer is:", self.tokenizer, "— type:", type(self.tokenizer))
|
57 |
+
encoding = self.tokenizer(prompt, return_tensors="pt")
|
58 |
+
inputs = {k: v.to(self.model.device) for k, v in encoding.items()}
|
59 |
|
60 |
+
outputs = self.model.generate(
|
61 |
**inputs,
|
62 |
max_new_tokens=256,
|
63 |
do_sample=True,
|
64 |
temperature=0.7,
|
65 |
+
pad_token_id=self.tokenizer.eos_token_id,
|
66 |
)
|
67 |
+
response = self.tokenizer.decode(outputs[0], skip_special_tokens=True)
|
68 |
|
69 |
thinking = ""
|
70 |
answer = response
|
|
|
78 |
|
79 |
# === Agents ===
|
80 |
summarizer = RoleAgent(
|
81 |
+
role_instruction="You are a clinical summarizer trained to extract structured vignettes from doctor–patient dialogues.",
|
82 |
+
tokenizer=tokenizer,
|
83 |
+
model=model,
|
84 |
)
|
85 |
diagnoser = RoleAgent(
|
86 |
+
role_instruction="You are a board-certified diagnostician that diagnoses patients.",
|
87 |
+
tokenizer=tokenizer,
|
88 |
+
model=model,
|
89 |
)
|
90 |
questioner = RoleAgent(
|
91 |
+
role_instruction="You are a physician asking questions to diagnose a patient.",
|
92 |
+
tokenizer=tokenizer,
|
93 |
+
model=model,
|
94 |
)
|
95 |
treatment_agent = RoleAgent(
|
96 |
+
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.",
|
97 |
+
tokenizer=tokenizer,
|
98 |
+
model=model,
|
99 |
)
|
100 |
|
101 |
|