Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,8 +1,6 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from PIL import Image
|
| 3 |
-
import requests
|
| 4 |
from transformers import DetrForObjectDetection, DetrFeatureExtractor
|
| 5 |
-
import
|
| 6 |
|
| 7 |
# ๋ชจ๋ธ๊ณผ ํผ์ฒ ์ถ์ถ๊ธฐ ๋ก๋
|
| 8 |
model_id = "facebook/detr-resnet-50"
|
|
@@ -10,24 +8,23 @@ model = DetrForObjectDetection.from_pretrained(model_id)
|
|
| 10 |
feature_extractor = DetrFeatureExtractor.from_pretrained(model_id)
|
| 11 |
|
| 12 |
def object_detection(image):
|
| 13 |
-
# ์ด๋ฏธ์ง
|
| 14 |
inputs = feature_extractor(images=image, return_tensors="pt")
|
| 15 |
-
# ๋ชจ๋ธ์ ์ฌ์ฉํ ์์ธก
|
| 16 |
outputs = model(**inputs)
|
| 17 |
|
| 18 |
-
#
|
| 19 |
-
#
|
| 20 |
-
#
|
| 21 |
-
|
| 22 |
-
return
|
| 23 |
|
| 24 |
-
# Gradio
|
| 25 |
iface = gr.Interface(
|
| 26 |
fn=object_detection,
|
| 27 |
-
inputs=gr.
|
| 28 |
-
outputs=
|
| 29 |
title="Object Detection with DETR",
|
| 30 |
-
description="Upload an image and the model will detect objects in the image."
|
| 31 |
)
|
| 32 |
|
| 33 |
iface.launch()
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
| 2 |
from transformers import DetrForObjectDetection, DetrFeatureExtractor
|
| 3 |
+
from PIL import Image
|
| 4 |
|
| 5 |
# ๋ชจ๋ธ๊ณผ ํผ์ฒ ์ถ์ถ๊ธฐ ๋ก๋
|
| 6 |
model_id = "facebook/detr-resnet-50"
|
|
|
|
| 8 |
feature_extractor = DetrFeatureExtractor.from_pretrained(model_id)
|
| 9 |
|
| 10 |
def object_detection(image):
|
| 11 |
+
# ์ด๋ฏธ์ง๋ฅผ ๋ชจ๋ธ์ด ์ฒ๋ฆฌํ ์ ์๋ ํํ๋ก ๋ณํ
|
| 12 |
inputs = feature_extractor(images=image, return_tensors="pt")
|
|
|
|
| 13 |
outputs = model(**inputs)
|
| 14 |
|
| 15 |
+
# ๊ฒฐ๊ณผ ์ฒ๋ฆฌ ๋ก์ง์ ๊ตฌํํ์ธ์.
|
| 16 |
+
# ์์ ์ฝ๋๋ ๊ฒฐ๊ณผ ์ฒ๋ฆฌ ๋ถ๋ถ์ ๋จ์ํํ๊ณ ์์ต๋๋ค.
|
| 17 |
+
# ์ค์ ๋ก๋ ํ์ง๋ ๊ฐ์ฒด๋ฅผ ์ด๋ฏธ์ง ์์ ๋ฐ์ค๋ก ๊ทธ๋ฆฌ๋ ๋ฑ์ ์ฒ๋ฆฌ๊ฐ ํ์ํ ์ ์์ต๋๋ค.
|
| 18 |
+
# ์ฌ๊ธฐ์๋ outputs์ ์์ฝ๋ ์ ๋ณด๋ง์ ๋ฐํํฉ๋๋ค.
|
| 19 |
+
return outputs.logits.tolist()
|
| 20 |
|
| 21 |
+
# Gradio ์ธํฐํ์ด์ค ์ค์ ๋ฐ ์ฑ ์คํ
|
| 22 |
iface = gr.Interface(
|
| 23 |
fn=object_detection,
|
| 24 |
+
inputs=gr.Image(type="pil", tool="editor"),
|
| 25 |
+
outputs=gr.Text(),
|
| 26 |
title="Object Detection with DETR",
|
| 27 |
+
description="Upload an image, and the model will detect objects in the image."
|
| 28 |
)
|
| 29 |
|
| 30 |
iface.launch()
|