/
githubmirror
/
NLSOM
Обзор
Документация
Войти
/
githubmirror
/
NLSOM
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
society/object_detection/agent.py
40 строк
1 KB
mczhuge
update
31 май 2023, 14:22
31 май 2023, 14:22
3fba974
Код
Авторство
О чём код?
import os import requests def prompts(name, description): def decorator(func): func.name = name func.description = description return func return decorator class DETR: def __init__(self, device="cpu"): self.device = device self.API_URL = "https://api-inference.huggingface.co/models/facebook/detr-resnet-50" self.headers = {"Authorization": "Bearer "+os.getenv("HUGGINGFACE_ACCESS_Tokens")} @prompts(name="DETR (object detection)", description="useful when you want to detect the objects in an image. " "The input to this tool should be a string, representing input image file. ") def inference(self, filename): output = self.query(filename) return output def query(self, filename): with open(filename, "rb") as f: data = f.read() response = requests.post(self.API_URL, headers=self.headers, data=data) return response.json() if __name__ == "__main__": object_detection_model = DETR(device="cpu") result = object_detection_model.inference("xyz.png") print(result)