Spaces:
Runtime error
Runtime error
| # app.py | |
| import streamlit as st | |
| from travel_logic import get_price_ranges, get_mode_options, get_live_buses, get_random_travel_suggestion, save, get_pune_bus_fare, get_route_map | |
| from langchain_core.tools import tool | |
| st.set_page_config(page_title="π§³ Travel Assistant", layout="centered") | |
| st.title("π§ AI Travel Assistant") | |
| # Initialize session state | |
| if "history" not in st.session_state: | |
| st.session_state.history = [] | |
| if "source" not in st.session_state: | |
| st.session_state.source = "" | |
| if "destination" not in st.session_state: | |
| st.session_state.destination = "" | |
| if "mode" not in st.session_state: | |
| st.session_state.mode = "" | |
| with st.form("travel_form"): | |
| st.subheader("Enter your travel details:") | |
| source = st.text_input("Source City", value=st.session_state.source) | |
| destination = st.text_input("Destination City", value=st.session_state.destination) | |
| mode = st.selectbox("Mode of Travel", ["bus", "train", "flight"], index=0) | |
| submitted = st.form_submit_button("Get Travel Options") | |
| if submitted: | |
| st.session_state.source = source | |
| st.session_state.destination = destination | |
| st.session_state.mode = mode | |
| # Normalize source/destination for consistency | |
| normalized_src = source.strip().lower() | |
| normalized_dst = destination.strip().lower() | |
| # Call Pune fare function first | |
| pune_response = get_pune_bus_fare(normalized_src, normalized_dst) | |
| # Check if PMPML data exists for this route | |
| if "No PMPML route found" not in pune_response and mode.lower() == "bus": | |
| st.session_state.history.append(("π Pune Bus Fare", pune_response)) | |
| else: | |
| # Fall back to general travel info | |
| price_info = get_price_ranges(source, destination) | |
| mode_info = get_mode_options(source, destination, mode) | |
| st.session_state.history.append(("π€", price_info)) | |
| st.session_state.history.append(("π€", mode_info)) | |
| # if submitted: | |
| # st.session_state.source = source | |
| # st.session_state.destination = destination | |
| # st.session_state.mode = mode | |
| # # Get responses | |
| # price_info = get_price_ranges(source, destination) | |
| # mode_info = get_mode_options(source, destination, mode) | |
| # st.session_state.history.append(("π€", price_info)) | |
| # st.session_state.history.append(("π€", mode_info)) | |
| # Display Chat History | |
| st.subheader("π¬ Assistant Response") | |
| for role, msg in st.session_state.history: | |
| st.markdown(f"**{role}**: {msg}") | |
| # pune_response = get_pune_bus_fare(source, destination) | |
| # if "No PMPML route found" not in pune_response: | |
| # st.session_state.history.append(("π Pune Bus Fare", pune_response)) | |
| # Then continue with general travel suggestions | |
| # price_info = get_price_ranges(source, destination) | |
| # mode_info = get_mode_options(source, destination, mode) | |
| # st.session_state.history.append(("π€", price_info)) | |
| # st.session_state.history.append(("π€", mode_info)) | |
| # Buttons for extra tools | |
| # st.markdown("---") | |
| # col1, col2, col3 = st.columns(3) | |
| # with col1: | |
| # if st.button("π Live Buses"): | |
| # buses = get_live_buses(st.session_state.source, st.session_state.destination) | |
| # st.session_state.history.append(("π Live Buses", buses)) | |
| # with col2: | |
| # if st.button("π Travel Tip"): | |
| # tip = get_random_travel_suggestion() | |
| # st.session_state.history.append(("π Travel Tip", tip)) | |
| # with col3: | |
| # if st.button("πΎ Save Session"): | |
| # filename = f"{st.session_state.source}_to_{st.session_state.destination}_session" | |
| # result = save(filename, st.session_state.history) # pass history as argument | |
| # st.success(result) | |
| if submitted: | |
| st.write(f"π Looking up options for: {source} β {destination}, mode: {mode}") | |