Beasto commited on
Commit
8c1fa71
·
verified ·
1 Parent(s): 86c90cd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -21
app.py CHANGED
@@ -1,21 +1,26 @@
1
- import cv2
2
- from tensorflow.keras.models import load_model
3
- from PIL import Image
4
- import numpy as np
5
- import tensorflow as tf
6
- import streamlit as st
7
- import tempfile
8
- model = load_model('HandSignClassifierGUD.h5')
9
- # Open the video file
10
- f = st.file_uploader("Choose a Video")
11
- array = ['a','b','c','d','e','f','g','h','i','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y']
12
- # Read the video file from the file-like object
13
- if f is not None:
14
- img = Image.open(f)
15
- img = img.resize((28,28))
16
- img = img.convert('L')
17
- img = np.reshape(img,(1,28,28,1))
18
- pred = model.predict(img)
19
- st.image(img,use_column_width=True)
20
- st.write(array[np.argmax(pred)])
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')