Spaces:
Build error
Build error
| # Importing libraries | |
| import streamlit as st | |
| import google.generativeai as genai | |
| # Configuring Gemini API Key | |
| genai.configure(api_key=GEMINI_API_KEY) | |
| # Function to query Gemini API to generate response | |
| def generate_response(prompt): | |
| """Uses Gemini API to generate AI-powered responses.""" | |
| model = genai.GenerativeModel("gemini-2.0-flash") | |
| response = model.generate_content(prompt) | |
| return response.text | |
| # Function to refine and clarify user inputs | |
| def refine_user_inputs(inputs): | |
| """Checks for missing details and asks clarifying questions.""" | |
| missing_fields = [] | |
| # Identify missing inputs | |
| for key, value in inputs.items(): | |
| if not value or value == "Select an option": | |
| missing_fields.append(key) | |
| if missing_fields: | |
| # Generate a dynamic clarification prompt | |
| missing_fields_str = ", ".join(missing_fields) | |
| prompt = f""" | |
| The user has provided incomplete travel details. They have not specified the following: {missing_fields_str}. | |
| Ask clear, user-friendly follow-up questions to fill in these gaps. | |
| """ | |
| return generate_response(prompt) | |
| return "Thank you for providing all details! Proceeding with itinerary generation for required no.of days." | |
| # Function to generate a detailed travel itinerary | |
| def generate_itinerary(user_inputs): | |
| """Creates a structured day-by-day itinerary based on user preferences.""" | |
| prompt = f""" | |
| Generate a **{user_inputs.get('trip_duration')}-day travel itinerary** for {user_inputs.get('destination')}. | |
| Customize it based on: | |
| - Budget: {user_inputs.get('budget')} | |
| - Interests: {user_inputs.get('preferences')} | |
| - Purpose: {user_inputs.get('purpose')} | |
| - Accommodation: {user_inputs.get('accommodation')} | |
| - Transport: {user_inputs.get('transport')} | |
| - Dietary Needs: {user_inputs.get('dietary')} | |
| Ensure the itinerary includes: | |
| - Morning, Afternoon, and Evening Activities | |
| - Top attractions & restaurants | |
| - Relaxation time & hidden gems | |
| - Logical time slots for activities | |
| """ | |
| return generate_response(prompt) | |
| # ๐น Streamlit UI | |
| st.title("AI-Powered Traveler Guide") | |
| st.write("Plan your trip with a personalized AI-generated itinerary!") | |
| # User input fields | |
| destination = st.text_input("Where are you traveling to?") | |
| starting_location = st.text_input("Where are you traveling from?") | |
| budget = st.selectbox("Budget:", ["Select an option", "Low", "Mid-range", "Luxury"]) | |
| trip_duration = st.number_input("Trip Duration (days):", min_value=1, max_value=30, step=1) | |
| travel_dates = st.text_input("Provide me Travel Dates (e.g., Jan 10 - Jan 17):") | |
| purpose = st.selectbox("Trip Purpose:", ["Select an option", "Vacation", "Business", "Adventure", "Honeymoon", "Cultural"]) | |
| preferences = st.multiselect("What interests you?", ["Nature", "Culture", "Food", "Shopping", "Adventure", "History"]) | |
| accommodation = st.selectbox("Accommodation Preference:", ["Select an option", "Luxury Hotel", "Budget Hotel", "Hostel", "Airbnb"]) | |
| transport = st.selectbox("Preferred Transport:", ["Select an option", "Public Transport", "Car Rental", "Walking", "Private Tours"]) | |
| dietary = st.selectbox("Dietary Preferences:", ["Select an option", "No Preference", "Vegetarian", "Vegan", "Non-Vegetarian", "Halal"]) | |
| # Button to generate itinerary | |
| if st.button("Generate Itinerary"): | |
| user_inputs = { | |
| "destination": destination, | |
| "starting_location": starting_location, | |
| "budget": budget, | |
| "trip_duration": trip_duration, | |
| "travel_dates": travel_dates, | |
| "purpose": purpose, | |
| "preferences": ", ".join(preferences) if preferences else "Not specified", | |
| "accommodation": accommodation, | |
| "transport": transport, | |
| "dietary": dietary, | |
| } | |
| # Step 1: Check and clarify missing inputs | |
| st.write("Checking the provided travel details...") | |
| refinement_message = refine_user_inputs(user_inputs) | |
| st.write(refinement_message) | |
| if "Thank you for providing all details!" in refinement_message: | |
| # Step 2: Generate Itinerary | |
| st.write("Creating your AI-powered travel itinerary...") | |
| itinerary = generate_itinerary(user_inputs) | |
| st.write(itinerary) | |
| else: | |
| st.warning("Some details are missing, please provide the missing details before generating the itinerary.") |