Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files- streamlit_app.py +83 -0
streamlit_app.py
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import requests
|
| 3 |
+
import datetime
|
| 4 |
+
|
| 5 |
+
BASE_URL = "https://mishrabp-trip-advisor-api.hf.space/" # Backend endpoint
|
| 6 |
+
|
| 7 |
+
# Set up Streamlit page configuration
|
| 8 |
+
st.set_page_config(
|
| 9 |
+
page_title="Travel Planner Agentic Application",
|
| 10 |
+
page_icon="π",
|
| 11 |
+
layout="wide",
|
| 12 |
+
initial_sidebar_state="expanded",
|
| 13 |
+
)
|
| 14 |
+
|
| 15 |
+
# ---------------------------
|
| 16 |
+
# Sidebar Navigation
|
| 17 |
+
# ---------------------------
|
| 18 |
+
with st.sidebar:
|
| 19 |
+
st.image("https://cdn-icons-png.flaticon.com/512/201/201623.png", width=80)
|
| 20 |
+
st.title("π Travel Planner")
|
| 21 |
+
st.markdown("Plan your trips effortlessly with AI βοΈ")
|
| 22 |
+
st.markdown("---")
|
| 23 |
+
st.subheader("Navigation")
|
| 24 |
+
st.page_link("https://openai.com", label="π Home", disabled=True)
|
| 25 |
+
st.page_link("https://openai.com", label="π§³ My Trips", disabled=True)
|
| 26 |
+
st.page_link("https://openai.com", label="βοΈ Settings", disabled=True)
|
| 27 |
+
st.markdown("---")
|
| 28 |
+
st.caption("Powered by Kube9t's Travel Agent AI")
|
| 29 |
+
|
| 30 |
+
# ---------------------------
|
| 31 |
+
# Hero Section
|
| 32 |
+
# ---------------------------
|
| 33 |
+
st.markdown(
|
| 34 |
+
"""
|
| 35 |
+
<div style="background-color:#0c2a45; padding:2rem 1rem; border-radius:10px;">
|
| 36 |
+
<h1 style="color:white; text-align:center;">π Travel Planner Agentic Application</h1>
|
| 37 |
+
<p style="color:white; text-align:center; font-size:1.2rem;">
|
| 38 |
+
Let me help you design your next perfect trip β just tell me where you want to go!
|
| 39 |
+
</p>
|
| 40 |
+
</div>
|
| 41 |
+
""",
|
| 42 |
+
unsafe_allow_html=True
|
| 43 |
+
)
|
| 44 |
+
|
| 45 |
+
st.markdown("### β¨ What can I help you plan today?")
|
| 46 |
+
|
| 47 |
+
# Initialize chat history
|
| 48 |
+
if "messages" not in st.session_state:
|
| 49 |
+
st.session_state.messages = []
|
| 50 |
+
|
| 51 |
+
# Chat input form
|
| 52 |
+
with st.form(key="query_form", clear_on_submit=True):
|
| 53 |
+
user_input = st.text_input("Ask me something like: 'Plan a 7 days trip to Washnigton-DC, NewYork, and Niagra.'")
|
| 54 |
+
submit_button = st.form_submit_button("Send")
|
| 55 |
+
|
| 56 |
+
# Handle form submission
|
| 57 |
+
if submit_button and user_input.strip():
|
| 58 |
+
try:
|
| 59 |
+
with st.spinner("π§ Thinking..."):
|
| 60 |
+
payload = {"question": user_input}
|
| 61 |
+
response = requests.post(f"{BASE_URL}/query", json=payload)
|
| 62 |
+
|
| 63 |
+
if response.status_code == 200:
|
| 64 |
+
answer = response.json().get("answer", "No answer returned.")
|
| 65 |
+
markdown_content = f"""
|
| 66 |
+
### πΊοΈ AI-Generated Travel Plan
|
| 67 |
+
**Generated:** {datetime.datetime.now().strftime('%Y-%m-%d at %H:%M')}
|
| 68 |
+
**Created by:** Kube9t's Travel Agent
|
| 69 |
+
|
| 70 |
+
---
|
| 71 |
+
|
| 72 |
+
{answer}
|
| 73 |
+
|
| 74 |
+
---
|
| 75 |
+
|
| 76 |
+
π *Please double-check all travel details, costs, and dates before booking.*
|
| 77 |
+
"""
|
| 78 |
+
st.markdown(markdown_content)
|
| 79 |
+
else:
|
| 80 |
+
st.error("β Bot failed to respond: " + response.text)
|
| 81 |
+
|
| 82 |
+
except Exception as e:
|
| 83 |
+
st.error(f"β οΈ Something went wrong: {e}")
|