Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,37 +1,67 @@
|
|
| 1 |
-
import
|
| 2 |
-
import subprocess
|
| 3 |
import cv2
|
| 4 |
import numpy as np
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
|
|
|
| 2 |
import cv2
|
| 3 |
import numpy as np
|
| 4 |
+
import os
|
| 5 |
+
import tempfile
|
| 6 |
+
import subprocess
|
| 7 |
+
|
| 8 |
+
def process_video(video, x1, y1, x2, y2):
|
| 9 |
+
temp_dir = tempfile.mkdtemp()
|
| 10 |
+
|
| 11 |
+
input_video = video
|
| 12 |
+
frames_dir = os.path.join(temp_dir, "frames")
|
| 13 |
+
os.makedirs(frames_dir, exist_ok=True)
|
| 14 |
+
|
| 15 |
+
# 1) Extraire les frames (FPS réduit)
|
| 16 |
+
subprocess.run([
|
| 17 |
+
"ffmpeg", "-i", input_video,
|
| 18 |
+
"-vf", "fps=10",
|
| 19 |
+
f"{frames_dir}/frame_%04d.png"
|
| 20 |
+
], check=True)
|
| 21 |
+
|
| 22 |
+
# 2) Inpainting image par image
|
| 23 |
+
for frame_name in sorted(os.listdir(frames_dir)):
|
| 24 |
+
frame_path = os.path.join(frames_dir, frame_name)
|
| 25 |
+
img = cv2.imread(frame_path)
|
| 26 |
+
|
| 27 |
+
mask = np.zeros(img.shape[:2], dtype=np.uint8)
|
| 28 |
+
mask[int(y1):int(y2), int(x1):int(x2)] = 255
|
| 29 |
+
mask = cv2.dilate(mask, np.ones((3,3), np.uint8), iterations=1)
|
| 30 |
+
|
| 31 |
+
result = cv2.inpaint(img, mask, 3, cv2.INPAINT_TELEA)
|
| 32 |
+
cv2.imwrite(frame_path, result)
|
| 33 |
+
|
| 34 |
+
# 3) Réassembler la vidéo (sans audio)
|
| 35 |
+
output_video = os.path.join(temp_dir, "output.mp4")
|
| 36 |
+
subprocess.run([
|
| 37 |
+
"ffmpeg", "-y",
|
| 38 |
+
"-framerate", "10",
|
| 39 |
+
"-i", f"{frames_dir}/frame_%04d.png",
|
| 40 |
+
"-c:v", "libx264",
|
| 41 |
+
"-pix_fmt", "yuv420p",
|
| 42 |
+
output_video
|
| 43 |
+
], check=True)
|
| 44 |
+
|
| 45 |
+
return output_video
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
with gr.Blocks() as demo:
|
| 49 |
+
gr.Markdown("## 🎥 Suppression de texte sur vidéo (100 % gratuit)")
|
| 50 |
+
|
| 51 |
+
video = gr.Video(label="Vidéo (max 30–60 s)")
|
| 52 |
+
with gr.Row():
|
| 53 |
+
x1 = gr.Number(label="X1")
|
| 54 |
+
y1 = gr.Number(label="Y1")
|
| 55 |
+
x2 = gr.Number(label="X2")
|
| 56 |
+
y2 = gr.Number(label="Y2")
|
| 57 |
+
|
| 58 |
+
btn = gr.Button("Supprimer le texte")
|
| 59 |
+
output = gr.Video(label="Vidéo finale")
|
| 60 |
+
|
| 61 |
+
btn.click(
|
| 62 |
+
process_video,
|
| 63 |
+
inputs=[video, x1, y1, x2, y2],
|
| 64 |
+
outputs=output
|
| 65 |
+
)
|
| 66 |
+
|
| 67 |
+
demo.launch()
|