Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,21 +1,26 @@
|
|
| 1 |
-
import
|
| 2 |
-
|
| 3 |
-
from
|
| 4 |
-
import
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from PIL import Image,ImageDraw,ImageFont
|
| 2 |
+
import numpy as np
|
| 3 |
+
from ultralytics import YOLO
|
| 4 |
+
import streamlit as st
|
| 5 |
+
|
| 6 |
+
model = YOLO('HandSignDetector.pt')
|
| 7 |
+
font_size = 40
|
| 8 |
+
img = st.file_uploader('Choose an Image')
|
| 9 |
+
font = ImageFont.truetype("arial.ttf", size=font_size)
|
| 10 |
+
arr = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
|
| 11 |
+
|
| 12 |
+
if img is not None:
|
| 13 |
+
img = Image.open(img).resize((416,416)).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)
|
| 25 |
+
|
| 26 |
+
st.image(img,'Detected')
|