Omnibus commited on
Commit
d1db311
·
1 Parent(s): 968d89a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -5
app.py CHANGED
@@ -9,6 +9,7 @@ from moviepy.video.io.ffmpeg_tools import ffmpeg_extract_subclip
9
  import moviepy.video.io.ImageSequenceClip
10
 
11
  uid=uuid.uuid4()
 
12
  if not os.path.exists(f'{uid}-frames'): os.makedirs(f'{uid}-frames')
13
  if not os.path.exists(f'{uid}-rembg'): os.makedirs(f'{uid}-rembg')
14
 
@@ -109,11 +110,11 @@ def dl(inp):
109
  inp_out=inp.replace("https://","")
110
  inp_out=inp_out.replace("/","_").replace(".","_")
111
  os.system(f'yt-dlp "{inp}" --trim-filenames 100 -o "{inp_out}.mp4"')
112
- out = f"{inp_out}.mp4"
113
  except Exception as e:
114
  print (e)
115
  out = None
116
- return out,out,out,out
117
 
118
  def trim_vid(vid,start_time,end_time):
119
  print (vid)
@@ -125,7 +126,7 @@ def trim_vid(vid,start_time,end_time):
125
  end_sec=int(end_time.split(":",2)[2])
126
  start=start_hr+start_min+start_sec
127
  end=end_hr+end_min+end_sec
128
- #vid = f"{uid}-tmp.mp4"
129
  ffmpeg_extract_subclip(vid, start, end, targetname=f"{uid}-clip.mp4")
130
  out= f"{uid}-clip.mp4"
131
  return out,out
@@ -167,6 +168,7 @@ with gr.Blocks() as app:
167
  end_f = gr.Textbox(label = "End", value = "0:00:05", placeholder = "0:00:54")
168
  trim_btn=gr.Button("Trim")
169
  out_trim=gr.Video(format="mp4")
 
170
 
171
  with gr.Tab("Frames"):
172
  frame_btn = gr.Button("Get Frames")
@@ -194,10 +196,10 @@ with gr.Blocks() as app:
194
  def echo_fn(inp):
195
  return inp
196
  #outp_vid.change(echo_fn,outp_vid,[out_trim])
197
- trim_btn.click(trim_vid,[outp_vid,start_f,end_f],[out_trim,in_vid])
198
  outp_vid.change(load_video,outp_vid,[frame_count,fps]).then(echo_fn,outp_vid,[out_trim])
199
  frame_btn.click(capture_function,[out_trim],[frame_gal,frame_file])
200
  rem_btn.click(rem_bg,[out_trim],[rem_vid,frame_num,rem_bg_vid])
201
- go_btn.click(dl,inp_url,[outp_vid,outp_file,out_trim])
202
  app.load(fn=predict, inputs=[text_input,url_params], outputs=[text_output,text_input],_js=load_js)
203
  app.launch()
 
9
  import moviepy.video.io.ImageSequenceClip
10
 
11
  uid=uuid.uuid4()
12
+ if not os.path.exists(f'{uid}'): os.makedirs(f'{uid}')
13
  if not os.path.exists(f'{uid}-frames'): os.makedirs(f'{uid}-frames')
14
  if not os.path.exists(f'{uid}-rembg'): os.makedirs(f'{uid}-rembg')
15
 
 
110
  inp_out=inp.replace("https://","")
111
  inp_out=inp_out.replace("/","_").replace(".","_")
112
  os.system(f'yt-dlp "{inp}" --trim-filenames 100 -o "{inp_out}.mp4"')
113
+ out = f"{uid}/{inp_out}.mp4"
114
  except Exception as e:
115
  print (e)
116
  out = None
117
+ return out,out,out,out,out
118
 
119
  def trim_vid(vid,start_time,end_time):
120
  print (vid)
 
126
  end_sec=int(end_time.split(":",2)[2])
127
  start=start_hr+start_min+start_sec
128
  end=end_hr+end_min+end_sec
129
+ #vid = f"{inp_out}.mp4"
130
  ffmpeg_extract_subclip(vid, start, end, targetname=f"{uid}-clip.mp4")
131
  out= f"{uid}-clip.mp4"
132
  return out,out
 
168
  end_f = gr.Textbox(label = "End", value = "0:00:05", placeholder = "0:00:54")
169
  trim_btn=gr.Button("Trim")
170
  out_trim=gr.Video(format="mp4")
171
+ hid_box = gr.Textbox(visible=False)
172
 
173
  with gr.Tab("Frames"):
174
  frame_btn = gr.Button("Get Frames")
 
196
  def echo_fn(inp):
197
  return inp
198
  #outp_vid.change(echo_fn,outp_vid,[out_trim])
199
+ trim_btn.click(trim_vid,[hid_box,start_f,end_f],[out_trim,in_vid])
200
  outp_vid.change(load_video,outp_vid,[frame_count,fps]).then(echo_fn,outp_vid,[out_trim])
201
  frame_btn.click(capture_function,[out_trim],[frame_gal,frame_file])
202
  rem_btn.click(rem_bg,[out_trim],[rem_vid,frame_num,rem_bg_vid])
203
+ go_btn.click(dl,inp_url,[outp_vid,outp_file,out_trim,hid_box])
204
  app.load(fn=predict, inputs=[text_input,url_params], outputs=[text_output,text_input],_js=load_js)
205
  app.launch()