Spaces:
Sleeping
Sleeping
Commit
•
50e5689
1
Parent(s):
8ee563e
Create app.py (#2)
Browse files- Create app.py (cc6360f39b34625d87b9b95765e7817c2f21fcca)
Co-authored-by: Bilal Sardar <BilalSardar@users.noreply.huggingface.co>
app.py
ADDED
@@ -0,0 +1,97 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import cv2
|
2 |
+
import os
|
3 |
+
from moviepy.editor import *
|
4 |
+
import gradio as gr
|
5 |
+
import re
|
6 |
+
|
7 |
+
def parse_string(string, dataset):
|
8 |
+
parsed_list = []
|
9 |
+
start = 0
|
10 |
+
otherword=""
|
11 |
+
end = len(string)
|
12 |
+
while start < end:
|
13 |
+
max_chunk = ""
|
14 |
+
max_length = 0
|
15 |
+
for chunk in VideosNames:
|
16 |
+
if string.startswith(chunk.lower(), start) and len(chunk) > max_length:
|
17 |
+
max_chunk = chunk
|
18 |
+
max_length = len(chunk)
|
19 |
+
if max_chunk:
|
20 |
+
if len(max_chunk)>1:
|
21 |
+
parsed_list.append(max_chunk)
|
22 |
+
print(max_chunk)
|
23 |
+
else:
|
24 |
+
otherword+=max_chunk
|
25 |
+
start += len(max_chunk)
|
26 |
+
else:
|
27 |
+
parsed_list.append(otherword)
|
28 |
+
otherword=""
|
29 |
+
start += 1
|
30 |
+
return parsed_list
|
31 |
+
|
32 |
+
|
33 |
+
def remove_empty_values(lst):
|
34 |
+
return [x for x in lst if x and (not isinstance(x, (str, list, dict)) or x)]
|
35 |
+
|
36 |
+
|
37 |
+
def flatten_lists(lst):
|
38 |
+
flat_list = []
|
39 |
+
for i in lst:
|
40 |
+
if type(i) == list:
|
41 |
+
flat_list.extend(flatten_lists(i))
|
42 |
+
else:
|
43 |
+
flat_list.append(i)
|
44 |
+
return flat_list
|
45 |
+
|
46 |
+
|
47 |
+
|
48 |
+
path = 'dataset'
|
49 |
+
videos = []
|
50 |
+
VideosNames = []
|
51 |
+
myList = os.listdir(path)
|
52 |
+
print(myList)
|
53 |
+
for cu_video in myList:
|
54 |
+
current_Video = cv2.imread(f'{path}/{cu_video}')
|
55 |
+
videos.append(current_Video)
|
56 |
+
VideosNames.append((os.path.splitext(cu_video)[0]).replace("-"," ").lower())
|
57 |
+
print(VideosNames)
|
58 |
+
|
59 |
+
def texttoSign(text):
|
60 |
+
text=text+" "
|
61 |
+
text=text.lower()
|
62 |
+
text=re.sub('[^a-z]+', ' ', text)
|
63 |
+
framescount=0
|
64 |
+
listofwords=parse_string(text,VideosNames)
|
65 |
+
listofwords=remove_empty_values(listofwords)
|
66 |
+
index=0
|
67 |
+
for word in listofwords:
|
68 |
+
if word not in VideosNames:
|
69 |
+
listofwords[index]=(list(word))
|
70 |
+
index+=1
|
71 |
+
listofwords=flatten_lists(listofwords)
|
72 |
+
clips=[]
|
73 |
+
for i in range(len(listofwords)):
|
74 |
+
|
75 |
+
path="Dataset/"+(listofwords[i])+".mp4"
|
76 |
+
data=cv2.VideoCapture(path)
|
77 |
+
framescount = data.get(cv2.CAP_PROP_FRAME_COUNT)
|
78 |
+
fps = data.get(cv2.CAP_PROP_FPS)
|
79 |
+
seconds = round(framescount / fps)
|
80 |
+
clips.append(VideoFileClip(path))
|
81 |
+
clips[i]=clips[i].subclip(1, seconds/2)
|
82 |
+
|
83 |
+
result_clip=concatenate_videoclips(clips, method='compose')
|
84 |
+
result_clip.write_videofile("combined.mp4", fps=30)
|
85 |
+
return "combined.mp4"
|
86 |
+
# except:
|
87 |
+
# pass
|
88 |
+
|
89 |
+
|
90 |
+
demo=gr.Interface(fn=texttoSign,
|
91 |
+
inputs="text",
|
92 |
+
outputs="video",
|
93 |
+
title="Urdu Text To Sign",
|
94 |
+
description="This is a small text to sign language model based on Urdu sign langugae standards",
|
95 |
+
examples=[["good boy"]])
|
96 |
+
|
97 |
+
demo.launch(debug=True)
|