Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,58 +5,15 @@ import numpy as np
|
|
| 5 |
import tensorflow as tf
|
| 6 |
import streamlit as st
|
| 7 |
import tempfile
|
| 8 |
-
|
| 9 |
# Open the video file
|
| 10 |
f = st.file_uploader("Choose a Video")
|
| 11 |
-
|
| 12 |
-
if f is not None:
|
| 13 |
# Read the video file from the file-like object
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
# Get the frames per second (fps) of the video
|
| 22 |
-
fps = (cap.get(cv2.CAP_PROP_FPS))
|
| 23 |
-
st.write(fps)
|
| 24 |
-
|
| 25 |
-
# Calculate the interval to capture one frame per second
|
| 26 |
-
interval = int(round(fps/1))
|
| 27 |
-
|
| 28 |
-
# Initialize a counter for frames
|
| 29 |
-
frame_count = 0
|
| 30 |
-
model = tf.keras.models.load_model('HandSignClassifier (2).h5')
|
| 31 |
-
array = ['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','del','nothing','space']
|
| 32 |
-
out = ''
|
| 33 |
-
|
| 34 |
-
while True:
|
| 35 |
-
# Read the next fram
|
| 36 |
-
|
| 37 |
-
ret, frame = cap.read()
|
| 38 |
-
|
| 39 |
-
# Break the loop if the video is over
|
| 40 |
-
if not ret:
|
| 41 |
-
break
|
| 42 |
-
|
| 43 |
-
# Check if it's time to capture a frame
|
| 44 |
-
if frame_count % interval == 0:
|
| 45 |
-
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
|
| 46 |
-
frame = cv2.resize(frame, (256, 256)) # Resize to (28, 28)
|
| 47 |
-
frame = np.reshape(frame, (1, 256, 256, 3))
|
| 48 |
-
st.image(frame, 'input')# Reshape
|
| 49 |
-
pred = model.predict(frame)
|
| 50 |
-
st.write(pred)
|
| 51 |
-
pred = np.argmax(pred)
|
| 52 |
-
pred = array[pred]
|
| 53 |
-
if not out or out[-1] != pred:
|
| 54 |
-
out = out + pred
|
| 55 |
-
|
| 56 |
-
# Increment the frame counter
|
| 57 |
-
frame_count += 1
|
| 58 |
-
|
| 59 |
-
# Release the video capture object
|
| 60 |
-
cap.release()
|
| 61 |
-
|
| 62 |
-
st.write(out)
|
|
|
|
| 5 |
import tensorflow as tf
|
| 6 |
import streamlit as st
|
| 7 |
import tempfile
|
| 8 |
+
model = load_model('HandSignClassifier (2).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','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','del','nothing','space']if f is not None:
|
|
|
|
| 12 |
# Read the video file from the file-like object
|
| 13 |
+
img = Image.open(f)
|
| 14 |
+
img = img.resize((256,256))
|
| 15 |
+
img = np.reshape(img,(1,256,256,3))
|
| 16 |
+
pred = model.predict(img)
|
| 17 |
+
st.Image(img,use_column_width=True)
|
| 18 |
+
st.write(array[np.argmax(pred)])
|
| 19 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|