|
import os |
|
import gradio as gr |
|
from transformers import pipeline |
|
from huggingface_hub import login |
|
|
|
|
|
HF_TOKEN = os.getenv("HF_TOKEN") |
|
|
|
|
|
if HF_TOKEN: |
|
login(HF_TOKEN) |
|
else: |
|
raise ValueError("π¨ Hugging Face token not found! Please add it to Secrets in your Hugging Face Space.") |
|
|
|
|
|
chatbot = pipeline("text-generation", model="mistralai/Mistral-7B-8Bit", token=HF_TOKEN) |
|
|
|
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 travel assistant. Generate a detailed day-by-day itinerary for a trip to {destination}. |
|
- Trip Duration: {start_date} to {end_date} |
|
- Type of traveler: {traveler_type} |
|
- Traveling with: {companion} |
|
- Each day should have 3 activities for morning, afternoon, and night. |
|
- Provide unique local recommendations based on the traveler's interests. |
|
""" |
|
|
|
response = chatbot(prompt, max_length=150, do_sample=True, temperature=0.7, top_p=0.9) |
|
return response[0]['generated_text'] |
|
|
|
|
|
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() |
|
|