jpjp9292 commited on
Commit
ba9c126
ยท
verified ยท
1 Parent(s): 2492c20

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -26
app.py CHANGED
@@ -1,31 +1,34 @@
1
- from flask import Flask, render_template, request, redirect, url_for
2
- import os
 
3
 
4
- app = Flask(__name__)
5
- app.config['UPLOAD_FOLDER'] = 'uploads'
 
6
 
7
- if not os.path.exists(app.config['UPLOAD_FOLDER']):
8
- os.makedirs(app.config['UPLOAD_FOLDER'])
 
 
9
 
10
- @app.route('/')
11
- def index():
12
- return render_template('index.html')
 
 
 
13
 
14
- @app.route('/upload', methods=['POST'])
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
- if __name__ == '__main__':
31
- app.run(debug=True)
 
 
 
 
 
 
 
 
 
 
 
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()