| from smolagents import Tool | |
| from selenium import webdriver | |
| from selenium.webdriver.chrome.options import Options | |
| from selenium.webdriver.chrome.service import Service as ChromeService | |
| from webdriver_manager.chrome import ChromeDriverManager | |
| from markdownify import markdownify as md | |
| from selenium.webdriver.support.ui import WebDriverWait | |
| from selenium.webdriver.support import expected_conditions as EC | |
| from selenium.webdriver.common.by import By | |
| import random | |
| class GetLogo(Tool): | |
| name = "get_logo" | |
| description = "Lookup and search for a logo and generate the SVG code" | |
| inputs = { | |
| } | |
| output_type = "string" | |
| def forward(self) -> str: | |
| chrome_options = Options() | |
| chrome_options.add_argument("--headless") | |
| chrome_options.add_argument("--no-sandbox") | |
| chrome_options.add_argument("--disable-dev-shm-usage") | |
| chrome_options.add_argument( | |
| "user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) " | |
| "AppleWebKit/537.36 (KHTML, like Gecko) " | |
| "Chrome/114.0.0.0 Safari/537.36" | |
| ) | |
| driver = webdriver.Chrome(service=ChromeService(ChromeDriverManager().install()), options=chrome_options) | |
| try: | |
| url = f"https://logoipsum.com/" | |
| driver.get(url) | |
| wait = WebDriverWait(driver, 10) | |
| buttons = wait.until( | |
| EC.presence_of_all_elements_located((By.CSS_SELECTOR, "div.artwork")) | |
| ) | |
| if not buttons: | |
| return "Aucun résultat trouvé." | |
| random_logo = random.choice(buttons) | |
| svg_element = random_logo.find_element(By.TAG_NAME, "svg") | |
| svg_code = svg_element.get_attribute("outerHTML") | |
| return svg_code | |
| finally: | |
| driver.quit() | |