File size: 2,208 Bytes
e5d4be3
cb2beda
 
e5d4be3
cb2beda
e5d4be3
 
 
 
 
 
 
 
 
d603dc2
 
 
 
 
 
 
cb2beda
 
 
d603dc2
cb2beda
d603dc2
 
 
 
 
 
 
 
 
 
 
 
 
cb2beda
d603dc2
 
cb2beda
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import os
import gradio as gr
from transformers import pipeline
from huggingface_hub import login

# Get Hugging Face token securely from environment variables
HF_TOKEN = os.getenv("HF_TOKEN")

# Authenticate with Hugging Face
if HF_TOKEN:
    login(HF_TOKEN)
else:
    raise ValueError("🚨 Hugging Face token not found! Please add it to Secrets in your Hugging Face Space.")

# Load AI model (optimized for T4 Small GPU)
chatbot = pipeline(
    "text-generation",
    model="mistralai/Mistral-7B-Instruct-v0.1",
    token=HF_TOKEN,
    device=0  # Runs on GPU
)

def generate_itinerary(destination, start_date, end_date, traveler_type, companion):
    """Generates an AI-powered travel itinerary based on user preferences"""

    prompt = f"""
    You are a professional travel assistant. Create a **day-by-day itinerary** for a trip to {destination}.
    - πŸ“… **Dates**: {start_date} to {end_date}
    - 🎭 **Traveler Type**: {traveler_type}
    - 🧳 **Companion**: {companion}
    - Provide **3 activities per day**: πŸŒ… Morning, β˜€οΈ Afternoon, πŸŒ™ Night.
    - Include **real attractions, famous landmarks, hidden gems, and local experiences**.
    - Keep responses **structured, short, and engaging**.

    πŸ“Œ **Example Format**:
    **Day 1**:
    - πŸŒ… **Morning**: Visit [Famous Landmark] in {destination}
    - β˜€οΈ **Afternoon**: Try [Local Food] at [Best Restaurant]
    - πŸŒ™ **Night**: Experience [Cultural/Nightlife Activity]
    """

    response = chatbot(prompt, max_length=300, do_sample=True, temperature=0.6, top_p=0.85)
    return response[0]['generated_text']

# Creating a simple user interface
interface = gr.Interface(
    fn=generate_itinerary,
    inputs=[
        gr.Textbox(label="Destination"),
        gr.Textbox(label="Start Date (YYYY-MM-DD)"),
        gr.Textbox(label="End Date (YYYY-MM-DD)"),
        gr.Dropdown(["Art", "Food", "Nature", "Culture", "Nightlife"], label="Traveler Type"),
        gr.Dropdown(["Alone", "With Family", "With Friends", "With Partner"], label="Companion Type"),
    ],
    outputs="text",
    title="✈️ AI Travel Assistant",
    description="Enter your details, and let AI plan your perfect trip!"
)

interface.launch()