Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,8 +5,6 @@ import tempfile
|
|
| 5 |
import subprocess
|
| 6 |
import os
|
| 7 |
|
| 8 |
-
selection_box = [0, 0, 0, 0]
|
| 9 |
-
|
| 10 |
def extract_preview(video):
|
| 11 |
temp_dir = tempfile.mkdtemp()
|
| 12 |
frame_path = os.path.join(temp_dir, "preview.png")
|
|
@@ -22,15 +20,16 @@ def extract_preview(video):
|
|
| 22 |
return frame_path
|
| 23 |
|
| 24 |
|
| 25 |
-
def
|
| 26 |
-
global selection_box
|
| 27 |
(x1, y1), (x2, y2) = evt.index
|
| 28 |
-
|
| 29 |
-
|
| 30 |
|
|
|
|
|
|
|
|
|
|
| 31 |
|
| 32 |
-
|
| 33 |
-
x1, y1, x2, y2 = selection_box
|
| 34 |
|
| 35 |
temp_dir = tempfile.mkdtemp()
|
| 36 |
frames_dir = os.path.join(temp_dir, "frames")
|
|
@@ -70,9 +69,9 @@ with gr.Blocks() as demo:
|
|
| 70 |
gr.Markdown("## 🎥 Suppression de texte sur vidéo")
|
| 71 |
|
| 72 |
video = gr.Video(label="Upload vidéo (≤ 60s)")
|
| 73 |
-
preview = gr.Image(label="
|
| 74 |
|
| 75 |
-
|
| 76 |
|
| 77 |
btn_preview = gr.Button("Afficher une image")
|
| 78 |
btn_process = gr.Button("Supprimer le texte")
|
|
@@ -80,7 +79,7 @@ with gr.Blocks() as demo:
|
|
| 80 |
output = gr.Video(label="Vidéo finale")
|
| 81 |
|
| 82 |
btn_preview.click(extract_preview, video, preview)
|
| 83 |
-
preview.select(
|
| 84 |
-
btn_process.click(process_video, video, output)
|
| 85 |
|
| 86 |
demo.launch()
|
|
|
|
| 5 |
import subprocess
|
| 6 |
import os
|
| 7 |
|
|
|
|
|
|
|
| 8 |
def extract_preview(video):
|
| 9 |
temp_dir = tempfile.mkdtemp()
|
| 10 |
frame_path = os.path.join(temp_dir, "preview.png")
|
|
|
|
| 20 |
return frame_path
|
| 21 |
|
| 22 |
|
| 23 |
+
def save_selection(evt: gr.SelectData):
|
|
|
|
| 24 |
(x1, y1), (x2, y2) = evt.index
|
| 25 |
+
return [int(x1), int(y1), int(x2), int(y2)]
|
| 26 |
+
|
| 27 |
|
| 28 |
+
def process_video(video, box):
|
| 29 |
+
if box is None:
|
| 30 |
+
raise gr.Error("Aucune zone sélectionnée")
|
| 31 |
|
| 32 |
+
x1, y1, x2, y2 = box
|
|
|
|
| 33 |
|
| 34 |
temp_dir = tempfile.mkdtemp()
|
| 35 |
frames_dir = os.path.join(temp_dir, "frames")
|
|
|
|
| 69 |
gr.Markdown("## 🎥 Suppression de texte sur vidéo")
|
| 70 |
|
| 71 |
video = gr.Video(label="Upload vidéo (≤ 60s)")
|
| 72 |
+
preview = gr.Image(label="Sélectionne la zone à supprimer", interactive=True)
|
| 73 |
|
| 74 |
+
selection_state = gr.State(None)
|
| 75 |
|
| 76 |
btn_preview = gr.Button("Afficher une image")
|
| 77 |
btn_process = gr.Button("Supprimer le texte")
|
|
|
|
| 79 |
output = gr.Video(label="Vidéo finale")
|
| 80 |
|
| 81 |
btn_preview.click(extract_preview, video, preview)
|
| 82 |
+
preview.select(save_selection, None, selection_state)
|
| 83 |
+
btn_process.click(process_video, [video, selection_state], output)
|
| 84 |
|
| 85 |
demo.launch()
|