Spaces:
Runtime error
Runtime error
Commit
Β·
5b8ce4d
1
Parent(s):
f48d0d7
made changes to the prompts for report section
Browse files- interface.py +25 -21
- medrax/docs/system_prompts.txt +37 -39
interface.py
CHANGED
|
@@ -275,10 +275,10 @@ def create_demo(agent, tools_dict):
|
|
| 275 |
|
| 276 |
with gr.Tab(label="Report section"):
|
| 277 |
generate_report_btn = gr.Button("Generate Report")
|
| 278 |
-
diseases_df = gr.Dataframe(
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
|
| 282 |
conclusion_tb = gr.Textbox(label="Conclusion", interactive=False, visible=False)
|
| 283 |
with gr.Row():
|
| 284 |
approve_btn = gr.Button("Approve", visible=False)
|
|
@@ -324,19 +324,19 @@ def create_demo(agent, tools_dict):
|
|
| 324 |
|
| 325 |
def generate_report():
|
| 326 |
result = interface.agent.summarize_message(interface.current_thread_id)
|
| 327 |
-
table = [[d["name"], d["info"]] for d in result["Disease"]]
|
| 328 |
return (
|
| 329 |
-
gr.update(value=table, interactive=True, visible=True),
|
| 330 |
gr.update(value=result["Conclusion"], lines=4, interactive=True, visible=True),
|
| 331 |
gr.update(visible=True),
|
| 332 |
gr.update(visible=True),
|
| 333 |
)
|
| 334 |
|
| 335 |
-
def records_to_pdf(table, conclusion) -> Path:
|
|
|
|
| 336 |
"""
|
| 337 |
Writes a PDF report under ./reports/ and returns the Path.
|
| 338 |
"""
|
| 339 |
-
print(type(table))
|
| 340 |
pdf = FPDF()
|
| 341 |
pdf.set_auto_page_break(auto=True, margin=15)
|
| 342 |
pdf.add_page()
|
|
@@ -345,17 +345,17 @@ def create_demo(agent, tools_dict):
|
|
| 345 |
pdf.cell(0, 10, "Chest-X-ray Report", ln=1, align="C")
|
| 346 |
pdf.ln(4)
|
| 347 |
|
| 348 |
-
pdf.set_font(family="Helvetica", style="B")
|
| 349 |
-
pdf.cell(60, 8, "Disease")
|
| 350 |
-
pdf.cell(0, 8, "Information", ln=1)
|
| 351 |
-
pdf.set_font(family="Helvetica", style="")
|
| 352 |
|
| 353 |
-
for idx, row in table.iterrows():
|
| 354 |
-
|
| 355 |
|
| 356 |
-
pdf.ln(4)
|
| 357 |
-
pdf.set_font(family="Helvetica", style="B")
|
| 358 |
-
pdf.cell(0, 8, "Conclusion", ln=1)
|
| 359 |
pdf.set_font(family="Helvetica", style="")
|
| 360 |
pdf.multi_cell(0, 8, conclusion)
|
| 361 |
|
|
@@ -363,8 +363,10 @@ def create_demo(agent, tools_dict):
|
|
| 363 |
pdf.output(str(pdf_path))
|
| 364 |
return pdf_path
|
| 365 |
|
| 366 |
-
def build_pdf_and_preview(table, conclusion):
|
| 367 |
-
|
|
|
|
|
|
|
| 368 |
|
| 369 |
iframe_html = (
|
| 370 |
f'<iframe src="file={pdf_path}" '
|
|
@@ -430,10 +432,12 @@ def create_demo(agent, tools_dict):
|
|
| 430 |
|
| 431 |
clear_btn.click(clear_chat, outputs=[chatbot, image_display])
|
| 432 |
new_thread_btn.click(new_thread, outputs=[chatbot, image_display])
|
| 433 |
-
generate_report_btn.click(generate_report, outputs=[diseases_df, conclusion_tb, approve_btn, reject_btn])
|
|
|
|
| 434 |
approve_btn.click(
|
| 435 |
build_pdf_and_preview,
|
| 436 |
-
inputs=[diseases_df, conclusion_tb],
|
|
|
|
| 437 |
outputs=[download_pdf_btn, pdf_preview],
|
| 438 |
)
|
| 439 |
reject_btn.click(show_reject_ui, outputs=[rejection_text, submit_reject_btn, cancel_reject_btn])
|
|
|
|
| 275 |
|
| 276 |
with gr.Tab(label="Report section"):
|
| 277 |
generate_report_btn = gr.Button("Generate Report")
|
| 278 |
+
# diseases_df = gr.Dataframe(
|
| 279 |
+
# headers=["Disease", "Info"],
|
| 280 |
+
# datatype=["str", "str"],
|
| 281 |
+
# interactive=False, visible=False, max_height=220)
|
| 282 |
conclusion_tb = gr.Textbox(label="Conclusion", interactive=False, visible=False)
|
| 283 |
with gr.Row():
|
| 284 |
approve_btn = gr.Button("Approve", visible=False)
|
|
|
|
| 324 |
|
| 325 |
def generate_report():
|
| 326 |
result = interface.agent.summarize_message(interface.current_thread_id)
|
| 327 |
+
# table = [[d["name"], d["info"]] for d in result["Disease"]]
|
| 328 |
return (
|
| 329 |
+
# gr.update(value=table, interactive=True, visible=True),
|
| 330 |
gr.update(value=result["Conclusion"], lines=4, interactive=True, visible=True),
|
| 331 |
gr.update(visible=True),
|
| 332 |
gr.update(visible=True),
|
| 333 |
)
|
| 334 |
|
| 335 |
+
# def records_to_pdf(table, conclusion) -> Path:
|
| 336 |
+
def records_to_pdf(conclusion) -> Path:
|
| 337 |
"""
|
| 338 |
Writes a PDF report under ./reports/ and returns the Path.
|
| 339 |
"""
|
|
|
|
| 340 |
pdf = FPDF()
|
| 341 |
pdf.set_auto_page_break(auto=True, margin=15)
|
| 342 |
pdf.add_page()
|
|
|
|
| 345 |
pdf.cell(0, 10, "Chest-X-ray Report", ln=1, align="C")
|
| 346 |
pdf.ln(4)
|
| 347 |
|
| 348 |
+
# pdf.set_font(family="Helvetica", style="B")
|
| 349 |
+
# pdf.cell(60, 8, "Disease")
|
| 350 |
+
# pdf.cell(0, 8, "Information", ln=1)
|
| 351 |
+
# pdf.set_font(family="Helvetica", style="")
|
| 352 |
|
| 353 |
+
# for idx, row in table.iterrows():
|
| 354 |
+
# pdf.multi_cell(0, 8, f"{row['Disease']}: {row['Info']}")
|
| 355 |
|
| 356 |
+
# pdf.ln(4)
|
| 357 |
+
# pdf.set_font(family="Helvetica", style="B")
|
| 358 |
+
# pdf.cell(0, 8, "Conclusion", ln=1)
|
| 359 |
pdf.set_font(family="Helvetica", style="")
|
| 360 |
pdf.multi_cell(0, 8, conclusion)
|
| 361 |
|
|
|
|
| 363 |
pdf.output(str(pdf_path))
|
| 364 |
return pdf_path
|
| 365 |
|
| 366 |
+
# def build_pdf_and_preview(table, conclusion):
|
| 367 |
+
def build_pdf_and_preview(conclusion):
|
| 368 |
+
# pdf_path = records_to_pdf(table, conclusion)
|
| 369 |
+
pdf_path = records_to_pdf(conclusion)
|
| 370 |
|
| 371 |
iframe_html = (
|
| 372 |
f'<iframe src="file={pdf_path}" '
|
|
|
|
| 432 |
|
| 433 |
clear_btn.click(clear_chat, outputs=[chatbot, image_display])
|
| 434 |
new_thread_btn.click(new_thread, outputs=[chatbot, image_display])
|
| 435 |
+
# generate_report_btn.click(generate_report, outputs=[diseases_df, conclusion_tb, approve_btn, reject_btn])
|
| 436 |
+
generate_report_btn.click(generate_report, outputs=[conclusion_tb, approve_btn, reject_btn])
|
| 437 |
approve_btn.click(
|
| 438 |
build_pdf_and_preview,
|
| 439 |
+
# inputs=[diseases_df, conclusion_tb],
|
| 440 |
+
inputs=[conclusion_tb],
|
| 441 |
outputs=[download_pdf_btn, pdf_preview],
|
| 442 |
)
|
| 443 |
reject_btn.click(show_reject_ui, outputs=[rejection_text, submit_reject_btn, cancel_reject_btn])
|
medrax/docs/system_prompts.txt
CHANGED
|
@@ -42,47 +42,45 @@ You are a helpful AI assistant. Your role is to assist users with a wide range o
|
|
| 42 |
|
| 43 |
|
| 44 |
[SUMMARIZE_SYSTEM_PROMPT]
|
| 45 |
-
You are an expert medical
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
|
| 51 |
-
[SUMMARIZE_USER_PROMPT]
|
| 52 |
-
Your task is to go through the following chat history and create a summary by identifying the diseases mentioned and providing relevant information.
|
| 53 |
|
| 54 |
-
|
|
|
|
| 55 |
{chat_messages}
|
| 56 |
|
| 57 |
-
###
|
| 58 |
-
|
| 59 |
-
- The description related to the disease must be derived from the information available in the chat history and there must be no additional information provided.
|
| 60 |
-
- In case no diseases are found, in the response, please indicate 'No Evident Diseases' under the 'name' key and state the reason for it under the 'info' key.
|
| 61 |
-
|
| 62 |
-
### Expected Response Schema:
|
| 63 |
-
Always respond with a single valid $JSON_BLOB as follows:
|
| 64 |
-
If diseases are found:
|
| 65 |
-
```json
|
| 66 |
-
{{
|
| 67 |
-
"Disease": [
|
| 68 |
-
{{
|
| 69 |
-
"name": "<string: The name of the disease.>",
|
| 70 |
-
"info": "<string: A short description regarding disease (can include key factors and figures related to it).>"
|
| 71 |
-
}}
|
| 72 |
-
],
|
| 73 |
-
"Conclusion": "<string: A final information providing a summary based on the values within the 'Disease' key.>"
|
| 74 |
-
}}
|
| 75 |
-
```
|
| 76 |
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
{{
|
| 82 |
-
"name": "<string: No Evident Diseases.>",
|
| 83 |
-
"info": "<string: A short description explaining the reason why there are no diseases found.>"
|
| 84 |
-
}}
|
| 85 |
-
],
|
| 86 |
-
"Conclusion": "<string: A final information providing a summary based on the values within the 'Disease' key.>"
|
| 87 |
-
}}
|
| 88 |
-
```
|
|
|
|
| 42 |
|
| 43 |
|
| 44 |
[SUMMARIZE_SYSTEM_PROMPT]
|
| 45 |
+
You are **MedReport-GPT** an expert medical documentation assistant.
|
| 46 |
+
|
| 47 |
+
Your job is to read a list of chat messages (supplied in JSON) and distil them into a single, well-structured clinical summary appropriate for healthcare professionals (physicians, nurses, pharmacists, clinical coders, etc.).
|
| 48 |
+
|
| 49 |
+
Each item in the JSON input has:
|
| 50 |
+
β type : The type of message. Can either be Human message, AI message, or Tool message.
|
| 51 |
+
β content: The textual message
|
| 52 |
+
|
| 53 |
+
Write formally, using standard medical terminology and abbreviations that a clinician would understand. Organise the summary under the following fixed section headings (include a heading even if the section must be left blank or state βNot mentionedβ):
|
| 54 |
+
|
| 55 |
+
1. Presenting Concerns / Chief Complaints
|
| 56 |
+
2. Medications & Therapies
|
| 57 |
+
3. Examination / Vital Signs
|
| 58 |
+
4. Investigations & Results
|
| 59 |
+
5. Differential Diagnoses (if explicitly discussed)
|
| 60 |
+
6. Assessment & Impression
|
| 61 |
+
7. Management Plan / Recommendations
|
| 62 |
+
8. Follow-up & Next Steps
|
| 63 |
+
|
| 64 |
+
Within each heading, provide detailed information and use bullet points if necessary.
|
| 65 |
+
If **no medical information** is found at all, state under heading 1: βNo clinically relevant data in chat historyβ and leave the remaining sections as βN/Aβ.
|
| 66 |
+
|
| 67 |
+
**Output format**
|
| 68 |
+
Return **exactly one valid JSON object** with this structure:
|
| 69 |
+
|
| 70 |
+
```json
|
| 71 |
+
{{
|
| 72 |
+
"Conclusion": "<single string containing the formatted report; use newline characters (\\n) to separate lines>"
|
| 73 |
+
}}
|
| 74 |
|
|
|
|
|
|
|
| 75 |
|
| 76 |
+
[SUMMARIZE_USER_PROMPT]
|
| 77 |
+
### Chat History
|
| 78 |
{chat_messages}
|
| 79 |
|
| 80 |
+
### Task
|
| 81 |
+
Create a single comprehensive **Clinical Summary Report** following the heading template defined in the system prompt.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
|
| 83 |
+
Remember:
|
| 84 |
+
* Include only details present in the chat history.
|
| 85 |
+
* Do not add any information that is not explicitly supported by the messages.
|
| 86 |
+
* Maintain professional tone suitable for medical records.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|