Update src/streamlit_app.py
Browse files- src/streamlit_app.py +48 -2
src/streamlit_app.py
CHANGED
@@ -15,7 +15,6 @@ from sendgrid_service import SendGridService
|
|
15 |
from report_generator import (
|
16 |
extract_medical_json,
|
17 |
build_medical_report,
|
18 |
-
format_conversation_history,
|
19 |
generate_and_download_report,
|
20 |
show_email_form
|
21 |
)
|
@@ -646,4 +645,51 @@ st.markdown("""
|
|
646 |
<div class="footer-text">
|
647 |
For informational purposes only. Not a substitute for professional medical advice.
|
648 |
</div>
|
649 |
-
""", unsafe_allow_html=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
from report_generator import (
|
16 |
extract_medical_json,
|
17 |
build_medical_report,
|
|
|
18 |
generate_and_download_report,
|
19 |
show_email_form
|
20 |
)
|
|
|
645 |
<div class="footer-text">
|
646 |
For informational purposes only. Not a substitute for professional medical advice.
|
647 |
</div>
|
648 |
+
""", unsafe_allow_html=True)
|
649 |
+
|
650 |
+
# Function to format conversation history for report generation
|
651 |
+
def format_conversation_history(history, patient_info=None):
|
652 |
+
"""
|
653 |
+
Format the conversation history into a string suitable for LLM processing.
|
654 |
+
Optionally adds patient info at the beginning.
|
655 |
+
"""
|
656 |
+
formatted_text = "# Medical Consultation\n\n"
|
657 |
+
|
658 |
+
# Add patient info if provided
|
659 |
+
if patient_info:
|
660 |
+
formatted_text += "## Patient Information\n"
|
661 |
+
formatted_text += f"* Name: {patient_info.get('name', '')}\n"
|
662 |
+
formatted_text += f"* Age: {patient_info.get('age', '')}\n"
|
663 |
+
formatted_text += f"* Gender: {patient_info.get('gender', '')}\n\n"
|
664 |
+
|
665 |
+
formatted_text += "## Conversation Transcript\n\n"
|
666 |
+
|
667 |
+
for message in history:
|
668 |
+
role = message.get("role", "").strip()
|
669 |
+
content = message.get("content", "").strip()
|
670 |
+
|
671 |
+
if not content:
|
672 |
+
continue # Skip empty messages
|
673 |
+
|
674 |
+
if role.lower() == "user":
|
675 |
+
formatted_text += f"PATIENT: {content}\n\n"
|
676 |
+
elif role.lower() == "assistant":
|
677 |
+
formatted_text += f"ASSISTANT: {content}\n\n"
|
678 |
+
# Include explanations which often contain diagnostic reasoning
|
679 |
+
if "explanation" in message and message["explanation"]:
|
680 |
+
explanation = message.get("explanation", "").strip()
|
681 |
+
if explanation:
|
682 |
+
formatted_text += f"REASONING: {explanation}\n\n"
|
683 |
+
|
684 |
+
return formatted_text
|
685 |
+
|
686 |
+
# This ensures app.py can be used as a direct entry point for deployment platforms like Hugging Face
|
687 |
+
if __name__ == "__main__":
|
688 |
+
# Add the current directory to the Python path if needed
|
689 |
+
import os
|
690 |
+
import sys
|
691 |
+
current_dir = os.path.dirname(os.path.abspath(__file__))
|
692 |
+
if current_dir not in sys.path:
|
693 |
+
sys.path.insert(0, current_dir)
|
694 |
+
|
695 |
+
# The app is already running due to the Streamlit script structure
|