BilalSardar commited on
Commit
5b80433
1 Parent(s): 631ee60

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +88 -0
app.py ADDED
@@ -0,0 +1,88 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import cv2
2
+ import os
3
+ from moviepy.editor import *
4
+ import gradio as gr
5
+
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
+ listofwords=parse_string(text,VideosNames)
61
+ listofwords=remove_empty_values(listofwords)
62
+ index=0
63
+ for word in listofwords:
64
+ if word not in VideosNames:
65
+ listofwords[index]=(list(word))
66
+ index+=1
67
+ listofwords=flatten_lists(listofwords)
68
+ clips=[]
69
+ for i in range(len(listofwords)):
70
+
71
+ clips.append(VideoFileClip("Dataset/"+(listofwords[i])+".mp4"))
72
+ clips[i]=clips[i].subclip(1, 4)
73
+
74
+ result_clip=concatenate_videoclips(clips)
75
+ result_clip.write_videofile("combined.mp4")
76
+ return "combined.mp4"
77
+ # except:
78
+ # pass
79
+
80
+
81
+ demo=gr.Interface(fn=texttoSign,
82
+ inputs="text",
83
+ outputs="video",
84
+ title="Urdu Text To Sign",
85
+ description="This is a small text to sign language model based on Urdu sign langugae standards",
86
+ examples=[["good boy"]])
87
+
88
+ demo.launch(debug=True)