Spaces:
Running
on
A10G
Running
on
A10G
Update app.py
Browse files
app.py
CHANGED
@@ -6,7 +6,7 @@ import warnings, tempfile
|
|
6 |
from audio import gen_audio
|
7 |
warnings.filterwarnings("ignore")
|
8 |
warnings.simplefilter("ignore")
|
9 |
-
import time
|
10 |
|
11 |
videos = {
|
12 |
# "教學視頻1": "teach/00.mp4",
|
@@ -46,8 +46,43 @@ def get_video_url(option):
|
|
46 |
# print(videos[option])
|
47 |
return videos[option]
|
48 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
49 |
@spaces.GPU()
|
50 |
def evaluate_sign_language(user_video, standard_video_option):
|
|
|
|
|
|
|
51 |
tmp = tempfile.TemporaryDirectory()
|
52 |
tmpdir = tmp.name
|
53 |
new_path = tmpdir + "/user.mp4"
|
|
|
6 |
from audio import gen_audio
|
7 |
warnings.filterwarnings("ignore")
|
8 |
warnings.simplefilter("ignore")
|
9 |
+
import time, cv2, os
|
10 |
|
11 |
videos = {
|
12 |
# "教學視頻1": "teach/00.mp4",
|
|
|
46 |
# print(videos[option])
|
47 |
return videos[option]
|
48 |
|
49 |
+
def flip_video_horizontally(video_path):
|
50 |
+
if not os.path.exists(video_path):
|
51 |
+
print(f"Error: {video_path} does not exist.")
|
52 |
+
return
|
53 |
+
|
54 |
+
cap = cv2.VideoCapture(video_path)
|
55 |
+
if not cap.isOpened():
|
56 |
+
print(f"Error: cannot open {video_path}.")
|
57 |
+
return
|
58 |
+
|
59 |
+
frame_width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
|
60 |
+
frame_height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
|
61 |
+
fps = int(cap.get(cv2.CAP_PROP_FPS))
|
62 |
+
fourcc = int(cap.get(cv2.CAP_PROP_FOURCC))
|
63 |
+
|
64 |
+
temp_output_path = video_path + "_temp.mp4"
|
65 |
+
|
66 |
+
out = cv2.VideoWriter(temp_output_path, fourcc, fps, (frame_width, frame_height))
|
67 |
+
|
68 |
+
while True:
|
69 |
+
ret, frame = cap.read()
|
70 |
+
if not ret:
|
71 |
+
break
|
72 |
+
flipped_frame = cv2.flip(frame, 1)
|
73 |
+
out.write(flipped_frame)
|
74 |
+
|
75 |
+
cap.release()
|
76 |
+
out.release()
|
77 |
+
|
78 |
+
os.replace(temp_output_path, video_path)
|
79 |
+
print(f"Finished flipping video:{video_path}")
|
80 |
+
|
81 |
@spaces.GPU()
|
82 |
def evaluate_sign_language(user_video, standard_video_option):
|
83 |
+
if user_video.split('/')[-1].startswith("sample."):
|
84 |
+
flip_video_horizontally(user_video)
|
85 |
+
|
86 |
tmp = tempfile.TemporaryDirectory()
|
87 |
tmpdir = tmp.name
|
88 |
new_path = tmpdir + "/user.mp4"
|