import os import requests import gradio as gr API_KEY = os.environ.get("GEMINI_API_KEY", "") MODEL = "gemini-2.5-flash-lite" def make_itinerary(destination, days, start_date, budget, travelers, interests, transport, pace): if not API_KEY: return ( "### Setup needed\n" "Add your Gemini API key as a secret named " "`GEMINI_API_KEY` in your Space Settings." ) if not destination.strip(): return "Please enter a destination." prompt = f""" You are a helpful travel itinerary planner. Create a practical, personalized itinerary for: Destination: {destination} Duration: {days} days Start date: {start_date or 'Dates not specified'} Total budget: {budget} Number of travellers: {travelers} Interests: {interests} Preferred transport: {transport} Travel pace: {pace} Include: 1. A short overview and suggested route. 2. A day-by-day schedule with morning, afternoon and evening. 3. Suggested visit order to reduce unnecessary travel. 4. Estimated local travel, food and activity costs. 5. Suggested areas to stay and local food to try. 6. Practical transport guidance and booking tips. 7. A realistic total estimated budget in INR. 8. Useful safety, weather and packing advice. State assumptions clearly. Do not invent confirmed bookings, live prices, opening hours or transport schedules. Tell the traveller to verify current details before departure. If the budget is insufficient, explain how to adjust the plan. Use readable headings and tables where helpful. """ url = ( "https://generativelanguage.googleapis.com/v1beta/" f"models/{MODEL}:generateContent" ) try: response = requests.post( url, params={"key": API_KEY}, json={ "contents": [{ "parts": [{"text": prompt}] }] }, timeout=90 ) if response.status_code != 200: return ( "AI request failed. Check your API key and free-tier " "quota in Google AI Studio. No paid billing is required " "for this app; do not enable billing to fix the error." ) data = response.json() return data["candidates"][0]["content"]["parts"][0]["text"] except Exception: return "Unable to get a response. Please try again." with gr.Blocks(theme=gr.themes.Soft(), title="TripWise AI") as app: gr.Markdown( "# ✈️ TripWise AI\n" "### Your personal AI travel planner\n" "Enter a destination and get a personalized travel schedule." ) with gr.Row(): destination = gr.Textbox( label="Where do you want to go?", placeholder="e.g. Sri Lanka, Goa, Paris" ) days = gr.Dropdown( choices=[str(i) for i in range(1, 16)], value="4", label="Trip duration (days)" ) with gr.Row(): start_date = gr.Textbox( label="Start date (optional)", placeholder="e.g. 23 October 2026" ) budget = gr.Dropdown( choices=[ "Budget: under ₹10,000", "₹10,000–₹25,000", "₹25,000–₹50,000", "₹50,000–₹1,00,000", "Flexible budget" ], value="₹25,000–₹50,000", label="Total budget for the trip" ) travelers = gr.Dropdown( choices=["1", "2", "3", "4", "5", "6+"], value="2", label="Number of travellers" ) interests = gr.CheckboxGroup( choices=[ "Beaches", "Nature", "Mountains", "History", "Food and cafés", "Shopping", "Nightlife", "Adventure", "Culture", "Family activities" ], value=["Nature", "Food and cafés"], label="What do you enjoy?" ) transport = gr.Radio( choices=["Public transport", "Taxi", "Rental car/bike", "Mixed transport"], value="Mixed transport", label="Preferred transport" ) pace = gr.Radio( choices=["Relaxed", "Balanced", "Packed schedule"], value="Balanced", label="Travel pace" ) generate = gr.Button("✨ Generate My Itinerary", variant="primary") output = gr.Markdown() generate.click( fn=make_itinerary, inputs=[ destination, days, start_date, budget, travelers, interests, transport, pace ], outputs=output ) app.launch()