NeuralFalcon commited on
Commit
2ade3a8
·
verified ·
1 Parent(s): d8f5169

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -10
app.py CHANGED
@@ -85,14 +85,14 @@ def remove_watermark(image, blur_type="strong_gaussian"):
85
 
86
 
87
 
88
- def process_frame(frame_path, save_path):
89
  image = cv2.imread(frame_path)
90
 
91
  if image is None:
92
  print(f"Failed to load: {frame_path}") # Debugging step
93
  return
94
 
95
- no_watermark_image = remove_watermark(image, blur_type="median")
96
 
97
  output_file = os.path.join(save_path, os.path.basename(frame_path))
98
  success = cv2.imwrite(output_file, no_watermark_image)
@@ -100,7 +100,7 @@ def process_frame(frame_path, save_path):
100
  if not success:
101
  print(f"Failed to save: {output_file}") # Debugging step
102
 
103
- def batch_process(batch_size=100):
104
  input_folder = "./frames"
105
  output_folder = "./clean"
106
 
@@ -111,7 +111,7 @@ def batch_process(batch_size=100):
111
  frame_paths = [os.path.join(input_folder, f) for f in os.listdir(input_folder) if f.endswith((".jpg", ".png"))]
112
 
113
  with ThreadPoolExecutor() as executor:
114
- executor.map(process_frame, frame_paths, [output_folder] * len(frame_paths))
115
 
116
  print(f"Processing complete! {len(frame_paths)} frames saved to {output_folder}")
117
 
@@ -255,11 +255,11 @@ def recover_audio(upload_path):
255
  if var2==0:
256
  return save_path
257
  return None
258
- def video_watermark_remover(video_path):
259
  global gpu
260
  upload_path=upload_file(video_path)
261
  extract_frames(upload_path, "./frames")
262
- batch_process(batch_size=100)
263
  vido_chunks(upload_path)
264
  marge_video(gpu=gpu)
265
  save_path=recover_audio(upload_path)
@@ -269,13 +269,18 @@ def video_watermark_remover(video_path):
269
  import gradio as gr
270
  import click
271
 
272
- def gradio_interface(video_file):
273
- vid_path=video_watermark_remover(video_file)
274
  return vid_path,vid_path
275
 
 
 
276
  demo = gr.Interface(
277
  fn=gradio_interface,
278
- inputs=gr.File(label="Upload Video"),
 
 
 
279
  outputs=[gr.File(label="Download Video"),gr.Video(label="Play Video")],
280
  title="Video Watermark Remover",
281
  description="Upload a video, and this tool will remove watermarks using blurring techniques."
@@ -289,4 +294,4 @@ demo = gr.Interface(
289
  def main(debug, share):
290
  demo.queue().launch(debug=debug, share=share)
291
  if __name__ == "__main__":
292
- main()
 
85
 
86
 
87
 
88
+ def process_frame(frame_path, save_path, blur_type):
89
  image = cv2.imread(frame_path)
90
 
91
  if image is None:
92
  print(f"Failed to load: {frame_path}") # Debugging step
93
  return
94
 
95
+ no_watermark_image = remove_watermark(image, blur_type=blur_type)
96
 
97
  output_file = os.path.join(save_path, os.path.basename(frame_path))
98
  success = cv2.imwrite(output_file, no_watermark_image)
 
100
  if not success:
101
  print(f"Failed to save: {output_file}") # Debugging step
102
 
103
+ def batch_process(blur_type="median", batch_size=100):
104
  input_folder = "./frames"
105
  output_folder = "./clean"
106
 
 
111
  frame_paths = [os.path.join(input_folder, f) for f in os.listdir(input_folder) if f.endswith((".jpg", ".png"))]
112
 
113
  with ThreadPoolExecutor() as executor:
114
+ executor.map(process_frame, frame_paths, [output_folder] * len(frame_paths), [blur_type] * len(frame_paths))
115
 
116
  print(f"Processing complete! {len(frame_paths)} frames saved to {output_folder}")
117
 
 
255
  if var2==0:
256
  return save_path
257
  return None
258
+ def video_watermark_remover(video_path, blur_type="median"):
259
  global gpu
260
  upload_path=upload_file(video_path)
261
  extract_frames(upload_path, "./frames")
262
+ batch_process(blur_type=blur_type)
263
  vido_chunks(upload_path)
264
  marge_video(gpu=gpu)
265
  save_path=recover_audio(upload_path)
 
269
  import gradio as gr
270
  import click
271
 
272
+ def gradio_interface(video_file, blur_type):
273
+ vid_path=video_watermark_remover(video_file, blur_type=blur_type)
274
  return vid_path,vid_path
275
 
276
+ blur_types = ["strong_gaussian", "median"]
277
+
278
  demo = gr.Interface(
279
  fn=gradio_interface,
280
+ inputs=[
281
+ gr.File(label="Upload Video"),
282
+ gr.Dropdown(choices=blur_types, label="Blur Type", value="strong_gaussian") # Default to median
283
+ ],
284
  outputs=[gr.File(label="Download Video"),gr.Video(label="Play Video")],
285
  title="Video Watermark Remover",
286
  description="Upload a video, and this tool will remove watermarks using blurring techniques."
 
294
  def main(debug, share):
295
  demo.queue().launch(debug=debug, share=share)
296
  if __name__ == "__main__":
297
+ main()