Dhruv-Ty commited on
Commit
4d3b443
Β·
verified Β·
1 Parent(s): b6d67b5
Files changed (1) hide show
  1. src/ui_helpers.py +0 -104
src/ui_helpers.py DELETED
@@ -1,104 +0,0 @@
1
- import os
2
- import base64
3
- import streamlit as st
4
-
5
-
6
- def get_image_base64(image_path):
7
- """Encode an image file to base64."""
8
- try:
9
- if os.path.exists(image_path):
10
- with open(image_path, "rb") as img_file:
11
- return base64.b64encode(img_file.read()).decode()
12
- else:
13
- st.warning(f"Image not found: {image_path}")
14
- return None
15
- except Exception as e:
16
- st.warning(f"Error loading image: {e}")
17
- return None
18
-
19
-
20
- def load_avatars():
21
- """Load avatar images for user and assistant."""
22
- # Define paths to company logo images
23
- user_logo_path = os.path.join("src/assets", "icon3.png")
24
- assistant_logo_path = os.path.join("src/assets", "logo.png")
25
-
26
- # Get base64 encoded images or use default emoji as fallback
27
- user_logo_base64 = get_image_base64(user_logo_path)
28
- assistant_logo_base64 = get_image_base64(assistant_logo_path)
29
-
30
- # Create avatar URLs with base64 data
31
- user_avatar = f"data:image/png;base64,{user_logo_base64}" if user_logo_base64 else "πŸ‘€"
32
- assistant_avatar = f"data:image/png;base64,{assistant_logo_base64}" if assistant_logo_base64 else "πŸ€–"
33
-
34
- return user_avatar, assistant_avatar
35
-
36
-
37
- def initialize_session_state():
38
- """Initialize all necessary session state variables."""
39
- import uuid
40
- from datetime import datetime
41
-
42
- if 'history' not in st.session_state:
43
- st.session_state.history = []
44
- if 'consultation_id' not in st.session_state:
45
- st.session_state.consultation_id = str(uuid.uuid4())[:8]
46
- if 'use_rag' not in st.session_state:
47
- st.session_state.use_rag = True
48
- if 'processing' not in st.session_state:
49
- st.session_state.processing = False
50
- if 'show_report_form' not in st.session_state:
51
- st.session_state.show_report_form = False
52
- if 'report_step' not in st.session_state:
53
- st.session_state.report_step = 0
54
- if 'patient_info' not in st.session_state:
55
- st.session_state.patient_info = {"name": "", "age": "", "gender": ""}
56
- if 'pdf_data' not in st.session_state:
57
- st.session_state.pdf_data = None
58
- if 'show_email_form' not in st.session_state:
59
- st.session_state.show_email_form = False
60
-
61
-
62
- def display_chat_history(history, user_avatar, assistant_avatar):
63
- """Display the chat history with proper formatting."""
64
- from text_processors import remove_reasoning_and_sources, has_meaningful_content, clean_explanation
65
-
66
- for message in history:
67
- if message["role"] == "user":
68
- # Right-aligned container for user messages
69
- with st.container():
70
- col1, col2 = st.columns([2, 10])
71
- with col2:
72
- with st.chat_message("user", avatar=user_avatar):
73
- st.write(message["content"])
74
- else:
75
- # Left-aligned container for assistant messages
76
- with st.container():
77
- col1, col2 = st.columns([10, 2])
78
- with col1:
79
- with st.chat_message("assistant", avatar=assistant_avatar):
80
- # Display the response text without reasoning or sources sections
81
- cleaned_response = remove_reasoning_and_sources(message["content"])
82
- st.markdown(cleaned_response)
83
-
84
- # Only display the explanation in an expander if it exists AND has actual content
85
- if message.get("explanation") and has_meaningful_content(message.get("explanation")):
86
- # Clean up the explanation text
87
- cleaned_explanation = clean_explanation(message["explanation"])
88
-
89
- with st.expander("Show Reasoning"):
90
- st.markdown(cleaned_explanation)
91
- if message.get("evidence"):
92
- st.markdown("---")
93
- st.markdown("**Legend:** πŸ”“ = Open Access (full text available)")
94
-
95
-
96
- def display_typing_indicator(assistant_avatar):
97
- """Display a typing indicator while processing a response."""
98
- from styles import get_typing_indicator_html
99
-
100
- with st.container():
101
- col1, col2 = st.columns([10, 2])
102
- with col1:
103
- with st.chat_message("assistant", avatar=assistant_avatar):
104
- st.markdown(get_typing_indicator_html(), unsafe_allow_html=True)