# ============================================================
# TripMind AI - Travel Planner using Python + Flask + Claude
# AIML Concepts: NLP, LLM, Content-Based Filtering,
# Prompt Engineering, Response Parsing
# ============================================================
from flask import Flask, render_template, request, jsonify
import anthropic # Anthropic SDK for Claude AI
import os
app = Flask(__name__)
# ■■ Initialize the Anthropic (Claude) client ■■■■■■■■■■■■■■■■■■
# AIML Concept: LLM (Large Language Model) Integration
# Claude is the AI brain of our app. We send it prompts and
# it generates intelligent travel plans for us.
client = [Link](
api_key=[Link]("ANTHROPIC_API_KEY", "your-api-key-here")
)
# =============================================================
# AIML MODULE 1: PROMPT ENGINEERING
# We craft special instructions (system prompts) to control
# how the AI responds. This is Prompt Engineering.
# =============================================================
ITINERARY_SYSTEM_PROMPT = """
You are a friendly travel planner for beginner travelers.
Reply in EXACTLY these 4 sections separated by the text ###:
SECTION 1 - DAILY PLAN: Give a simple day-by-day itinerary (1-2 lines per day)
SECTION 2 - WHERE TO STAY: 2 budget-friendly hotel options with price range
SECTION 3 - MUST SEE: Top 3 attractions with one fun fact each
SECTION 4 - MONEY TIPS: Simple budget breakdown (food, stay, travel, total estimate)
Keep it simple, friendly, and easy to understand for beginners.
"""
RECOMMENDATION_SYSTEM_PROMPT = """
You are a friendly travel destination recommender.
Reply in EXACTLY these 4 sections separated by the text ###:
SECTION 1 - TOP 3 PICKS: Three destinations that match the user's preferences, one sentence reason ea
SECTION 2 - BEST FOR BUDGET: Which destination gives most value for money and why
SECTION 3 - HIDDEN GEM: One lesser-known spot that perfectly matches their interests
SECTION 4 - QUICK CHECKLIST: 5 things to do before booking (visa, season, documents etc.)
Keep it practical, simple, and beginner friendly.
"""
# =============================================================
# AIML MODULE 2: CONTENT-BASED FILTERING
# We match user preferences (interests, budget, style) to
# relevant destination categories before sending to AI.
# This is a simple rule-based content filtering system.
# =============================================================
def content_based_filter(interests, budget, travel_style):
"""
AIML Concept: Content-Based Filtering
Maps user inputs to destination categories.
Similar to how Netflix recommends movies based on what you liked before.
"""
category_hints = []
# Map interests to destination types
interest_map = {
"beach": "coastal destinations, island getaways, beach resorts",
"adventure": "mountains, trekking spots, adventure parks, national parks",
"culture": "heritage cities, museums, UNESCO sites, historical towns",
"food": "food capitals, street food hubs, culinary destinations",
"wildlife": "wildlife sanctuaries, national parks, jungle safaris",
"pilgrimage": "religious sites, temple towns, spiritual destinations",
}
for interest in interests:
if [Link]() in interest_map:
category_hints.append(interest_map[[Link]()])
# Map budget to price tier
budget_hint = {
"low": "budget-friendly, backpacker-friendly, hostels available",
"medium": "mid-range hotels, comfortable travel",
"high": "luxury resorts, premium experiences",
}.get([Link](), "")
# Map travel style
style_hint = {
"solo": "solo traveler friendly, safe for solo trips",
"couple": "romantic getaways, honeymoon destinations",
"family": "family-friendly, kid-safe activities",
"friends": "group activities, nightlife, social spots",
}.get(travel_style.lower(), "")
return {
"categories": ", ".join(category_hints),
"budget_hint": budget_hint,
"style_hint": style_hint,
}
# =============================================================
# AIML MODULE 3: NLP - Natural Language Processing
# We convert structured user inputs into natural language
# prompts that the AI can understand. This is NLP in action.
# =============================================================
def build_itinerary_prompt(destination, days, budget, travel_style, interests):
"""
AIML Concept: NLP - Turning structured data into natural language
We take form inputs and build a human-readable sentence
that the LLM understands better than raw data.
"""
interests_text = ", ".join(interests) if interests else "general sightseeing"
# This is NLP: converting data → natural language
prompt = f"""
Plan a trip to {destination}.
Duration: {days} days
Budget level: {budget}
Travel style: {travel_style}
Interests: {interests_text}
Please create a complete travel plan for this trip.
"""
return prompt
def build_recommendation_prompt(interests, budget, days, travel_style):
"""
AIML Concept: NLP + Content-Based Filtering combined
We first filter categories, then build a natural language prompt.
"""
# Step 1: Content-based filtering
filters = content_based_filter(interests, budget, travel_style)
# Step 2: Build NLP prompt using filtered data
interests_text = ", ".join(interests) if interests else "general travel"
prompt = f"""
Recommend travel destinations for someone with these preferences:
- Interests: {interests_text}
- Preferred destination types: {filters['categories']}
- Budget preference: {budget} ({filters['budget_hint']})
- Trip duration: {days} days
- Travel style: {travel_style} ({filters['style_hint']})
Suggest the best matching destinations.
"""
return prompt
# =============================================================
# AIML MODULE 4: LLM RESPONSE PARSING
# After the AI responds, we extract structured data from
# the raw text. This is how we turn AI output into UI cards.
# =============================================================
def parse_ai_response(raw_text, section_titles):
"""
AIML Concept: Response Parsing
The AI returns one big text block. We split it into sections
using the ### separator we defined in our system prompt.
This converts unstructured AI output → structured data.
"""
sections = raw_text.split("###")
sections = [[Link]() for s in sections if [Link]()]
result = []
for i, section_text in enumerate(sections):
[Link]({
"title": section_titles[i] if i < len(section_titles) else f"Section {i+1}",
"content": section_text,
"index": i,
})
return result
# =============================================================
# FLASK ROUTES (Web Pages & API Endpoints)
# =============================================================
@[Link]("/")
def home():
"""Render the main page"""
return render_template("[Link]")
@[Link]("/generate-itinerary", methods=["POST"])
def generate_itinerary():
"""
API endpoint for Itinerary Generation
AIML Pipeline: NLP (prompt build) → LLM (Claude) → Parsing (sections)
"""
try:
data = request.get_json()
# Extract user inputs
destination = [Link]("destination", "")
days = [Link]("days", "3")
budget = [Link]("budget", "medium")
travel_style = [Link]("style", "solo")
interests = [Link]("interests", [])
# Validate inputs
if not destination:
return jsonify({"error": "Please enter a destination"}), 400
# AIML Step 1: NLP - Build natural language prompt
user_prompt = build_itinerary_prompt(destination, days, budget, travel_style, interests)
# AIML Step 2: LLM - Send to Claude AI
message = [Link](
model="claude-sonnet-4-6",
max_tokens=1000,
system=ITINERARY_SYSTEM_PROMPT, # Prompt Engineering
messages=[{"role": "user", "content": user_prompt}]
)
raw_response = [Link][0].text
# AIML Step 3: Response Parsing - Extract sections
section_titles = [
"■■ Day-by-Day Plan",
"■ Where to Stay",
"■ Must-See Spots",
"■ Budget Breakdown"
]
sections = parse_ai_response(raw_response, section_titles)
return jsonify({
"success": True,
"destination": destination,
"sections": sections,
"aiml_note": "NLP → Prompt Engineering → Claude LLM → Response Parsing"
})
except Exception as e:
return jsonify({"error": str(e)}), 500
@[Link]("/get-recommendations", methods=["POST"])
def get_recommendations():
"""
API endpoint for Destination Recommendations
AIML Pipeline: Content Filtering → NLP → LLM → Parsing
"""
try:
data = request.get_json()
interests = [Link]("interests", [])
budget = [Link]("budget", "medium")
days = [Link]("days", "3-5")
travel_style = [Link]("style", "solo")
# Validate
if not interests and not budget:
return jsonify({"error": "Please select at least one interest or budget"}), 400
# AIML Step 1: Content-Based Filtering + NLP
user_prompt = build_recommendation_prompt(interests, budget, days, travel_style)
# AIML Step 2: LLM - Send to Claude AI
message = [Link](
model="claude-sonnet-4-6",
max_tokens=1000,
system=RECOMMENDATION_SYSTEM_PROMPT,
messages=[{"role": "user", "content": user_prompt}]
)
raw_response = [Link][0].text
# AIML Step 3: Response Parsing
section_titles = [
"■ Top 3 Destinations For You",
"■ Best Value Destination",
"■ Hidden Gem Pick",
"■ Pre-Trip Checklist"
]
sections = parse_ai_response(raw_response, section_titles)
return jsonify({
"success": True,
"sections": sections,
"filters_applied": content_based_filter(interests, budget, travel_style),
"aiml_note": "Content-Based Filtering → NLP → Claude LLM → Response Parsing"
})
except Exception as e:
return jsonify({"error": str(e)}), 500
if __name__ == "__main__":
print("■ TripMind AI Server Starting...")
print("■ Open [Link] in your browser")
[Link](debug=True, port=5000)