Update app.py
Browse files
app.py
CHANGED
|
@@ -176,8 +176,7 @@ def analyze_ecg_image(image):
|
|
| 176 |
},
|
| 177 |
],
|
| 178 |
}
|
| 179 |
-
]
|
| 180 |
-
max_tokens=2048
|
| 181 |
)
|
| 182 |
|
| 183 |
ecg_analysis = response.output_text
|
|
@@ -265,17 +264,8 @@ Important Instructions:
|
|
| 265 |
try:
|
| 266 |
assessment_completion = openai_client.responses.create(
|
| 267 |
model="gpt-4.1",
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
"role": "system",
|
| 271 |
-
"content": "You are a medical AI assistant specialized in cardiology. Generate a structured clinical assessment based on the provided ECG and patient data, formatted in HTML for physician review. Highlight urgent findings appropriately. Avoid definitive diagnoses."
|
| 272 |
-
},
|
| 273 |
-
{
|
| 274 |
-
"role": "user",
|
| 275 |
-
"content": [{"type": "input_text", "text": prompt}]
|
| 276 |
-
}
|
| 277 |
-
],
|
| 278 |
-
max_tokens=2048
|
| 279 |
)
|
| 280 |
|
| 281 |
assessment_text = assessment_completion.output_text
|
|
@@ -351,10 +341,27 @@ Based *only* on the patient context provided above, answer the doctor's question
|
|
| 351 |
messages.append({"role": "user", "content": [{"type": "input_text", "text": message}]})
|
| 352 |
|
| 353 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 354 |
chat_completion = openai_client.responses.create(
|
| 355 |
model="gpt-4.1",
|
| 356 |
-
|
| 357 |
-
|
| 358 |
)
|
| 359 |
|
| 360 |
response = chat_completion.output_text
|
|
|
|
| 176 |
},
|
| 177 |
],
|
| 178 |
}
|
| 179 |
+
]
|
|
|
|
| 180 |
)
|
| 181 |
|
| 182 |
ecg_analysis = response.output_text
|
|
|
|
| 264 |
try:
|
| 265 |
assessment_completion = openai_client.responses.create(
|
| 266 |
model="gpt-4.1",
|
| 267 |
+
instructions="You are a medical AI assistant specialized in cardiology. Generate a structured clinical assessment based on the provided ECG and patient data, formatted in HTML for physician review. Highlight urgent findings appropriately. Avoid definitive diagnoses.",
|
| 268 |
+
input=prompt
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 269 |
)
|
| 270 |
|
| 271 |
assessment_text = assessment_completion.output_text
|
|
|
|
| 341 |
messages.append({"role": "user", "content": [{"type": "input_text", "text": message}]})
|
| 342 |
|
| 343 |
try:
|
| 344 |
+
# Format the messages for GPT-4.1 API
|
| 345 |
+
system_prompt = messages[0]["content"]
|
| 346 |
+
# Combine all subsequent messages into the input
|
| 347 |
+
user_messages = []
|
| 348 |
+
for msg in messages[1:]:
|
| 349 |
+
if msg["role"] == "user":
|
| 350 |
+
if isinstance(msg["content"], list):
|
| 351 |
+
for content in msg["content"]:
|
| 352 |
+
if isinstance(content, dict) and content.get("type") == "input_text":
|
| 353 |
+
user_messages.append(content["text"])
|
| 354 |
+
else:
|
| 355 |
+
user_messages.append(str(msg["content"]))
|
| 356 |
+
else:
|
| 357 |
+
user_messages.append(msg["content"])
|
| 358 |
+
|
| 359 |
+
combined_input = "\n\n".join(user_messages)
|
| 360 |
+
|
| 361 |
chat_completion = openai_client.responses.create(
|
| 362 |
model="gpt-4.1",
|
| 363 |
+
instructions=system_prompt,
|
| 364 |
+
input=combined_input
|
| 365 |
)
|
| 366 |
|
| 367 |
response = chat_completion.output_text
|