Spaces:
Build error
Build error
| import os | |
| import PIL | |
| import requests | |
| from io import BytesIO | |
| from PIL import Image | |
| from smolagents import CodeAgent, OpenAIServerModel, InferenceClientModel | |
| from huggingface_hub import login | |
| image_urls = [ | |
| "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTcB9-ieIzm2uhtTkMkV5F50xbL4itvh3j8bg&s", # Joker image | |
| "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcR0SWQC74KuQWrJA33pJqUmOuDx62K7p1uEcQ&s" # Joker image | |
| ] | |
| stored_images = [] | |
| for url in image_urls: | |
| headers = { | |
| "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" | |
| } | |
| response = requests.get(url, headers) | |
| try: | |
| image = Image.open(BytesIO(response.content)).convert("RGB") | |
| stored_images.append(image) | |
| except PIL.UnidentifiedImageError: | |
| print("⚠️ The downloaded file is not a valid image.") | |
| # Optional: save the raw bytes for inspection | |
| with open("debug_image.bin", "wb") as f: | |
| f.write(response.content) | |
| # image = Image.open(BytesIO(response.content)).convert("RGB") | |
| def init_stored_image_agent() -> CodeAgent: | |
| # Now based on the images indicate if it's wonder women or joker. | |
| model = OpenAIServerModel(model_id="gpt-4o") | |
| stored_image_agent = CodeAgent( | |
| tools=[], | |
| model=model, | |
| max_steps=5, | |
| verbosity_level=2 | |
| ) | |
| return stored_image_agent |