File size: 1,480 Bytes
53f5d13
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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()