|
import requests |
|
import os, io |
|
import gradio as gr |
|
|
|
|
|
|
|
|
|
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): |
|
|
|
img_byte_arr = io.BytesIO() |
|
|
|
img.save(img_byte_arr, format='JPEG', subsampling=0, quality=100) |
|
|
|
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() |