Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,31 +1,34 @@
|
|
| 1 |
-
|
| 2 |
-
import
|
|
|
|
| 3 |
|
| 4 |
-
|
| 5 |
-
|
|
|
|
| 6 |
|
| 7 |
-
|
| 8 |
-
|
|
|
|
|
|
|
| 9 |
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
-
|
| 15 |
-
def upload_file():
|
| 16 |
-
if 'file' not in request.files:
|
| 17 |
-
return redirect(request.url)
|
| 18 |
-
|
| 19 |
-
file = request.files['file']
|
| 20 |
-
|
| 21 |
-
if file.filename == '':
|
| 22 |
-
return redirect(request.url)
|
| 23 |
-
|
| 24 |
-
if file:
|
| 25 |
-
filepath = os.path.join(app.config['UPLOAD_FOLDER'], file.filename)
|
| 26 |
-
file.save(filepath)
|
| 27 |
-
# ์ฌ๊ธฐ์ ํ์ผ ์ฒ๋ฆฌ ๋ก์ง์ ์ถ๊ฐํ ์ ์์ต๋๋ค.
|
| 28 |
-
return f'ํ์ผ์ด ์ฑ๊ณต์ ์ผ๋ก ์
๋ก๋ ๋์์ต๋๋ค: {filepath}'
|
| 29 |
|
| 30 |
-
|
| 31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
from PIL import Image, ImageDraw
|
| 4 |
|
| 5 |
+
# Hugging Face์์ YOLO ๋ชจ๋ธ์ ๋ก๋ํฉ๋๋ค.
|
| 6 |
+
model_name = "jameslahm/yolov10x"
|
| 7 |
+
yolo_model = pipeline('object-detection', model=model_name)
|
| 8 |
|
| 9 |
+
# ๊ฐ์ฒด ๊ฐ์ง์ ์ด๋ฏธ์ง ๊ทธ๋ฆฌ๊ธฐ ํจ์๋ฅผ ์ ์ํฉ๋๋ค.
|
| 10 |
+
def detect_objects(image):
|
| 11 |
+
# ๊ฐ์ฒด ๊ฐ์ง
|
| 12 |
+
results = yolo_model(image)
|
| 13 |
|
| 14 |
+
# ๊ฐ์ง๋ ๊ฐ์ฒด์ ๊ฒฝ๊ณ ์์ ๊ทธ๋ฆฌ๊ธฐ
|
| 15 |
+
draw = ImageDraw.Draw(image)
|
| 16 |
+
for obj in results:
|
| 17 |
+
box = obj['box']
|
| 18 |
+
draw.rectangle([box['xmin'], box['ymin'], box['xmax'], box['ymax']], outline="red", width=2)
|
| 19 |
+
draw.text((box['xmin'], box['ymin']), obj['label'], fill="red")
|
| 20 |
|
| 21 |
+
return results, image
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
+
# Gradio ์ธํฐํ์ด์ค ์ค์
|
| 24 |
+
iface = gr.Interface(
|
| 25 |
+
fn=detect_objects,
|
| 26 |
+
inputs=gr.Image(type="pil"),
|
| 27 |
+
outputs=[gr.JSON(), gr.Image(type="pil")],
|
| 28 |
+
title="YOLOv10x Object Detection",
|
| 29 |
+
description="Upload an image to detect objects using the YOLOv10x model. The results are shown in JSON and the image with bounding boxes."
|
| 30 |
+
)
|
| 31 |
+
|
| 32 |
+
# Gradio ์ธํฐํ์ด์ค ์คํ
|
| 33 |
+
if __name__ == "__main__":
|
| 34 |
+
iface.launch()
|