File size: 9,118 Bytes
e51b1cb 18236b5 e51b1cb |
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 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 |
import gradio as gr
from typing import Dict, List, Any
class TravelDocumentationService:
"""Service for fetching travel documentation requirements"""
def get_visa_requirements(
self,
from_country: str,
to_country: str,
trip_duration: int = 30
) -> Dict[str, Any]:
"""Get visa requirements for travel between countries"""
# Mock data
visa_free_combinations = {
("canada", "japan"): {"visa_required": False, "max_stay": "90 days"},
("canada", "uk"): {"visa_required": False, "max_stay": "6 months"},
("canada", "usa"): {"visa_required": False, "max_stay": "6 months"},
("canada", "germany"): {"visa_required": False, "max_stay": "90 days"},
("usa", "japan"): {"visa_required": False, "max_stay": "90 days"},
("usa", "uk"): {"visa_required": False, "max_stay": "6 months"},
("usa", "germany"): {"visa_required": False, "max_stay": "90 days"},
("china", "japan"): {"visa_required": True, "visa_type": "Tourist Visa", "max_stay": "30 days", "processing_time": "5-7 business days", "fee": "$30 USD"},
("india", "japan"): {"visa_required": True, "visa_type": "Tourist Visa", "max_stay": "90 days", "processing_time": "5-10 business days", "fee": "$50 USD"},
("china", "usa"): {"visa_required": True, "visa_type": "B-2 Tourist Visa", "max_stay": "6 months", "processing_time": "3-5 weeks", "fee": "$160 USD"},
("india", "usa"): {"visa_required": True, "visa_type": "B-2 Tourist Visa", "max_stay": "6 months", "processing_time": "3-5 weeks", "fee": "$160 USD"},
}
key = (from_country.lower(), to_country.lower())
if key in visa_free_combinations:
return visa_free_combinations[key]
else:
return {
"visa_required": True,
"visa_type": "Tourist Visa",
"max_stay": "30 days",
"processing_time": "5-10 business days",
"fee": "$50-150 USD"
}
def get_document_requirements(
self,
from_country: str,
to_country: str,
trip_duration: int = 30,
trip_purpose: str = "tourism"
) -> List[Dict[str, Any]]:
"""Get comprehensive document requirements for travel"""
requirements = []
requirements.append({
"document_type": "Passport",
"required": True,
"description": "Valid passport with at least 6 months validity remaining",
"validity_period": "At least 6 months from travel date",
"additional_notes": "Must have at least 2 blank pages for stamps"
})
visa_info = self.get_visa_requirements(from_country, to_country, trip_duration)
if visa_info.get("visa_required", False):
requirements.append({
"document_type": "Visa",
"required": True,
"description": f"Required {visa_info.get('visa_type', 'Tourist Visa')}",
"processing_time": visa_info.get("processing_time", "5-10 business days"),
"additional_notes": f"Fee: {visa_info.get('fee', 'Varies by embassy')}"
})
insurance_required_countries = ["schengen", "germany", "france", "italy", "spain", "netherlands", "austria", "belgium"]
if to_country.lower() in insurance_required_countries:
requirements.append({
"document_type": "Travel Insurance",
"required": True,
"description": "Travel insurance with minimum €30,000 coverage",
"additional_notes": "Required for Schengen area countries"
})
else:
requirements.append({
"document_type": "Travel Insurance",
"required": False,
"description": "Travel insurance (highly recommended)",
"additional_notes": "Covers medical emergencies, trip cancellation, etc."
})
requirements.append({
"document_type": "Return/Onward Ticket",
"required": True,
"description": "Proof of return or onward travel",
"additional_notes": "Flight confirmation or travel itinerary"
})
financial_amount = "$100-150 per day" if to_country.lower() in ["japan", "switzerland", "norway"] else "$50-100 per day"
requirements.append({
"document_type": "Financial Proof",
"required": True,
"description": f"Proof of sufficient funds ({financial_amount})",
"additional_notes": "Bank statements, credit cards, or traveler's checks"
})
requirements.append({
"document_type": "Accommodation Proof",
"required": True,
"description": "Hotel booking or invitation letter",
"additional_notes": "Confirmation of where you'll be staying"
})
if trip_purpose.lower() == "business":
requirements.append({
"document_type": "Business Invitation Letter",
"required": True,
"description": "Letter from host company",
"additional_notes": "Must include company details and purpose of visit"
})
elif trip_purpose.lower() == "study":
requirements.append({
"document_type": "Student Visa/Permit",
"required": True,
"description": "Student visa or study permit",
"additional_notes": "Issued by educational institution"
})
requirements.append({
"document_type": "Acceptance Letter",
"required": True,
"description": "Letter of acceptance from educational institution",
"additional_notes": "Must be from recognized institution"
})
return requirements
travel_service = TravelDocumentationService()
def get_requirements(from_country, to_country, trip_duration, trip_purpose):
"""
Analyze the documentation requirment for user's travel plan
Args:
from_country (str): User's original country
to_country (str): The destination country that the user plans to travel to
trip_duration (number): The days length that the user plans to stay in the destination country
trip_purpose (str): The purpose of the travel, the user is go for business, tourism, study or other purposes
Returns:
json: Contains the comprehensive documentation requires and suggestions based on the user input
"""
try:
requirements = travel_service.get_document_requirements(
from_country, to_country, int(trip_duration), trip_purpose
)
visa_info = travel_service.get_visa_requirements(from_country, to_country, int(trip_duration))
required_docs = [req for req in requirements if req['required']]
optional_docs = [req for req in requirements if not req['required']]
result = {
"trip_info": {
"from_country": from_country.title(),
"to_country": to_country.title(),
"duration_days": int(trip_duration),
"purpose": trip_purpose.title()
},
"visa_requirements": {
"visa_required": visa_info.get("visa_required", False),
"visa_type": visa_info.get("visa_type"),
"max_stay": visa_info.get("max_stay"),
"processing_time": visa_info.get("processing_time"),
"fee": visa_info.get("fee")
},
"required_documents": required_docs,
"optional_documents": optional_docs,
"total_documents": len(requirements),
"summary": {
"required_count": len(required_docs),
"optional_count": len(optional_docs),
"visa_needed": visa_info.get("visa_required", False)
}
}
return result
except Exception as e:
return {"error": str(e)}
travel_demo = gr.Interface(
fn=get_requirements,
inputs=[
gr.Textbox(label="Your Citizenship Country", placeholder="e.g., Canada", value="Canada"),
gr.Textbox(label="Destination Country", placeholder="e.g., Japan", value="Japan"),
gr.Number(label="Trip Duration (days)", value=30, minimum=1, maximum=365),
gr.Dropdown(label="Trip Purpose", choices=["tourism", "business", "transit", "study", "work", "family visit"], value="tourism")
],
outputs=gr.JSON(),
title="Travel Documentation Requirements",
description="Get the comprehensive travel documentation requirements for international travel"
)
if __name__ == "__main__":
travel_demo.launch(
# share=True,
show_error=True,
mcp_server=True,
# server_port=7861
)
|