Spaces:
Runtime error
Runtime error
Commit
·
c5c5b54
1
Parent(s):
d15b1fa
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from transformers import DetrFeatureExtractor, DetrForObjectDetection
|
| 2 |
+
from PIL import Image
|
| 3 |
+
import requests
|
| 4 |
+
import gradio as gr
|
| 5 |
+
|
| 6 |
+
def object_classify(img):
|
| 7 |
+
feature_extractor = DetrFeatureExtractor.from_pretrained('facebook/detr-resnet-50')
|
| 8 |
+
model = DetrForObjectDetection.from_pretrained('facebook/detr-resnet-50')
|
| 9 |
+
|
| 10 |
+
inputs = feature_extractor(images=img, return_tensors="pt")
|
| 11 |
+
outputs = model(**inputs)
|
| 12 |
+
# model predicts bounding boxes and corresponding COCO classes
|
| 13 |
+
logits = outputs.logits
|
| 14 |
+
bboxes = outputs.pred_boxes
|
| 15 |
+
return logits, bboxes
|
| 16 |
+
|
| 17 |
+
interface=gr.Interface(fn=imgtrans,
|
| 18 |
+
inputs=gr.inputs.Image(shape=(224,224),label='Insert Image'),
|
| 19 |
+
outputs=[gr.outputs.Textbox()],
|
| 20 |
+
examples = [],description='??')
|
| 21 |
+
interface.launch()
|