Spaces:
Sleeping
Sleeping
Upload 2 files
Browse files- tools/translate_phrase_tool.txt +39 -0
- tools/visa_requirements_tool.py +185 -0
tools/translate_phrase_tool.txt
ADDED
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from typing import Any, Optional
|
2 |
+
from smolagents.tools import Tool
|
3 |
+
import os
|
4 |
+
import requests
|
5 |
+
|
6 |
+
class TranslatePhraseTool(Tool):
|
7 |
+
name = "translate_phrase"
|
8 |
+
description = "Translates common travel phrases to a local language."
|
9 |
+
inputs = {
|
10 |
+
'text': {'type': 'string', 'description': 'Text to translate (e.g., "Hello", "Thank you", "Where is the bathroom?")'},
|
11 |
+
'language': {'type': 'string', 'description': 'Target language (e.g., "Spanish", "Japanese", "French")'}
|
12 |
+
}
|
13 |
+
output_type = "string"
|
14 |
+
|
15 |
+
def __init__(self, api_key=None):
|
16 |
+
super().__init__()
|
17 |
+
# You can set an API key for a real translation API
|
18 |
+
self.api_key = api_key or os.environ.get("TRANSLATION_API_KEY")
|
19 |
+
|
20 |
+
# Common travel phrases in various languages (for demo/fallback purposes)
|
21 |
+
self.phrase_translations = {
|
22 |
+
"hello": {
|
23 |
+
"spanish": {"text": "Hola", "pronunciation": "oh-lah"},
|
24 |
+
"french": {"text": "Bonjour", "pronunciation": "bohn-zhoor"},
|
25 |
+
"italian": {"text": "Ciao", "pronunciation": "chow"},
|
26 |
+
"german": {"text": "Hallo", "pronunciation": "hah-loh"},
|
27 |
+
"japanese": {"text": "こんにちは (Konnichiwa)", "pronunciation": "kohn-nee-chee-wah"},
|
28 |
+
"mandarin": {"text": "你好 (Nǐ hǎo)", "pronunciation": "nee how"},
|
29 |
+
"arabic": {"text": "مرحبا (Marhaba)", "pronunciation": "mar-ha-ba"},
|
30 |
+
"russian": {"text": "Здравствуйте (Zdravstvuyte)", "pronunciation": "zdrah-stvooy-tye"},
|
31 |
+
"portuguese": {"text": "Olá", "pronunciation": "oh-lah"},
|
32 |
+
"thai": {"text": "สวัสดี (Sawatdee)", "pronunciation": "sa-wat-dee"}
|
33 |
+
},
|
34 |
+
"thank you": {
|
35 |
+
"spanish": {"text": "Gracias", "pronunciation": "grah-see-ahs"},
|
36 |
+
"french": {"text": "Merci", "pronunciation": "mair-see"},
|
37 |
+
"italian": {"text": "Grazie", "pronunciation": "graht-see-eh"},
|
38 |
+
"german": {"text": "Danke", "pronunciation": "dahn-kuh"},
|
39 |
+
"japanese": {"text": "ありがとう (Arigatou)", "pronunciation": "ah-
|
tools/visa_requirements_tool.py
ADDED
@@ -0,0 +1,185 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from typing import Any, Optional
|
2 |
+
from smolagents.tools import Tool
|
3 |
+
import os
|
4 |
+
import requests
|
5 |
+
|
6 |
+
class GetVisaRequirementsTool(Tool):
|
7 |
+
name = "get_visa_requirements"
|
8 |
+
description = "Checks visa requirements for traveling to a destination."
|
9 |
+
inputs = {
|
10 |
+
'nationality': {'type': 'string', 'description': "Traveler's passport country (e.g., 'US', 'UK', 'Canada')"},
|
11 |
+
'destination': {'type': 'string', 'description': "Country to visit (e.g., 'Japan', 'France', 'Brazil')"}
|
12 |
+
}
|
13 |
+
output_type = "string"
|
14 |
+
|
15 |
+
def __init__(self, api_key=None):
|
16 |
+
super().__init__()
|
17 |
+
# You can set an API key for a real visa API service
|
18 |
+
self.api_key = api_key or os.environ.get("VISA_API_KEY")
|
19 |
+
|
20 |
+
# Map of common country names to their normalized forms
|
21 |
+
self.country_mapping = {
|
22 |
+
"us": "united states", "usa": "united states", "united states of america": "united states",
|
23 |
+
"uk": "united kingdom", "britain": "united kingdom", "great britain": "united kingdom",
|
24 |
+
"uae": "united arab emirates", "emirates": "united arab emirates",
|
25 |
+
"china": "china", "prc": "china",
|
26 |
+
"japan": "japan",
|
27 |
+
"korea": "south korea", "south korea": "south korea", "republic of korea": "south korea",
|
28 |
+
"india": "india",
|
29 |
+
"germany": "germany",
|
30 |
+
"france": "france",
|
31 |
+
"italy": "italy",
|
32 |
+
"spain": "spain",
|
33 |
+
"mexico": "mexico",
|
34 |
+
"brazil": "brazil",
|
35 |
+
"australia": "australia", "aus": "australia",
|
36 |
+
"new zealand": "new zealand", "nz": "new zealand",
|
37 |
+
"canada": "canada", "can": "canada",
|
38 |
+
"russia": "russia", "russian federation": "russia",
|
39 |
+
"south africa": "south africa", "sa": "south africa",
|
40 |
+
"thailand": "thailand",
|
41 |
+
"vietnam": "vietnam",
|
42 |
+
"indonesia": "indonesia",
|
43 |
+
"malaysia": "malaysia",
|
44 |
+
"philippines": "philippines", "ph": "philippines",
|
45 |
+
"singapore": "singapore", "sg": "singapore",
|
46 |
+
"egypt": "egypt",
|
47 |
+
"turkey": "turkey", "türkiye": "turkey"
|
48 |
+
}
|
49 |
+
|
50 |
+
# Sample visa requirement data for frequently traveled routes
|
51 |
+
self.visa_data = {
|
52 |
+
"united states": {
|
53 |
+
"european union": "No visa required for stays up to 90 days in the Schengen Area",
|
54 |
+
"united kingdom": "No visa required for stays up to 6 months",
|
55 |
+
"japan": "No visa required for stays up to 90 days",
|
56 |
+
"australia": "Electronic Travel Authority (ETA) required",
|
57 |
+
"china": "Visa required, must apply in advance",
|
58 |
+
"india": "e-Visa available, apply online before travel",
|
59 |
+
"brazil": "No visa required for stays up to 90 days",
|
60 |
+
"mexico": "No visa required for stays up to 180 days",
|
61 |
+
"south africa": "No visa required for stays up to 90 days",
|
62 |
+
"thailand": "No visa required for stays up to 30 days",
|
63 |
+
"canada": "No visa required for US citizens"
|
64 |
+
},
|
65 |
+
"united kingdom": {
|
66 |
+
"european union": "No visa required for stays up to 90 days in the Schengen Area",
|
67 |
+
"united states": "ESTA required for entry",
|
68 |
+
"japan": "No visa required for stays up to 90 days",
|
69 |
+
"australia": "eVisitor visa required",
|
70 |
+
"china": "Visa required, must apply in advance",
|
71 |
+
"india": "e-Visa available, apply online before travel",
|
72 |
+
"brazil": "No visa required for stays up to 90 days",
|
73 |
+
"mexico": "No visa required for stays up to 180 days",
|
74 |
+
"south africa": "No visa required for stays up to 90 days",
|
75 |
+
"thailand": "No visa required for stays up to 30 days",
|
76 |
+
"canada": "eTA required for British citizens"
|
77 |
+
},
|
78 |
+
"canada": {
|
79 |
+
"european union": "No visa required for stays up to 90 days in the Schengen Area",
|
80 |
+
"united states": "No visa required for Canadian citizens",
|
81 |
+
"japan": "No visa required for stays up to 90 days",
|
82 |
+
"australia": "eVisitor visa required",
|
83 |
+
"china": "Visa required, must apply in advance",
|
84 |
+
"india": "e-Visa available, apply online before travel",
|
85 |
+
"brazil": "No visa required for stays up to 90 days",
|
86 |
+
"mexico": "No visa required for stays up to 180 days",
|
87 |
+
"south africa": "No visa required for stays up to 90 days",
|
88 |
+
"thailand": "No visa required for stays up to 30 days",
|
89 |
+
"united kingdom": "No visa required for stays up to 6 months"
|
90 |
+
},
|
91 |
+
"japan": {
|
92 |
+
"european union": "No visa required for stays up to 90 days in the Schengen Area",
|
93 |
+
"united states": "ESTA required for entry",
|
94 |
+
"australia": "eVisitor visa required",
|
95 |
+
"china": "Visa required, must apply in advance",
|
96 |
+
"india": "e-Visa available, apply online before travel",
|
97 |
+
"brazil": "Visa required for Japanese citizens",
|
98 |
+
"mexico": "No visa required for stays up to 180 days",
|
99 |
+
"south africa": "No visa required for stays up to 90 days",
|
100 |
+
"thailand": "No visa required for stays up to 30 days",
|
101 |
+
"united kingdom": "No visa required for stays up to 6 months",
|
102 |
+
"canada": "eTA required for Japanese citizens"
|
103 |
+
},
|
104 |
+
"australia": {
|
105 |
+
"european union": "No visa required for stays up to 90 days in the Schengen Area",
|
106 |
+
"united states": "ESTA required for entry",
|
107 |
+
"japan": "No visa required for stays up to 90 days",
|
108 |
+
"china": "Visa required, must apply in advance",
|
109 |
+
"india": "e-Visa available, apply online before travel",
|
110 |
+
"brazil": "Visa required for Australian citizens",
|
111 |
+
"mexico": "No visa required for stays up to 180 days",
|
112 |
+
"south africa": "No visa required for stays up to 90 days",
|
113 |
+
"thailand": "No visa required for stays up to 30 days",
|
114 |
+
"united kingdom": "No visa required for stays up to 6 months",
|
115 |
+
"canada": "eTA required for Australian citizens"
|
116 |
+
}
|
117 |
+
}
|
118 |
+
|
119 |
+
def forward(self, nationality: str, destination: str) -> str:
|
120 |
+
try:
|
121 |
+
# Normalize inputs
|
122 |
+
nationality = nationality.lower().strip()
|
123 |
+
destination = destination.lower().strip()
|
124 |
+
|
125 |
+
# Apply mappings if available
|
126 |
+
nationality = self.country_mapping.get(nationality, nationality)
|
127 |
+
destination = self.country_mapping.get(destination, destination)
|
128 |
+
|
129 |
+
# Try to use a real visa API if the API key is available
|
130 |
+
if self.api_key:
|
131 |
+
try:
|
132 |
+
# This would be the API call in a real implementation
|
133 |
+
# For now, we'll fall back to stored data
|
134 |
+
pass
|
135 |
+
except:
|
136 |
+
# Fall back to stored data if API call fails
|
137 |
+
return self._check_with_stored_data(nationality, destination)
|
138 |
+
|
139 |
+
# If no API key is available, use the stored data
|
140 |
+
return self._check_with_stored_data(nationality, destination)
|
141 |
+
|
142 |
+
except Exception as e:
|
143 |
+
return f"Error retrieving visa information: {str(e)}"
|
144 |
+
|
145 |
+
def _check_with_stored_data(self, nationality: str, destination: str) -> str:
|
146 |
+
# Skip if same country (generally no visa needed for citizens)
|
147 |
+
if nationality == destination:
|
148 |
+
return f"As a citizen of {nationality.title()}, you generally don't need a visa to visit your own country."
|
149 |
+
|
150 |
+
# Check if we have data for this nationality
|
151 |
+
if nationality not in self.visa_data:
|
152 |
+
# Try to search web for information if available
|
153 |
+
try:
|
154 |
+
import importlib
|
155 |
+
if importlib.util.find_spec("duckduckgo_search"):
|
156 |
+
from duckduckgo_search import DDGS
|
157 |
+
ddgs = DDGS()
|
158 |
+
results = ddgs.text(f"visa requirements for {nationality} citizens traveling to {destination}")
|
159 |
+
if results:
|
160 |
+
return f"Based on web search, for {nationality.title()} citizens traveling to {destination.title()}: {results[0]['body']}\n\n(Note: Always verify visa requirements with the official embassy or consulate before travel.)"
|
161 |
+
except:
|
162 |
+
pass
|
163 |
+
|
164 |
+
return f"I don't have specific visa information for citizens of {nationality.title()}. Please check with the embassy of {destination.title()} for accurate visa requirements."
|
165 |
+
|
166 |
+
# Check if we have data for this destination
|
167 |
+
if destination not in self.visa_data[nationality]:
|
168 |
+
# Try to search web for information if available
|
169 |
+
try:
|
170 |
+
import importlib
|
171 |
+
if importlib.util.find_spec("duckduckgo_search"):
|
172 |
+
from duckduckgo_search import DDGS
|
173 |
+
ddgs = DDGS()
|
174 |
+
results = ddgs.text(f"visa requirements for {nationality} citizens traveling to {destination}")
|
175 |
+
if results:
|
176 |
+
return f"Based on web search, for {nationality.title()} citizens traveling to {destination.title()}: {results[0]['body']}\n\n(Note: Always verify visa requirements with the official embassy or consulate before travel.)"
|
177 |
+
except:
|
178 |
+
pass
|
179 |
+
|
180 |
+
return f"I don't have specific visa information for {nationality.title()} citizens traveling to {destination.title()}. Please check with the embassy of {destination.title()} for accurate visa requirements."
|
181 |
+
|
182 |
+
# Get the visa requirements
|
183 |
+
requirements = self.visa_data[nationality][destination]
|
184 |
+
|
185 |
+
return f"🛂 Visa requirements for {nationality.title()} citizens traveling to {destination.title()}:\n\n{requirements}\n\n(Note: Visa requirements may change. Always verify with the official embassy or consulate before travel.)"
|