File size: 1,108 Bytes
c899fa2 5e904fc fd3835f 882c6dd 7d1537c 8db3578 94d7bd9 8db3578 d532c55 7d1537c 8db3578 fd3835f 7d1537c e9b5cc1 79948e0 fd5fbc8 7fdbcb9 cb7cbf4 fd3835f f33344b 9b9f35d f33344b |
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 |
import requests
import os, io
import gradio as gr
# from PIL import Image
# API_URL = "https://api-inference.huggingface.co/models/facebook/detr-resnet-50-panoptic"
SECRET_TOKEN = os.getenv("SECRET_TOKEN")
API_URL = "https://api-inference.huggingface.co/models/facebook/detr-resnet-50-dc5-panoptic"
headers = {"Authorization": f'Bearer {SECRET_TOKEN}'}
def image_classifier(inp):
return {'cat': 0.3, 'dog': 0.7}
def query(filename):
with open(filename, "rb") as f:
data = f.read()
response = requests.post(API_URL, headers=headers, data=data)
return response.json()
def rb(img):
# initialiaze io to_bytes converter
img_byte_arr = io.BytesIO()
# define quality of saved array
img.save(img_byte_arr, format='JPEG', subsampling=0, quality=100)
# converts image array to bytesarray
img_byte_arr = img_byte_arr.getvalue()
response = requests.post(API_URL, headers=headers, data=img_byte_arr)
return response.json()
inputs = gr.inputs.Image(type="pil", label="Upload an image")
demo = gr.Interface(fn=rb, inputs=inputs, outputs="json")
demo.launch() |