File size: 997 Bytes
faf0b67
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import os, io
import gradio as gr
from transformers import pipeline
# 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 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()
    return img_byte_arr

estimator = pipeline("depth-estimation")
result = estimator("http://images.cocodataset.org/val2017/000000039769.jpg")


inputs = gr.inputs.Image(type="pil", label="Upload an image")

demo = gr.Interface(fn=rb, inputs=inputs, outputs=result)
#demo = gr.Interface(fn=rb, inputs=inputs, outputs=result["depth"])
demo.launch()