Update app.py
Browse files
app.py
CHANGED
|
@@ -966,6 +966,7 @@ elif st.session_state.step == 2:
|
|
| 966 |
|
| 967 |
st.markdown('<div class="label-soft">Speak (optional)</div>', unsafe_allow_html=True)
|
| 968 |
|
|
|
|
| 969 |
audio_bytes = audio_recorder(
|
| 970 |
text="Tap to record",
|
| 971 |
recording_color="#ef4444",
|
|
@@ -974,6 +975,7 @@ elif st.session_state.step == 2:
|
|
| 974 |
icon_size="1.3x",
|
| 975 |
)
|
| 976 |
|
|
|
|
| 977 |
if audio_bytes:
|
| 978 |
st.session_state.audio_bytes = audio_bytes
|
| 979 |
if st.session_state.last_audio != audio_bytes:
|
|
@@ -983,6 +985,7 @@ elif st.session_state.step == 2:
|
|
| 983 |
st.session_state.user_text = transcript
|
| 984 |
st.session_state.last_audio = audio_bytes
|
| 985 |
|
|
|
|
| 986 |
user_text = st.text_area(
|
| 987 |
"Or type / edit your description here",
|
| 988 |
value=st.session_state.user_text,
|
|
@@ -996,57 +999,73 @@ elif st.session_state.step == 2:
|
|
| 996 |
unsafe_allow_html=True,
|
| 997 |
)
|
| 998 |
|
|
|
|
| 999 |
col1, col2 = st.columns(2)
|
| 1000 |
with col1:
|
| 1001 |
-
|
| 1002 |
-
|
| 1003 |
-
|
|
|
|
|
|
|
| 1004 |
with col2:
|
| 1005 |
-
|
| 1006 |
-
|
| 1007 |
-
|
| 1008 |
-
|
|
|
|
| 1009 |
|
| 1010 |
-
|
| 1011 |
-
|
|
|
|
|
|
|
| 1012 |
|
| 1013 |
-
|
| 1014 |
-
|
| 1015 |
-
|
|
|
|
|
|
|
|
|
|
| 1016 |
|
| 1017 |
-
|
| 1018 |
-
|
| 1019 |
-
if combined_for_drugs
|
| 1020 |
-
else "No medication context."
|
| 1021 |
-
)
|
| 1022 |
-
recalls_context = tool_get_recent_recalls_snippet()
|
| 1023 |
-
wait_awareness_context = tool_get_wait_times_awareness()
|
| 1024 |
-
|
| 1025 |
-
if city_label:
|
| 1026 |
-
facilities_context = tool_list_facilities_places(city_label)
|
| 1027 |
-
region_context = tool_region_context_city(city_label)
|
| 1028 |
-
hqontario_context = tool_hqontario_context_city(city_label)
|
| 1029 |
-
else:
|
| 1030 |
-
facilities_context = "No city selected; cannot list local facilities."
|
| 1031 |
-
region_context = "No city selected; use Canada-wide guidance."
|
| 1032 |
-
hqontario_context = ""
|
| 1033 |
-
|
| 1034 |
-
final_answer = call_reasoning_agent(
|
| 1035 |
-
narrative=narrative_text,
|
| 1036 |
-
vision_summary=vision_summary,
|
| 1037 |
-
city_label=city_label,
|
| 1038 |
-
dpd_context=dpd_context,
|
| 1039 |
-
recalls_context=recalls_context,
|
| 1040 |
-
wait_awareness_context=wait_awareness_context,
|
| 1041 |
-
region_context=region_context,
|
| 1042 |
-
facilities_context=facilities_context,
|
| 1043 |
-
hqontario_context=hqontario_context,
|
| 1044 |
-
)
|
| 1045 |
|
| 1046 |
-
|
|
|
|
|
|
|
| 1047 |
|
| 1048 |
-
|
| 1049 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1050 |
|
| 1051 |
st.markdown("</div>", unsafe_allow_html=True)
|
| 1052 |
|
|
|
|
| 966 |
|
| 967 |
st.markdown('<div class="label-soft">Speak (optional)</div>', unsafe_allow_html=True)
|
| 968 |
|
| 969 |
+
# Mic recorder
|
| 970 |
audio_bytes = audio_recorder(
|
| 971 |
text="Tap to record",
|
| 972 |
recording_color="#ef4444",
|
|
|
|
| 975 |
icon_size="1.3x",
|
| 976 |
)
|
| 977 |
|
| 978 |
+
# If new audio, send to Whisper + fill textarea
|
| 979 |
if audio_bytes:
|
| 980 |
st.session_state.audio_bytes = audio_bytes
|
| 981 |
if st.session_state.last_audio != audio_bytes:
|
|
|
|
| 985 |
st.session_state.user_text = transcript
|
| 986 |
st.session_state.last_audio = audio_bytes
|
| 987 |
|
| 988 |
+
# Text area (shows transcript or manual input)
|
| 989 |
user_text = st.text_area(
|
| 990 |
"Or type / edit your description here",
|
| 991 |
value=st.session_state.user_text,
|
|
|
|
| 999 |
unsafe_allow_html=True,
|
| 1000 |
)
|
| 1001 |
|
| 1002 |
+
# Buttons: defined once
|
| 1003 |
col1, col2 = st.columns(2)
|
| 1004 |
with col1:
|
| 1005 |
+
back_clicked = st.button(
|
| 1006 |
+
"Back",
|
| 1007 |
+
use_container_width=True,
|
| 1008 |
+
key="step2_back",
|
| 1009 |
+
)
|
| 1010 |
with col2:
|
| 1011 |
+
go_clicked = st.button(
|
| 1012 |
+
"Get my recommendation",
|
| 1013 |
+
use_container_width=True,
|
| 1014 |
+
key="step2_go",
|
| 1015 |
+
)
|
| 1016 |
|
| 1017 |
+
# Handle Back
|
| 1018 |
+
if back_clicked:
|
| 1019 |
+
go_to_step(1)
|
| 1020 |
+
st.rerun()
|
| 1021 |
|
| 1022 |
+
# Handle Get my recommendation
|
| 1023 |
+
if go_clicked:
|
| 1024 |
+
spinner_placeholder = st.empty()
|
| 1025 |
+
with spinner_placeholder, st.spinner("Analyzing your photo, your description, and local options..."):
|
| 1026 |
+
image_bytes = st.session_state.image_bytes
|
| 1027 |
+
city_label = (st.session_state.city_label or "").strip()
|
| 1028 |
|
| 1029 |
+
vision_summary = call_vision_summarizer(image_bytes) if image_bytes else ""
|
| 1030 |
+
narrative_text = st.session_state.user_text.strip()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1031 |
|
| 1032 |
+
combined_for_drugs = " ".join(
|
| 1033 |
+
x for x in [narrative_text, vision_summary] if x
|
| 1034 |
+
)
|
| 1035 |
|
| 1036 |
+
dpd_context = (
|
| 1037 |
+
tool_lookup_drug_products(combined_for_drugs)
|
| 1038 |
+
if combined_for_drugs
|
| 1039 |
+
else "No medication context."
|
| 1040 |
+
)
|
| 1041 |
+
recalls_context = tool_get_recent_recalls_snippet()
|
| 1042 |
+
wait_awareness_context = tool_get_wait_times_awareness()
|
| 1043 |
+
|
| 1044 |
+
if city_label:
|
| 1045 |
+
facilities_context = tool_list_facilities_places(city_label)
|
| 1046 |
+
region_context = tool_region_context_city(city_label)
|
| 1047 |
+
hqontario_context = tool_hqontario_context_city(city_label)
|
| 1048 |
+
else:
|
| 1049 |
+
facilities_context = "No city selected; cannot list local facilities."
|
| 1050 |
+
region_context = "No city selected; use Canada-wide guidance."
|
| 1051 |
+
hqontario_context = ""
|
| 1052 |
+
|
| 1053 |
+
final_answer = call_reasoning_agent(
|
| 1054 |
+
narrative=narrative_text,
|
| 1055 |
+
vision_summary=vision_summary,
|
| 1056 |
+
city_label=city_label,
|
| 1057 |
+
dpd_context=dpd_context,
|
| 1058 |
+
recalls_context=recalls_context,
|
| 1059 |
+
wait_awareness_context=wait_awareness_context,
|
| 1060 |
+
region_context=region_context,
|
| 1061 |
+
facilities_context=facilities_context,
|
| 1062 |
+
hqontario_context=hqontario_context,
|
| 1063 |
+
)
|
| 1064 |
+
|
| 1065 |
+
st.session_state.final_answer = final_answer
|
| 1066 |
+
|
| 1067 |
+
go_to_step(3)
|
| 1068 |
+
st.rerun()
|
| 1069 |
|
| 1070 |
st.markdown("</div>", unsafe_allow_html=True)
|
| 1071 |
|