Update app.py
Browse files
app.py
CHANGED
|
@@ -12,22 +12,34 @@ if HF_TOKEN:
|
|
| 12 |
else:
|
| 13 |
raise ValueError("π¨ Hugging Face token not found! Please add it to Secrets in your Hugging Face Space.")
|
| 14 |
|
| 15 |
-
#
|
| 16 |
-
chatbot = pipeline(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
def generate_itinerary(destination, start_date, end_date, traveler_type, companion):
|
| 19 |
"""Generates an AI-powered travel itinerary based on user preferences"""
|
| 20 |
-
|
| 21 |
prompt = f"""
|
| 22 |
-
You are
|
| 23 |
-
- Dates
|
| 24 |
-
- Traveler
|
| 25 |
-
- Companion
|
| 26 |
-
- Provide 3 activities per day
|
| 27 |
-
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
"""
|
| 29 |
-
|
| 30 |
-
response = chatbot(prompt, max_length=
|
| 31 |
return response[0]['generated_text']
|
| 32 |
|
| 33 |
# Creating a simple user interface
|
|
|
|
| 12 |
else:
|
| 13 |
raise ValueError("π¨ Hugging Face token not found! Please add it to Secrets in your Hugging Face Space.")
|
| 14 |
|
| 15 |
+
# Load AI model (optimized for T4 Small GPU)
|
| 16 |
+
chatbot = pipeline(
|
| 17 |
+
"text-generation",
|
| 18 |
+
model="mistralai/Mistral-7B-Instruct-v0.1",
|
| 19 |
+
token=HF_TOKEN,
|
| 20 |
+
device=0 # Runs on GPU
|
| 21 |
+
)
|
| 22 |
|
| 23 |
def generate_itinerary(destination, start_date, end_date, traveler_type, companion):
|
| 24 |
"""Generates an AI-powered travel itinerary based on user preferences"""
|
| 25 |
+
|
| 26 |
prompt = f"""
|
| 27 |
+
You are a professional travel assistant. Create a **day-by-day itinerary** for a trip to {destination}.
|
| 28 |
+
- π
**Dates**: {start_date} to {end_date}
|
| 29 |
+
- π **Traveler Type**: {traveler_type}
|
| 30 |
+
- π§³ **Companion**: {companion}
|
| 31 |
+
- Provide **3 activities per day**: π
Morning, βοΈ Afternoon, π Night.
|
| 32 |
+
- Include **real attractions, famous landmarks, hidden gems, and local experiences**.
|
| 33 |
+
- Keep responses **structured, short, and engaging**.
|
| 34 |
+
|
| 35 |
+
π **Example Format**:
|
| 36 |
+
**Day 1**:
|
| 37 |
+
- π
**Morning**: Visit [Famous Landmark] in {destination}
|
| 38 |
+
- βοΈ **Afternoon**: Try [Local Food] at [Best Restaurant]
|
| 39 |
+
- π **Night**: Experience [Cultural/Nightlife Activity]
|
| 40 |
"""
|
| 41 |
+
|
| 42 |
+
response = chatbot(prompt, max_length=300, do_sample=True, temperature=0.6, top_p=0.85)
|
| 43 |
return response[0]['generated_text']
|
| 44 |
|
| 45 |
# Creating a simple user interface
|