Beasto commited on
Commit
b8b003e
·
verified ·
1 Parent(s): 382912a

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -0
app.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from PIL import Image,ImageDraw,ImageFont
2
+ import numpy as np
3
+ from ultralytics import YOLO
4
+ import atreamlit as st
5
+
6
+ model = YOLO('NarutoHandSignDetector.pt')
7
+ font_size = 40
8
+ img = st.file_uploader('Choose an Image')
9
+ font = ImageFont.truetype("arial.ttf", size=font_size)
10
+ arr = ['bird', 'boar', 'dog', 'dragon', 'hare', 'horse', 'monkey', 'ox', 'ram', 'rat', 'snake', 'tiger']
11
+
12
+ if img is not None:
13
+ img = Image.open(img).resize((640,640)).convert('RGB')
14
+ results = model(img)
15
+ for result in results:
16
+ for i in range(len(result.boxes.cls)):
17
+ cls = result.boxes.cls[i]
18
+ cls = arr[int(cls)]
19
+ lbl = result.boxes.conf[i]
20
+ boxes = result.boxes.xyxy[i]
21
+ draw = ImageDraw.Draw(img)
22
+ draw.rectangle([boxes[0], boxes[1], boxes[2], boxes[3]], outline="white", width=5)
23
+ text_position = (boxes[0]+boxes[2])/2, boxes[1]-10
24
+ draw.text(text_position, f'{cls} {lbl}', fill="red", font=font,spacing=10)
25
+
26
+ st.image(img,'Detected')