Spaces:
Runtime error
Runtime error
Commit ·
faf0b67
1
Parent(s): 3929c56
Upload 2 files
Browse files- app.py +30 -0
- requirements.txt +2 -0
app.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os, io
|
| 2 |
+
import gradio as gr
|
| 3 |
+
from transformers import pipeline
|
| 4 |
+
# from PIL import Image
|
| 5 |
+
|
| 6 |
+
# API_URL = "https://api-inference.huggingface.co/models/facebook/detr-resnet-50-panoptic"
|
| 7 |
+
|
| 8 |
+
SECRET_TOKEN = os.getenv("SECRET_TOKEN")
|
| 9 |
+
API_URL = "https://api-inference.huggingface.co/models/facebook/detr-resnet-50-dc5-panoptic"
|
| 10 |
+
headers = {"Authorization": f'Bearer {SECRET_TOKEN}'}
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
def rb(img):
|
| 14 |
+
# initialiaze io to_bytes converter
|
| 15 |
+
img_byte_arr = io.BytesIO()
|
| 16 |
+
# define quality of saved array
|
| 17 |
+
img.save(img_byte_arr, format='JPEG', subsampling=0, quality=100)
|
| 18 |
+
# converts image array to bytesarray
|
| 19 |
+
img_byte_arr = img_byte_arr.getvalue()
|
| 20 |
+
return img_byte_arr
|
| 21 |
+
|
| 22 |
+
estimator = pipeline("depth-estimation")
|
| 23 |
+
result = estimator("http://images.cocodataset.org/val2017/000000039769.jpg")
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
inputs = gr.inputs.Image(type="pil", label="Upload an image")
|
| 27 |
+
|
| 28 |
+
demo = gr.Interface(fn=rb, inputs=inputs, outputs=result)
|
| 29 |
+
#demo = gr.Interface(fn=rb, inputs=inputs, outputs=result["depth"])
|
| 30 |
+
demo.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio
|
| 2 |
+
transformers
|