Dhruv-Ty commited on
Commit
471785c
·
verified ·
1 Parent(s): 0c4f973

Update src/report_generator.py

Browse files
Files changed (1) hide show
  1. src/report_generator.py +38 -2
src/report_generator.py CHANGED
@@ -13,10 +13,46 @@ from reportlab.lib import colors
13
  from reportlab.lib.units import inch, cm
14
  from reportlab.platypus import PageBreak, KeepTogether
15
 
16
- from text_processors import format_conversation_history
17
  from model import orchestrator_chat
18
 
19
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
  # Function to encode images to base64 (similar to app.py)
21
  def get_image_base64(image_path):
22
  try:
@@ -459,7 +495,7 @@ def generate_and_download_report():
459
  # Step 4: Generate report
460
  elif st.session_state.report_step == 4:
461
  with st.spinner("Generating medical report..."):
462
- # Format conversation with patient info
463
  conversation_text = format_conversation_history(
464
  st.session_state.history,
465
  st.session_state.patient_info
 
13
  from reportlab.lib.units import inch, cm
14
  from reportlab.platypus import PageBreak, KeepTogether
15
 
 
16
  from model import orchestrator_chat
17
 
18
 
19
+ # Function to format conversation history for report generation
20
+ def format_conversation_history(history, patient_info=None):
21
+ """
22
+ Format the conversation history into a string suitable for LLM processing.
23
+ Optionally adds patient info at the beginning.
24
+ """
25
+ formatted_text = "# Medical Consultation\n\n"
26
+
27
+ # Add patient info if provided
28
+ if patient_info:
29
+ formatted_text += "## Patient Information\n"
30
+ formatted_text += f"* Name: {patient_info.get('name', '')}\n"
31
+ formatted_text += f"* Age: {patient_info.get('age', '')}\n"
32
+ formatted_text += f"* Gender: {patient_info.get('gender', '')}\n\n"
33
+
34
+ formatted_text += "## Conversation Transcript\n\n"
35
+
36
+ for message in history:
37
+ role = message.get("role", "").strip()
38
+ content = message.get("content", "").strip()
39
+
40
+ if not content:
41
+ continue # Skip empty messages
42
+
43
+ if role.lower() == "user":
44
+ formatted_text += f"PATIENT: {content}\n\n"
45
+ elif role.lower() == "assistant":
46
+ formatted_text += f"ASSISTANT: {content}\n\n"
47
+ # Include explanations which often contain diagnostic reasoning
48
+ if "explanation" in message and message["explanation"]:
49
+ explanation = message.get("explanation", "").strip()
50
+ if explanation:
51
+ formatted_text += f"REASONING: {explanation}\n\n"
52
+
53
+ return formatted_text
54
+
55
+
56
  # Function to encode images to base64 (similar to app.py)
57
  def get_image_base64(image_path):
58
  try:
 
495
  # Step 4: Generate report
496
  elif st.session_state.report_step == 4:
497
  with st.spinner("Generating medical report..."):
498
+ # Format conversation with patient info - using the local format_conversation_history
499
  conversation_text = format_conversation_history(
500
  st.session_state.history,
501
  st.session_state.patient_info