Spaces:
Sleeping
Sleeping
File size: 5,437 Bytes
9b5b26a c19d193 6aae614 8fe992b 9b5b26a 5df72d6 9855a3e 9b5b26a 88d3733 9b5b26a 88d3733 9b5b26a 88d3733 9855a3e 88d3733 9b5b26a 9855a3e 9b5b26a 8c01ffb 6aae614 ae7a494 e121372 bf6d34c 29ec968 fe328e0 13d500a 8c01ffb 9b5b26a 8c01ffb 861422e 9b5b26a 8c01ffb 8fe992b d2f6a24 8c01ffb 861422e 8fe992b 9b5b26a 8c01ffb | 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 | from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool
import datetime
import requests
import pytz
import yaml
from tools.final_answer import FinalAnswerTool
from Gradio_UI import GradioUI
# Below is an example of a tool that does nothing. Amaze us with your creativity !
#==============================================================================================================================#
@tool
def get_tourist_place_info(place: str, duration_days: int)-> str :
"""A tool that provides comprehensive tourist information about a particular tourist place or places,
Args:
place: the name of the given tourist destination (landmark, city, state, country).
duration_days: the no. of days planned for the visit.
"""
import anthropic
client = anthropic.Anthropic()
prompt = f"""
Provide detailed tourist information about {place} for a {duration_days}-day visit in the following structured format:-
1. **Overview**: Brief introduction of the place.
2. **Best season to visit**: Ideal months and why, including weather details.
3. **Tourist attractions**: Top 5-7 must see attractions with a one-line description of each.
4. **Best places to stay**: 3 accomodation options with budget ranges (budget. mid-range, luxury).
5. *Best way to travel there**: Primary transport options (flight, train, road) with trips.
6. **Local transport**: How to get around once there.
7. **Local cuisine**: 3-5 must try dishes or food experiences.
8. **Travel trips**: 3-4 practical trips (visa, language, currency, customs).
Keep each section concise but informative.
"""
message = client.messages.create(
model= "claude-sonnet-4-2025-0514",
max_tokens=1000,
messages= [{"role": "user", "content": prompt}]
)
return message.context[0].text
#================================================================================================================================#
@tool
def travel_plan_creator(place: str, duration_days: int, budget_level: str) -> str:
"""A tool that creates a detailed day-by-day travel itinerary for a tourist destination.
Args:
place: the name of the tourist destination (landmark, city, state, country).
duration_days: the nop. of days planned for the visit.
budget_level: travel budget preference- must be one of: 'budget', 'mid-range', or 'luxury'.
"""
import anthropic
client = anthropic.Anthropic()
place_info = get_tourist_place_info(place, duration_days)
prompt= f"""
Using the following tourist information about {place}:
{place_info}
Create a detailed {duration_days}-day travel itinerary for a {budget_level} traveller. Structure it as:
**Trip summary**
- Destination, duration, budget level, estimated total cost range.
**Pre-Trip Checklist**
- visa, vaccinations, bookings to be made in advance.
*Day-by-day itinerary**
for each day provide:
-Morning, Afternoon, Evening activities.
-Recommended meals (breakfast, lunch, dinner spots)
-Estimated daily spend.
**Accomodation Plan**
- Recommended stay options matching the {budget_level} budget.
**Transport plan**
- How to reach {place} + local commute tips.
**Packing essentials**
- 5-6 items specific to this destination and season.
Make the plan realistic, time-efficient, and enjoyable.
"""
message = client.messages.create(
model= "claude-sonnet-4-20250514",
tokens= 1000,
messages= [{"role": "user", "content": prompt}]
)
return message.content[0].text
#===================================================================================================================================#
@tool
def get_current_time_in_timezone(timezone: str) -> str:
"""A tool that fetches the current local time in a specified timezone.
Args:
timezone: A string representing a valid timezone (e.g., 'America/New_York').
"""
try:
# Create timezone object
tz = pytz.timezone(timezone)
# Get current time in that timezone
local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
return f"The current local time in {timezone} is: {local_time}"
except Exception as e:
return f"Error fetching time for timezone '{timezone}': {str(e)}"
final_answer = FinalAnswerTool()
# If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
# model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
model = HfApiModel(
max_tokens=2096,
temperature=0.5,
model_id='Qwen/Qwen2.5-Coder-32B-Instruct',# it is possible that this model may be overloaded
custom_role_conversions=None,
)
# Import tool from Hub
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
with open("prompts.yaml", 'r') as stream:
prompt_templates = yaml.safe_load(stream)
agent = CodeAgent(
model=model,
tools=[final_answer], ## add your tools here (don't remove final answer)
max_steps=6,
verbosity_level=1,
grammar=None,
planning_interval=None,
name=None,
description=None,
prompt_templates=prompt_templates
)
GradioUI(agent).launch() |