Spaces:
Sleeping
Sleeping
File size: 1,084 Bytes
9571928 02840f8 5c5f32d 0b0ce33 02840f8 0a0ae08 0b0ce33 9571928 0b0ce33 9571928 0b0ce33 9571928 0b0ce33 9571928 0a0ae08 9571928 0a0ae08 9571928 88701df 0b0ce33 5c5f32d 0a0ae08 0b0ce33 |
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 |
import os
import base64
import requests
from smolagents import Tool
class ImageAnalysisTool(Tool):
name = "image_analysis"
description = "Analyze the content of an image and answer a specific question about it using Hugging Face Inference API."
inputs = {
"image_path": {
"type": "string",
"description": "Path to the image file (jpg, png, etc.)"
},
"question": {
"type": "string",
"description": "A question about the image content"
}
}
output_type = "string"
def __init__(self):
super().__init__()
api_token = os.getenv("HF_API_TOKEN")
if not api_token:
raise EnvironmentError("HF_API_TOKEN not found in environment variables.")
self.api_url = "https://api-inference.huggingface.co/models/microsoft/git-base-captioning"
self.headers = {
"Authorization": f"Bearer {api_token}",
"Content-Type": "application/json"
}
def forward(self, image_path: str, question: str) -> str
|