TravelAI / app.py
rahul7star's picture
Create app.py
53f5d13 verified
import gradio as gr
def generate_itinerary(destination, days, interests):
"""
Generate a travel itinerary using GPT-2 from Hugging Face.
"""
prompt = (f"Create a {days}-day travel itinerary for {destination}. "
f"Focus on activities related to {', '.join(interests)}. "
"Include a list of daily activities, landmarks, restaurants, and other travel suggestions.")
# Generate itinerary using GPT-2
itinerary = generator(prompt, max_length=300, num_return_sequences=1)
# Return the generated text
return itinerary[0]['generated_text'].strip()
def ai_travel_agent(destination, days, interests):
"""
Process user input and generate a travel itinerary.
"""
interests_list = interests.split(",") # Convert comma-separated string to list
return generate_itinerary(destination, days, interests_list)
# Create the Gradio interface
interface = gr.Interface(
fn=ai_travel_agent,
inputs=[
gr.Textbox(label="Destination", placeholder="Enter a city or country"),
gr.Slider(label="Number of Days", minimum=1, maximum=14, step=1, value=3),
gr.Textbox(label="Interests", placeholder="E.g., adventure, food, culture")
],
outputs="textbox",
title="AI Travel Itinerary Generator",
description="Plan your next trip with AI! Enter your destination, duration, and interests, and get a personalized travel itinerary."
)
# Launch the interface
interface.launch()