Spaces:
				
			
			
	
			
			
		Sleeping
		
	
	
	
			
			
	
	
	
	
		
		
		Sleeping
		
	| # image analyzer using open ai model | |
| from smolagents import tool | |
| from openai import OpenAI | |
| import dotenv | |
| dotenv.load_dotenv() | |
| def analyze_image(question: str, image_url: str) -> str: | |
| """ | |
| Analyze an image using OpenAI's API. | |
| Args: | |
| question (str): The question to ask about the image. eg. "What is in this image?" | |
| image_url (str): The URL of the image to analyze. | |
| """ | |
| client = OpenAI() | |
| response = client.responses.create( | |
| model="gpt-4o-mini", | |
| input=[ | |
| { | |
| "role": "user", | |
| "content": [ | |
| { "type": "input_text", "text": f"{question}" }, | |
| { | |
| "type": "input_image", | |
| "image_url": f"{image_url}", | |
| } | |
| ] | |
| } | |
| ] | |
| ) | |
| return response | |
| if __name__ == "__main__": | |
| question = "What is the main subject of this image?" | |
| image_url = "https://agents-course-unit4-scoring.hf.space/files/cca530fc-4052-43b2-b130-b30968d8aa44" | |
| answer = analyze_image(question, image_url) | |
| print(f"Answer: {answer}") |