Spaces:
Sleeping
Sleeping
Create image_caption.py
Browse files- tools/image_caption.py +14 -0
tools/image_caption.py
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from smolagents import Tool
|
| 2 |
+
from huggingface_hub import InferenceClient
|
| 3 |
+
|
| 4 |
+
class ImageCaptioningTool(Tool):
|
| 5 |
+
description = "Cet outil génère une légende descriptive pour une image donnée."
|
| 6 |
+
name = "image_captioner"
|
| 7 |
+
inputs = {"image_url": {"type": "string", "description": "URL de l'image à décrire."}}
|
| 8 |
+
output_type = "string"
|
| 9 |
+
model_id = "Salesforce/blip-image-captioning-large"
|
| 10 |
+
client = InferenceClient(model_id)
|
| 11 |
+
|
| 12 |
+
def forward(self, image_url):
|
| 13 |
+
image = requests.get(image_url, stream=True).raw
|
| 14 |
+
return self.client.image_to_text(image)
|