Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files
.hfignore
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Ignore Python cache and virtual environments
|
| 2 |
+
__pycache__/
|
| 3 |
+
*.pyc
|
| 4 |
+
*.pyo
|
| 5 |
+
*.pyd
|
| 6 |
+
.venv/
|
| 7 |
+
venv/
|
| 8 |
+
env/
|
| 9 |
+
ENV/
|
| 10 |
+
bkp/
|
| 11 |
+
|
| 12 |
+
# Ignore notebooks checkpoints
|
| 13 |
+
.ipynb_checkpoints/
|
| 14 |
+
|
| 15 |
+
# Ignore system files
|
| 16 |
+
.DS_Store
|
| 17 |
+
Thumbs.db
|
| 18 |
+
|
| 19 |
+
# Ignore logs and temp files
|
| 20 |
+
*.log
|
| 21 |
+
*.tmp
|
| 22 |
+
*.bak
|
| 23 |
+
|
| 24 |
+
# Ignore environment and secret files
|
| 25 |
+
.env
|
| 26 |
+
*.env
|
| 27 |
+
.env.*
|
| 28 |
+
secrets.json
|
| 29 |
+
config.json
|
| 30 |
+
|
| 31 |
+
# Ignore build artifacts
|
| 32 |
+
dist/
|
| 33 |
+
build/
|
| 34 |
+
*.egg-info/
|
| 35 |
+
|
| 36 |
+
# Ignore datasets or large local data files
|
| 37 |
+
data/
|
| 38 |
+
*.csv
|
| 39 |
+
*.tsv
|
| 40 |
+
*.xlsx
|
| 41 |
+
*.parquet
|
| 42 |
+
|
| 43 |
+
# Ignore tests and docs (optional)
|
| 44 |
+
tests/
|
| 45 |
+
docs/
|
| 46 |
+
|
| 47 |
+
# Ignore Git folders
|
| 48 |
+
.git/
|
| 49 |
+
.gitignore
|
| 50 |
+
|
| 51 |
+
# Hugging Face specific
|
| 52 |
+
.hf_cache/
|
| 53 |
+
output/
|
README.md
CHANGED
|
@@ -1,14 +1,29 @@
|
|
| 1 |
---
|
| 2 |
-
title: Trip Advisor App
|
| 3 |
-
emoji:
|
| 4 |
colorFrom: blue
|
| 5 |
colorTo: green
|
| 6 |
sdk: gradio
|
| 7 |
-
|
| 8 |
-
|
|
|
|
|
|
|
| 9 |
pinned: false
|
|
|
|
| 10 |
license: mit
|
| 11 |
-
short_description: trip-advisor-app
|
| 12 |
---
|
| 13 |
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
title: AI Trip Advisor App
|
| 3 |
+
emoji: π
|
| 4 |
colorFrom: blue
|
| 5 |
colorTo: green
|
| 6 |
sdk: gradio
|
| 7 |
+
app_port: 7860
|
| 8 |
+
tags:
|
| 9 |
+
- gradio
|
| 10 |
+
- chat
|
| 11 |
pinned: false
|
| 12 |
+
short_description: AI-powered travel planning assistant
|
| 13 |
license: mit
|
|
|
|
| 14 |
---
|
| 15 |
|
| 16 |
+
# AI Trip Advisor App
|
| 17 |
+
|
| 18 |
+
An interactive chat interface built with Gradio that connects to the `AI Trip Planner API`, providing intelligent travel planning through a langgraph agentic solution.
|
| 19 |
+
|
| 20 |
+
## Features
|
| 21 |
+
- π€ Chat-based interface for natural interaction
|
| 22 |
+
- πΊοΈ Detailed trip planning and itinerary generation
|
| 23 |
+
- π Markdown-formatted responses
|
| 24 |
+
- π Real-time API integration
|
| 25 |
+
|
| 26 |
+
## Technical Stack
|
| 27 |
+
- Frontend: Gradio 4.44.1+
|
| 28 |
+
- Backend: FastAPI with Langgraph
|
| 29 |
+
- Deployment: Hugging Face Spaces
|
app.py
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import requests
|
| 3 |
+
import datetime
|
| 4 |
+
import os
|
| 5 |
+
from dotenv import load_dotenv
|
| 6 |
+
|
| 7 |
+
# Load environment variables
|
| 8 |
+
load_dotenv()
|
| 9 |
+
|
| 10 |
+
# Backend endpoint - use environment variable or default to Hugging Face
|
| 11 |
+
BASE_URL = os.getenv("API_BASE_URL", "https://mishrabp-trip-advisor-api.hf.space")
|
| 12 |
+
|
| 13 |
+
def format_travel_plan(answer):
|
| 14 |
+
"""Format the travel plan response with markdown styling"""
|
| 15 |
+
return f"""### πΊοΈ AI-Generated Travel Plan
|
| 16 |
+
**Generated:** {datetime.datetime.now().strftime('%Y-%m-%d at %H:%M')}
|
| 17 |
+
**Created by:** Kube9t's Travel Agent
|
| 18 |
+
|
| 19 |
+
---
|
| 20 |
+
|
| 21 |
+
{answer}
|
| 22 |
+
|
| 23 |
+
---
|
| 24 |
+
|
| 25 |
+
π *Please double-check all travel details, costs, and dates before booking.*"""
|
| 26 |
+
|
| 27 |
+
def query_travel_agent(message, history):
|
| 28 |
+
"""Handle the travel agent query and format the response"""
|
| 29 |
+
try:
|
| 30 |
+
# Make API request
|
| 31 |
+
payload = {"question": message}
|
| 32 |
+
response = requests.post(f"{BASE_URL}/query", json=payload)
|
| 33 |
+
|
| 34 |
+
if response.status_code == 200:
|
| 35 |
+
answer = response.json().get("answer", "No answer returned.")
|
| 36 |
+
formatted_response = {
|
| 37 |
+
"role": "assistant",
|
| 38 |
+
"content": format_travel_plan(answer)
|
| 39 |
+
}
|
| 40 |
+
else:
|
| 41 |
+
formatted_response = {
|
| 42 |
+
"role": "assistant",
|
| 43 |
+
"content": f"β Bot failed to respond: {response.text}"
|
| 44 |
+
}
|
| 45 |
+
except Exception as e:
|
| 46 |
+
formatted_response = {
|
| 47 |
+
"role": "assistant",
|
| 48 |
+
"content": f"β οΈ Something went wrong: {str(e)}"
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
# Return updated history
|
| 52 |
+
return history + [
|
| 53 |
+
{"role": "user", "content": message},
|
| 54 |
+
formatted_response
|
| 55 |
+
]
|
| 56 |
+
|
| 57 |
+
def create_demo():
|
| 58 |
+
"""Create and configure the Gradio interface"""
|
| 59 |
+
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
| 60 |
+
# Header
|
| 61 |
+
gr.Markdown(
|
| 62 |
+
"""
|
| 63 |
+
# π Travel Planner Agentic Application
|
| 64 |
+
Let me help you design your next perfect trip β just tell me where you want to go!
|
| 65 |
+
"""
|
| 66 |
+
)
|
| 67 |
+
|
| 68 |
+
with gr.Row():
|
| 69 |
+
# Sidebar
|
| 70 |
+
with gr.Column(scale=1):
|
| 71 |
+
gr.Image(
|
| 72 |
+
"https://cdn-icons-png.flaticon.com/512/201/201623.png",
|
| 73 |
+
width=80,
|
| 74 |
+
show_label=False
|
| 75 |
+
)
|
| 76 |
+
gr.Markdown("### Navigation")
|
| 77 |
+
gr.Markdown("- π Home\n- π§³ My Trips\n- βοΈ Settings")
|
| 78 |
+
gr.Markdown("---")
|
| 79 |
+
gr.Markdown("*Powered by Kube9t's Travel Agent AI*")
|
| 80 |
+
|
| 81 |
+
# Main chat interface
|
| 82 |
+
with gr.Column(scale=3):
|
| 83 |
+
chatbot = gr.Chatbot(
|
| 84 |
+
height=400,
|
| 85 |
+
show_label=False,
|
| 86 |
+
avatar_images=["π€", "π€"],
|
| 87 |
+
type="messages" # Use new message format
|
| 88 |
+
)
|
| 89 |
+
msg = gr.Textbox(
|
| 90 |
+
label="Ask me something like: 'Plan a 7 days trip to Washington-DC, NewYork, and Niagra.'",
|
| 91 |
+
placeholder="Type your travel query here...",
|
| 92 |
+
lines=2
|
| 93 |
+
)
|
| 94 |
+
with gr.Row():
|
| 95 |
+
submit = gr.Button("Send", variant="primary")
|
| 96 |
+
clear = gr.Button("Clear")
|
| 97 |
+
|
| 98 |
+
# Event handlers
|
| 99 |
+
msg.submit(
|
| 100 |
+
fn=query_travel_agent,
|
| 101 |
+
inputs=[msg, chatbot],
|
| 102 |
+
outputs=chatbot
|
| 103 |
+
).then(
|
| 104 |
+
fn=lambda: "",
|
| 105 |
+
outputs=msg
|
| 106 |
+
)
|
| 107 |
+
|
| 108 |
+
submit.click(
|
| 109 |
+
fn=query_travel_agent,
|
| 110 |
+
inputs=[msg, chatbot],
|
| 111 |
+
outputs=chatbot
|
| 112 |
+
).then(
|
| 113 |
+
fn=lambda: "",
|
| 114 |
+
outputs=msg
|
| 115 |
+
)
|
| 116 |
+
|
| 117 |
+
clear.click(lambda: [], outputs=chatbot)
|
| 118 |
+
|
| 119 |
+
return demo
|
| 120 |
+
|
| 121 |
+
# Create and launch the app
|
| 122 |
+
app = create_demo()
|
| 123 |
+
|
| 124 |
+
if __name__ == "__main__":
|
| 125 |
+
# Determine if running locally
|
| 126 |
+
is_local = os.getenv("RUNNING_LOCAL", "false").lower() == "true"
|
| 127 |
+
|
| 128 |
+
# Launch with appropriate settings
|
| 129 |
+
if is_local:
|
| 130 |
+
app.launch(
|
| 131 |
+
server_name="127.0.0.1",
|
| 132 |
+
server_port=7860,
|
| 133 |
+
share=False
|
| 134 |
+
)
|
| 135 |
+
else:
|
| 136 |
+
app.launch()
|