Spaces:
Sleeping
Sleeping
Update app.py
Browse files12345678910111213141516171819202122from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,toolimport datetimeimport requestsimport pytzimport yamlfrom tools.final_answer import FinalAnswerToolfrom Gradio_UI import GradioUI# Below is an example of a tool that does nothing. Amaze us with your creativity !@tooldef my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type#Keep this format for the description / args / args description but feel free to modify the tool"""A tool that does nothing yetArgs:arg1: the first argumentarg2: the second argument"""return "What magic will you build ?"@tooldef get_current_time_in_timezone(timezone: str) -> str:1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,toolfrom bs4 import BeautifulSoupimport datetimeimport requestsimport pytzimport yamlfrom tools.final_answer import FinalAnswerToolimport refrom Gradio_UI import GradioUI@tooldef my_custom_tool(animal_type=None, breed=None):"""Finds animals and breeds from Brampton Animal Shelter website."""base_url = "https://www.brampton.ca/EN/residents/Animal-Services/Pages/Adoption.aspx"matching_animals = []processed_ids = {}session = requests.Session()response = session.get(base_url)if response.status_code != 200:return f"Failed to access the website. Status code: {response.status_code}"# Only process the main page, no paginationprocess_page(response.text, matching_animals, processed_ids, animal_type, breed)animal_sentences = []for animal in matching_animals:if (animal.get("name") in [None, "", "Unknown"] oranimal.get("age") in [None, "", "unknown age"] oranimal.get("sex") in [None, "", "unknown gender"] oranimal.get("breed") in [None, "", "unknown breed"] oranimal.get("type") in [None, "", "animal"]):continuename = animal.get("name", "Unknown").title()age = animal.get("age", "unknown age").lower().strip()sex = animal.get("sex", "unknown gender").lower()breed_name = animal.get("breed", "unknown breed").title()animal_type_value = animal.get("type", "animal").lower()sentence = f"A {age} old {sex} {breed_name} named {name}, type: {animal_type_value}"animal_sentences.append(sentence)if animal_sentences:return "\n".join(animal_sentences)else:return "No matching animals found."def process_page(html_content, matching_animals, processed_ids, animal_type=None, breed=None):"""Process a single page of animal listings"""soup = BeautifulSoup(html_content, 'html.parser')animal_cards = soup.find_all("div", class_="dvanimalitem")for card in animal_cards:animal_info = {}name_element = card.find("span", class_="animalname")if name_element:animal_info["name"] = name_element.text.strip()for field in ["id", "type", "sex", "breed", "age", "size", "color", "location"]:field_element = card.find("span", id=lambda x: x and x.startswith(f"sp{field}"))if field_element:animal_info[field] = field_element.text.strip()if animal_info.get("id") in processed_ids:continueif "id" in animal_info:processed_ids[animal_info["id"]] = True# Matching logictype_match = Truebreed_match = Trueif animal_type:animal_type_lower = animal_type.lower()current_type_lower = animal_info.get("type", "").lower()if animal_type_lower == "other":type_match = current_type_lower not in ["dog", "cat", "bird"]else:type_match = animal_type_lower in current_type_lowerif breed:breed_match = breed.lower() in animal_info.get("breed", "").lower()if type_match and breed_match:matching_animals.append(animal_info)@tooldef get_current_time_in_timezone(timezone: str) -> str:
app.py+82-9