Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,47 +4,49 @@ from PIL import Image
|
|
| 4 |
import numpy as np
|
| 5 |
import streamlit as st
|
| 6 |
|
| 7 |
-
# Replace 'your_video.mp4' with the path to your video file
|
| 8 |
# Open the video file
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
#
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
#
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
#
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
import numpy as np
|
| 5 |
import streamlit as st
|
| 6 |
|
|
|
|
| 7 |
# Open the video file
|
| 8 |
+
video_file = st.file_uploader("Choose a video file", type=["mp4"])
|
| 9 |
+
|
| 10 |
+
if video_file is not None:
|
| 11 |
+
# Read the video file from the file-like object
|
| 12 |
+
video_path = video_file.name
|
| 13 |
+
cap = cv2.VideoCapture(video_path)
|
| 14 |
+
|
| 15 |
+
# Get the frames per second (fps) of the video
|
| 16 |
+
fps = cap.get(cv2.CAP_PROP_FPS)
|
| 17 |
+
|
| 18 |
+
# Calculate the interval to capture one frame per second
|
| 19 |
+
interval = int(round(1 / fps))
|
| 20 |
+
|
| 21 |
+
# Initialize a counter for frames
|
| 22 |
+
frame_count = 0
|
| 23 |
+
model = load_model('HandSignClassifier.h5')
|
| 24 |
+
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']
|
| 25 |
+
out = ''
|
| 26 |
+
|
| 27 |
+
while True:
|
| 28 |
+
# Read the next frame
|
| 29 |
+
ret, frame = cap.read()
|
| 30 |
+
|
| 31 |
+
# Break the loop if the video is over
|
| 32 |
+
if not ret:
|
| 33 |
+
break
|
| 34 |
+
|
| 35 |
+
# Check if it's time to capture a frame
|
| 36 |
+
if frame_count % interval == 0:
|
| 37 |
+
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) # Convert to grayscale
|
| 38 |
+
frame = cv2.resize(frame, (28, 28)) # Resize to (28, 28)
|
| 39 |
+
frame = np.reshape(frame, (1, 28, 28, 1)) # Reshape
|
| 40 |
+
pred = model.predict(frame)
|
| 41 |
+
pred = np.argmax(pred)
|
| 42 |
+
pred = array[pred]
|
| 43 |
+
if not out or out[-1] != pred:
|
| 44 |
+
out = out + pred
|
| 45 |
+
|
| 46 |
+
# Increment the frame counter
|
| 47 |
+
frame_count += 1
|
| 48 |
+
|
| 49 |
+
# Release the video capture object
|
| 50 |
+
cap.release()
|
| 51 |
+
|
| 52 |
+
print(out)
|