Spaces:
Build error
Build error
update
Browse files
app.py
CHANGED
@@ -62,22 +62,16 @@ def generate_gifs(gif_transcript, words, words_timestamp):
|
|
62 |
print(f"type of words is :{type(words)}")
|
63 |
print(f"length of words is :{len(words)}")
|
64 |
print(f"giflist is :{giflist}")
|
65 |
-
|
66 |
-
#indx_tmp = [num for num in get_gif_word_indexes(words, giflist)]
|
67 |
-
#print(f"index temp is : {indx_tmp}")
|
68 |
giflist_indxs = list(list(get_gif_word_indexes(words, giflist))[0])
|
69 |
print(f"giflist_indxs is : {giflist_indxs}")
|
70 |
#getting start and end timestamps for a gif video
|
71 |
start_seconds, end_seconds = get_gif_timestamps(giflist_indxs, words_timestamp)
|
72 |
print(f"start_seconds, end_seconds are : ({start_seconds}, {end_seconds})")
|
73 |
#generated .gif image
|
74 |
-
|
75 |
im.save('./gifimage1.gif', save_all=True)
|
76 |
-
|
77 |
-
#gif_img = f"./gifimage.gif"
|
78 |
-
#html_out = "<img src= '" + gif_img + "' alt='create a gif from video' width='100%'/>"
|
79 |
-
#print("html out is :", html_out)
|
80 |
-
return gif_video_out #vid_cap #gif_vid
|
81 |
|
82 |
|
83 |
#calling the hosted model
|
@@ -124,14 +118,11 @@ def get_word_timestamps(timestamps):
|
|
124 |
#getting index of gif words in main transcript
|
125 |
def get_gif_word_indexes(total_words_list, gif_words_list):
|
126 |
if not gif_words_list:
|
127 |
-
print("THIS IS 1")
|
128 |
return
|
129 |
# just optimization
|
130 |
COUNT=0
|
131 |
lengthgif_words_list = len(gif_words_list)
|
132 |
-
print("THIS IS 2")
|
133 |
firstgif_words_list = gif_words_list[0]
|
134 |
-
print("THIS IS 3")
|
135 |
|
136 |
print(f"total_words_list is :{total_words_list}")
|
137 |
print(f"length of total_words_list is :{len(total_words_list)}")
|
@@ -140,12 +131,8 @@ def get_gif_word_indexes(total_words_list, gif_words_list):
|
|
140 |
|
141 |
for idx, item in enumerate(total_words_list):
|
142 |
COUNT+=1
|
143 |
-
#print("COUNT IS :", COUNT)
|
144 |
if item == firstgif_words_list:
|
145 |
-
print("THIS IS 5")
|
146 |
if total_words_list[idx:idx+lengthgif_words_list] == gif_words_list:
|
147 |
-
print("THIS IS 6")
|
148 |
-
print(f"value 1 is: {range(idx, idx+lengthgif_words_list)}")
|
149 |
print(f"value of tuple is : {tuple(range(idx, idx+lengthgif_words_list))}")
|
150 |
yield tuple(range(idx, idx+lengthgif_words_list))
|
151 |
|
@@ -153,13 +140,11 @@ def get_gif_word_indexes(total_words_list, gif_words_list):
|
|
153 |
#getting start and end timestamps for gif transcript
|
154 |
def get_gif_timestamps(giflist_indxs, words_timestamp):
|
155 |
print(f"******** Inside get_gif_timestamps() **********")
|
156 |
-
#giflist_indxs = list(list(get_gif_word_indexes(words, giflist))[0])
|
157 |
min_idx = min(giflist_indxs)
|
158 |
max_idx = max(giflist_indxs)
|
159 |
print(f"min_idx is :{min_idx}")
|
160 |
print(f"max_idx is :{max_idx}")
|
161 |
|
162 |
-
print(f"type of words_timestamp is :{type(words_timestamp)}")
|
163 |
gif_words_timestamp = words_timestamp[min_idx : max_idx+1]
|
164 |
print(f"words_timestamp is :{words_timestamp}")
|
165 |
print(f"gif_words_timestamp is :{gif_words_timestamp}")
|
@@ -174,26 +159,22 @@ def get_gif_timestamps(giflist_indxs, words_timestamp):
|
|
174 |
def gen_moviepy_gif(start_seconds, end_seconds):
|
175 |
print("******** inside moviepy_gif () ***************")
|
176 |
video_path = "./ShiaLaBeouf.mp4"
|
177 |
-
video = mp.VideoFileClip(video_path)
|
178 |
final_clip = video.subclip(start_seconds, end_seconds)
|
179 |
-
#final_clip.write_videofile("gifimage.mp4")
|
180 |
-
print("I am here now")
|
181 |
|
182 |
-
|
183 |
-
final_clip.write_gif("./gifimage.gif") #, program='ffmpeg', tempfiles=True, fps=15, fuzz=3)
|
184 |
final_clip.close()
|
185 |
|
186 |
-
|
187 |
-
gif_img
|
188 |
-
|
189 |
-
|
190 |
-
gif_vid = mp.VideoFileClip("gifimage.mp4")
|
191 |
|
192 |
-
im = Image.open("gifimage.gif")
|
193 |
-
vid_cap = cv2.VideoCapture('gifimage.mp4')
|
194 |
|
195 |
print("At the very end")
|
196 |
-
return im, gif_img, gif_vid, vid_cap,
|
197 |
|
198 |
|
199 |
# showing gif
|
@@ -229,16 +210,8 @@ with demo:
|
|
229 |
button_transcript = gr.Button("Generate transcripts")
|
230 |
button_gifs = gr.Button("Create Gif")
|
231 |
|
232 |
-
#def load_gif():
|
233 |
-
# print("****** inside load_gif() ******")
|
234 |
-
# #created embedding width='560' height='315'
|
235 |
-
# html_out = "<img src='./gifimage.gif' />"
|
236 |
-
# print(f"html output is : {html_out}")
|
237 |
-
# return
|
238 |
with gr.Row():
|
239 |
-
|
240 |
-
#gr.Markdown(""" [] """)
|
241 |
-
out_gif = gr.Image() #gr.Video()
|
242 |
|
243 |
button_transcript.click(generate_transcripts, input_video, [text_transcript, text_words, text_wordstimestamps ])
|
244 |
button_gifs.click(generate_gifs, [text_gif_transcript, text_words, text_wordstimestamps], out_gif )
|
|
|
62 |
print(f"type of words is :{type(words)}")
|
63 |
print(f"length of words is :{len(words)}")
|
64 |
print(f"giflist is :{giflist}")
|
65 |
+
|
|
|
|
|
66 |
giflist_indxs = list(list(get_gif_word_indexes(words, giflist))[0])
|
67 |
print(f"giflist_indxs is : {giflist_indxs}")
|
68 |
#getting start and end timestamps for a gif video
|
69 |
start_seconds, end_seconds = get_gif_timestamps(giflist_indxs, words_timestamp)
|
70 |
print(f"start_seconds, end_seconds are : ({start_seconds}, {end_seconds})")
|
71 |
#generated .gif image
|
72 |
+
gif_out = gen_moviepy_gif(start_seconds, end_seconds)
|
73 |
im.save('./gifimage1.gif', save_all=True)
|
74 |
+
return gif_out
|
|
|
|
|
|
|
|
|
75 |
|
76 |
|
77 |
#calling the hosted model
|
|
|
118 |
#getting index of gif words in main transcript
|
119 |
def get_gif_word_indexes(total_words_list, gif_words_list):
|
120 |
if not gif_words_list:
|
|
|
121 |
return
|
122 |
# just optimization
|
123 |
COUNT=0
|
124 |
lengthgif_words_list = len(gif_words_list)
|
|
|
125 |
firstgif_words_list = gif_words_list[0]
|
|
|
126 |
|
127 |
print(f"total_words_list is :{total_words_list}")
|
128 |
print(f"length of total_words_list is :{len(total_words_list)}")
|
|
|
131 |
|
132 |
for idx, item in enumerate(total_words_list):
|
133 |
COUNT+=1
|
|
|
134 |
if item == firstgif_words_list:
|
|
|
135 |
if total_words_list[idx:idx+lengthgif_words_list] == gif_words_list:
|
|
|
|
|
136 |
print(f"value of tuple is : {tuple(range(idx, idx+lengthgif_words_list))}")
|
137 |
yield tuple(range(idx, idx+lengthgif_words_list))
|
138 |
|
|
|
140 |
#getting start and end timestamps for gif transcript
|
141 |
def get_gif_timestamps(giflist_indxs, words_timestamp):
|
142 |
print(f"******** Inside get_gif_timestamps() **********")
|
|
|
143 |
min_idx = min(giflist_indxs)
|
144 |
max_idx = max(giflist_indxs)
|
145 |
print(f"min_idx is :{min_idx}")
|
146 |
print(f"max_idx is :{max_idx}")
|
147 |
|
|
|
148 |
gif_words_timestamp = words_timestamp[min_idx : max_idx+1]
|
149 |
print(f"words_timestamp is :{words_timestamp}")
|
150 |
print(f"gif_words_timestamp is :{gif_words_timestamp}")
|
|
|
159 |
def gen_moviepy_gif(start_seconds, end_seconds):
|
160 |
print("******** inside moviepy_gif () ***************")
|
161 |
video_path = "./ShiaLaBeouf.mp4"
|
162 |
+
video = mp.VideoFileClip(video_path)
|
163 |
final_clip = video.subclip(start_seconds, end_seconds)
|
|
|
|
|
164 |
|
165 |
+
final_clip.write_gif("gifimage.gif") #, program='ffmpeg', tempfiles=True, fps=15, fuzz=3)
|
|
|
166 |
final_clip.close()
|
167 |
|
168 |
+
#gif_img = mp.VideoFileClip("gifimage.gif")
|
169 |
+
#print(gif_img)
|
170 |
+
#gif_img.write_videofile("gifimage.mp4")
|
171 |
+
#gif_vid = mp.VideoFileClip("gifimage.mp4")
|
|
|
172 |
|
173 |
+
#im = Image.open("gifimage.gif")
|
174 |
+
#vid_cap = cv2.VideoCapture('gifimage.mp4')
|
175 |
|
176 |
print("At the very end")
|
177 |
+
return "gifimage.gif" #im, gif_img, gif_vid, vid_cap, #"gifimage.mp4"
|
178 |
|
179 |
|
180 |
# showing gif
|
|
|
210 |
button_transcript = gr.Button("Generate transcripts")
|
211 |
button_gifs = gr.Button("Create Gif")
|
212 |
|
|
|
|
|
|
|
|
|
|
|
|
|
213 |
with gr.Row():
|
214 |
+
out_gif = gr.Image()
|
|
|
|
|
215 |
|
216 |
button_transcript.click(generate_transcripts, input_video, [text_transcript, text_words, text_wordstimestamps ])
|
217 |
button_gifs.click(generate_gifs, [text_gif_transcript, text_words, text_wordstimestamps], out_gif )
|