1littlecoder commited on
Commit
e966d07
·
verified ·
1 Parent(s): 86761b5

added video frames

Browse files
Files changed (1) hide show
  1. app.py +18 -5
app.py CHANGED
@@ -12,6 +12,7 @@ import openai
12
  # Set up Pixeltable database and table
13
  db_directory = "video_db"
14
  table_name = "video_table"
 
15
 
16
  # Define constants
17
  MAX_VIDEO_SIZE_MB = 35
@@ -164,16 +165,27 @@ def process_and_generate_post(video_file, social_media_type):
164
  )
165
  if sm_gen_flag:
166
  cur_video_df.update({"sm_post": social_media_post})
 
167
 
168
 
169
  print("######## processing thumbnail ##########")
170
 
171
- images = []
172
- for frame in FrameIterator(video=video_file, num_frames=4):
173
- images.append(frame['frame']) # frame['frame'] is a PIL image
174
 
 
 
175
 
176
- return cur_video_df["sm_post"], images
 
 
 
 
 
 
 
 
177
 
178
  except Exception as e:
179
  return f"An error occurred: {e}"
@@ -212,7 +224,8 @@ def gradio_interface():
212
 
213
  output = gr.Textbox(label="Generated Social Media Post", show_copy_button=True)
214
 
215
- thumbnail = gr.Gallery(label = "Pick your favorite Post Thumbnail", show_download_button= True, show_fullscreen_button= True,height= '400px')
 
216
 
217
  examples = gr.Examples(
218
  [["example1.mp4"], ["example2.mp4"],["example3.mp4"]], inputs=[video_input]
 
12
  # Set up Pixeltable database and table
13
  db_directory = "video_db"
14
  table_name = "video_table"
15
+ view_name = 'frames'
16
 
17
  # Define constants
18
  MAX_VIDEO_SIZE_MB = 35
 
165
  )
166
  if sm_gen_flag:
167
  cur_video_df.update({"sm_post": social_media_post})
168
+ sm_gen_flag = False
169
 
170
 
171
  print("######## processing thumbnail ##########")
172
 
173
+ # images = []
174
+ # for frame in FrameIterator(video=video_file, num_frames=4):
175
+ # images.append(frame['frame']) # frame['frame'] is a PIL image
176
 
177
+ if f"{db_directory}.{view_name}" in pxt.list_tables():
178
+ pxt.drop_table(f"{db_directory}.{view_name}")
179
 
180
+ frames_view = pxt.create_view(
181
+ f"{db_directory}.frames",
182
+ t,
183
+ iterator=FrameIterator.create(video=t.video, num_frames = 4)
184
+ )
185
+
186
+ frames = frames_view.select(frames_view.frame).collect()
187
+
188
+ return cur_video_df["sm_post"], [frame['frame'] for frame in frames]
189
 
190
  except Exception as e:
191
  return f"An error occurred: {e}"
 
224
 
225
  output = gr.Textbox(label="Generated Social Media Post", show_copy_button=True)
226
 
227
+ thumbnail = gr.Gallery(label = "Pick your favorite Post Thumbnail", show_download_button= True, show_fullscreen_button= True,
228
+ height= '400px')
229
 
230
  examples = gr.Examples(
231
  [["example1.mp4"], ["example2.mp4"],["example3.mp4"]], inputs=[video_input]