Spaces:
Sleeping
Sleeping
pleabargain
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -1,8 +1,55 @@
|
|
1 |
import gradio as gr
|
2 |
from huggingface_hub import InferenceClient
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
|
4 |
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
def generate_itinerary(
|
7 |
destination: str,
|
8 |
origin: str,
|
@@ -14,21 +61,37 @@ def generate_itinerary(
|
|
14 |
temperature: float,
|
15 |
top_p: float,
|
16 |
) -> str:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
# Construct a detailed prompt for the AI
|
18 |
-
prompt = f"""
|
19 |
- From: {origin}
|
20 |
- To: {destination}
|
21 |
-
- Budget: ${budget}
|
22 |
- Type of Holiday: {holiday_type}
|
23 |
|
24 |
-
|
25 |
-
|
26 |
-
2. Estimated costs for activities
|
27 |
-
3. Suggested accommodations within budget
|
28 |
-
4. Local transportation tips
|
29 |
-
5. Must-try local food recommendations
|
30 |
|
31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
|
33 |
messages = [
|
34 |
{"role": "system", "content": system_message},
|
@@ -49,15 +112,15 @@ def generate_itinerary(
|
|
49 |
yield response
|
50 |
|
51 |
# Create the Gradio interface
|
52 |
-
with gr.Blocks() as demo:
|
53 |
-
gr.Markdown("# AI Travel Itinerary Generator
|
54 |
-
gr.Markdown("Enter your travel details below to get a customized itinerary!")
|
55 |
|
56 |
with gr.Row():
|
57 |
with gr.Column():
|
58 |
origin = gr.Textbox(label="Starting Location", placeholder="e.g., New York, USA")
|
59 |
destination = gr.Textbox(label="Destination", placeholder="e.g., Paris, France")
|
60 |
-
budget = gr.Slider(minimum=500, maximum=10000, value=2000, step=100, label="Budget (USD)")
|
61 |
num_days = gr.Slider(minimum=1, maximum=14, value=3, step=1, label="Number of Days")
|
62 |
holiday_type = gr.Dropdown(
|
63 |
choices=[
|
@@ -69,20 +132,39 @@ with gr.Blocks() as demo:
|
|
69 |
"Luxury & High-End",
|
70 |
"Family-Friendly",
|
71 |
],
|
72 |
-
label="Type of Holiday"
|
|
|
73 |
)
|
74 |
|
75 |
with gr.Accordion("Advanced Settings", open=False):
|
76 |
system_message = gr.Textbox(
|
77 |
-
value="You are an experienced travel planner with extensive knowledge of destinations worldwide. Provide detailed, practical, and budget-conscious travel advice.",
|
78 |
-
label="System Message"
|
|
|
79 |
)
|
80 |
max_tokens = gr.Slider(minimum=1, maximum=2048, value=1024, step=1, label="Max Tokens")
|
81 |
temperature = gr.Slider(minimum=0.1, maximum=1.0, value=0.7, step=0.1, label="Temperature")
|
82 |
top_p = gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p")
|
83 |
|
84 |
-
|
85 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
86 |
|
87 |
generate_button.click(
|
88 |
fn=generate_itinerary,
|
|
|
1 |
import gradio as gr
|
2 |
from huggingface_hub import InferenceClient
|
3 |
+
import json
|
4 |
+
|
5 |
+
# Hotel data
|
6 |
+
HOTELS = [
|
7 |
+
{
|
8 |
+
"name": "Azure Haven",
|
9 |
+
"pricingPerDay": 250,
|
10 |
+
"roomTypes": ["Single Room", "Double Room", "Suite"],
|
11 |
+
"description": "Azure Haven is a tranquil getaway offering breathtaking ocean views and luxurious amenities. Ideal for a peaceful escape or a romantic retreat."
|
12 |
+
},
|
13 |
+
{
|
14 |
+
"name": "Golden Sands Resort",
|
15 |
+
"pricingPerDay": 300,
|
16 |
+
"roomTypes": ["Standard Room", "Deluxe Room", "Family Suite"],
|
17 |
+
"description": "Nestled on a pristine beach, Golden Sands Resort is perfect for family vacations and adventure seekers. Enjoy watersports, beachside dining, and more."
|
18 |
+
},
|
19 |
+
{
|
20 |
+
"name": "Mountain Bliss Lodge",
|
21 |
+
"pricingPerDay": 220,
|
22 |
+
"roomTypes": ["Cabin", "Deluxe Cabin", "Mountain Suite"],
|
23 |
+
"description": "Mountain Bliss Lodge offers cozy cabins and stunning mountain views. A perfect destination for nature lovers and outdoor enthusiasts."
|
24 |
+
},
|
25 |
+
{
|
26 |
+
"name": "Urban Oasis Hotel",
|
27 |
+
"pricingPerDay": 280,
|
28 |
+
"roomTypes": ["Single Room", "Double Room", "Executive Suite"],
|
29 |
+
"description": "Located in the heart of the city, Urban Oasis Hotel combines modern luxury with convenient access to top attractions, dining, and entertainment."
|
30 |
+
},
|
31 |
+
{
|
32 |
+
"name": "Lakeside Retreat",
|
33 |
+
"pricingPerDay": 270,
|
34 |
+
"roomTypes": ["Single Room", "Double Room", "Lakeside Suite"],
|
35 |
+
"description": "Lakeside Retreat offers serene lakeside accommodations with a focus on relaxation and rejuvenation. Enjoy spa treatments, boating, and picturesque views."
|
36 |
+
}
|
37 |
+
]
|
38 |
|
39 |
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
40 |
|
41 |
+
def get_suitable_hotels(budget_per_day, holiday_type):
|
42 |
+
suitable_hotels = []
|
43 |
+
for hotel in HOTELS:
|
44 |
+
if hotel["pricingPerDay"] <= budget_per_day:
|
45 |
+
# Match hotel type with holiday preference
|
46 |
+
if (holiday_type == "Relaxation & Wellness" and ("Haven" in hotel["name"] or "Retreat" in hotel["name"])) or \
|
47 |
+
(holiday_type == "Adventure & Outdoor" and ("Mountain" in hotel["name"] or "Sands" in hotel["name"])) or \
|
48 |
+
(holiday_type == "Cultural & Sightseeing" and "Urban" in hotel["name"]) or \
|
49 |
+
(holiday_type == "Family-Friendly" and "Family" in str(hotel["roomTypes"])):
|
50 |
+
suitable_hotels.append(hotel)
|
51 |
+
return suitable_hotels if suitable_hotels else HOTELS
|
52 |
+
|
53 |
def generate_itinerary(
|
54 |
destination: str,
|
55 |
origin: str,
|
|
|
61 |
temperature: float,
|
62 |
top_p: float,
|
63 |
) -> str:
|
64 |
+
# Calculate budget per day (excluding transportation)
|
65 |
+
daily_budget = (budget - (budget * 0.3)) / num_days # Assuming 30% for transportation
|
66 |
+
|
67 |
+
# Get suitable hotels based on budget and holiday type
|
68 |
+
recommended_hotels = get_suitable_hotels(daily_budget * 0.4, holiday_type) # Assuming 40% of daily budget for accommodation
|
69 |
+
|
70 |
+
# Create hotel recommendations string
|
71 |
+
hotel_recommendations = "\n".join([
|
72 |
+
f"- {hotel['name']} (${hotel['pricingPerDay']}/day): {hotel['description']}"
|
73 |
+
for hotel in recommended_hotels[:2] # Recommend top 2 hotels
|
74 |
+
])
|
75 |
+
|
76 |
# Construct a detailed prompt for the AI
|
77 |
+
prompt = f"""Create a detailed {num_days}-day travel itinerary for a trip:
|
78 |
- From: {origin}
|
79 |
- To: {destination}
|
80 |
+
- Total Budget: ${budget} (approximately ${daily_budget:.2f} per day after transportation)
|
81 |
- Type of Holiday: {holiday_type}
|
82 |
|
83 |
+
Consider these recommended accommodations based on the budget and preferences:
|
84 |
+
{hotel_recommendations}
|
|
|
|
|
|
|
|
|
85 |
|
86 |
+
Please include in your itinerary:
|
87 |
+
1. A day-by-day breakdown of activities and sightseeing
|
88 |
+
2. Estimated costs for each activity
|
89 |
+
3. Suggested accommodation from the recommended hotels above
|
90 |
+
4. Local transportation recommendations
|
91 |
+
5. Must-try local food spots and estimated meal costs
|
92 |
+
6. Any money-saving tips
|
93 |
+
|
94 |
+
Format the response with clear day-by-day breakdown and keep track of the budget."""
|
95 |
|
96 |
messages = [
|
97 |
{"role": "system", "content": system_message},
|
|
|
112 |
yield response
|
113 |
|
114 |
# Create the Gradio interface
|
115 |
+
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
116 |
+
gr.Markdown("# 🌎 AI Travel Itinerary Generator ✈️")
|
117 |
+
gr.Markdown("Enter your travel details below to get a customized itinerary with hotel recommendations!")
|
118 |
|
119 |
with gr.Row():
|
120 |
with gr.Column():
|
121 |
origin = gr.Textbox(label="Starting Location", placeholder="e.g., New York, USA")
|
122 |
destination = gr.Textbox(label="Destination", placeholder="e.g., Paris, France")
|
123 |
+
budget = gr.Slider(minimum=500, maximum=10000, value=2000, step=100, label="Total Budget (USD)")
|
124 |
num_days = gr.Slider(minimum=1, maximum=14, value=3, step=1, label="Number of Days")
|
125 |
holiday_type = gr.Dropdown(
|
126 |
choices=[
|
|
|
132 |
"Luxury & High-End",
|
133 |
"Family-Friendly",
|
134 |
],
|
135 |
+
label="Type of Holiday",
|
136 |
+
value="Cultural & Sightseeing"
|
137 |
)
|
138 |
|
139 |
with gr.Accordion("Advanced Settings", open=False):
|
140 |
system_message = gr.Textbox(
|
141 |
+
value="You are an experienced travel planner with extensive knowledge of destinations worldwide. Provide detailed, practical, and budget-conscious travel advice. Always recommend specific activities and keep track of the budget in the itinerary.",
|
142 |
+
label="System Message",
|
143 |
+
lines=3
|
144 |
)
|
145 |
max_tokens = gr.Slider(minimum=1, maximum=2048, value=1024, step=1, label="Max Tokens")
|
146 |
temperature = gr.Slider(minimum=0.1, maximum=1.0, value=0.7, step=0.1, label="Temperature")
|
147 |
top_p = gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p")
|
148 |
|
149 |
+
with gr.Row():
|
150 |
+
with gr.Column():
|
151 |
+
generate_button = gr.Button("Generate Itinerary", variant="primary")
|
152 |
+
output = gr.Textbox(
|
153 |
+
label="Your Custom Itinerary",
|
154 |
+
lines=20,
|
155 |
+
show_copy_button=True
|
156 |
+
)
|
157 |
+
|
158 |
+
# Display available hotels
|
159 |
+
with gr.Accordion("Available Hotels", open=False):
|
160 |
+
hotel_info = "\n\n".join([
|
161 |
+
f"**{hotel['name']}**\n" +
|
162 |
+
f"- Price per day: ${hotel['pricingPerDay']}\n" +
|
163 |
+
f"- Room Types: {', '.join(hotel['roomTypes'])}\n" +
|
164 |
+
f"- {hotel['description']}"
|
165 |
+
for hotel in HOTELS
|
166 |
+
])
|
167 |
+
gr.Markdown(hotel_info)
|
168 |
|
169 |
generate_button.click(
|
170 |
fn=generate_itinerary,
|