Upload google_colabs/gradio_app.py with huggingface_hub
Browse files- google_colabs/gradio_app.py +36 -9
google_colabs/gradio_app.py
CHANGED
|
@@ -26,11 +26,13 @@ sys.path.insert(0, os.path.join(PROJECT_ROOT, 'backend'))
|
|
| 26 |
from backend import config
|
| 27 |
from backend.config import InpaintMode
|
| 28 |
from backend.main import SubtitleRemover
|
|
|
|
| 29 |
|
| 30 |
|
| 31 |
def process_video(
|
| 32 |
video_file,
|
| 33 |
algorithm,
|
|
|
|
| 34 |
sttn_skip_detection,
|
| 35 |
sttn_max_load,
|
| 36 |
lama_super_fast,
|
|
@@ -40,9 +42,9 @@ def process_video(
|
|
| 40 |
diffueraser_max_load,
|
| 41 |
progress=gr.Progress()
|
| 42 |
):
|
| 43 |
-
"""Process video to remove subtitles"""
|
| 44 |
if video_file is None:
|
| 45 |
-
return None, "β Please upload a video first"
|
| 46 |
|
| 47 |
try:
|
| 48 |
progress(0, desc="Initializing...")
|
|
@@ -87,14 +89,32 @@ def process_video(
|
|
| 87 |
remover = SubtitleRemover(video_path, gui_mode=False)
|
| 88 |
remover.run()
|
| 89 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
progress(1.0, desc="Complete!")
|
| 91 |
|
| 92 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 93 |
|
| 94 |
except Exception as e:
|
| 95 |
import traceback
|
| 96 |
error_msg = f"β Error: {str(e)}\n\n{traceback.format_exc()}"
|
| 97 |
-
return None, error_msg
|
| 98 |
|
| 99 |
|
| 100 |
def create_interface():
|
|
@@ -129,6 +149,12 @@ def create_interface():
|
|
| 129 |
info="STTN: Fastest. DiffuEraser: Best quality (needs 12GB+ VRAM)."
|
| 130 |
)
|
| 131 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 132 |
with gr.Accordion("βοΈ Advanced Settings", open=False):
|
| 133 |
with gr.Tab("STTN"):
|
| 134 |
sttn_skip = gr.Checkbox(
|
|
@@ -176,6 +202,7 @@ def create_interface():
|
|
| 176 |
with gr.Column():
|
| 177 |
# Output
|
| 178 |
video_output = gr.Video(label="β¨ Output Video")
|
|
|
|
| 179 |
status_output = gr.Textbox(label="π Status", lines=3)
|
| 180 |
|
| 181 |
gr.Markdown("""
|
|
@@ -196,23 +223,23 @@ def create_interface():
|
|
| 196 |
process_btn.click(
|
| 197 |
fn=process_video,
|
| 198 |
inputs=[
|
| 199 |
-
video_input, algorithm,
|
| 200 |
sttn_skip, sttn_max_load,
|
| 201 |
lama_fast,
|
| 202 |
sd_steps, sd_guidance,
|
| 203 |
diffueraser_steps, diffueraser_max_load
|
| 204 |
],
|
| 205 |
-
outputs=[video_output, status_output]
|
| 206 |
)
|
| 207 |
|
| 208 |
# Examples
|
| 209 |
gr.Examples(
|
| 210 |
examples=[
|
| 211 |
-
["STTN (Fast)", True, 40, False, 50, 7.5, 50, 40],
|
| 212 |
-
["DiffuEraser (Recommended)", True, 80, False, 50, 7.5, 50, 40],
|
| 213 |
],
|
| 214 |
inputs=[
|
| 215 |
-
algorithm,
|
| 216 |
sttn_skip, sttn_max_load,
|
| 217 |
lama_fast,
|
| 218 |
sd_steps, sd_guidance,
|
|
|
|
| 26 |
from backend import config
|
| 27 |
from backend.config import InpaintMode
|
| 28 |
from backend.main import SubtitleRemover
|
| 29 |
+
from backend.subtitle_extractor import SubtitleExtractor
|
| 30 |
|
| 31 |
|
| 32 |
def process_video(
|
| 33 |
video_file,
|
| 34 |
algorithm,
|
| 35 |
+
extract_subtitles,
|
| 36 |
sttn_skip_detection,
|
| 37 |
sttn_max_load,
|
| 38 |
lama_super_fast,
|
|
|
|
| 42 |
diffueraser_max_load,
|
| 43 |
progress=gr.Progress()
|
| 44 |
):
|
| 45 |
+
"""Process video to remove subtitles and optionally extract them"""
|
| 46 |
if video_file is None:
|
| 47 |
+
return None, None, "β Please upload a video first"
|
| 48 |
|
| 49 |
try:
|
| 50 |
progress(0, desc="Initializing...")
|
|
|
|
| 89 |
remover = SubtitleRemover(video_path, gui_mode=False)
|
| 90 |
remover.run()
|
| 91 |
|
| 92 |
+
srt_file = None
|
| 93 |
+
|
| 94 |
+
# Extract subtitles if requested
|
| 95 |
+
if extract_subtitles:
|
| 96 |
+
progress(0.8, desc="Extracting subtitles...")
|
| 97 |
+
try:
|
| 98 |
+
extractor = SubtitleExtractor(video_path)
|
| 99 |
+
srt_file = extractor.extract_to_srt(
|
| 100 |
+
progress_callback=lambda p, desc: progress(0.8 + p * 0.2, desc)
|
| 101 |
+
)
|
| 102 |
+
except Exception as e:
|
| 103 |
+
print(f"Warning: Subtitle extraction failed: {e}")
|
| 104 |
+
srt_file = None
|
| 105 |
+
|
| 106 |
progress(1.0, desc="Complete!")
|
| 107 |
|
| 108 |
+
status_msg = f"β
Success! Processed with {algorithm}"
|
| 109 |
+
if srt_file:
|
| 110 |
+
status_msg += f"\nπ Subtitles extracted to SRT file"
|
| 111 |
+
|
| 112 |
+
return remover.video_out_name, srt_file, status_msg
|
| 113 |
|
| 114 |
except Exception as e:
|
| 115 |
import traceback
|
| 116 |
error_msg = f"β Error: {str(e)}\n\n{traceback.format_exc()}"
|
| 117 |
+
return None, None, error_msg
|
| 118 |
|
| 119 |
|
| 120 |
def create_interface():
|
|
|
|
| 149 |
info="STTN: Fastest. DiffuEraser: Best quality (needs 12GB+ VRAM)."
|
| 150 |
)
|
| 151 |
|
| 152 |
+
extract_subs = gr.Checkbox(
|
| 153 |
+
label="π Extract Subtitles to SRT",
|
| 154 |
+
value=False,
|
| 155 |
+
info="Extract detected subtitles using OCR and save as SRT file"
|
| 156 |
+
)
|
| 157 |
+
|
| 158 |
with gr.Accordion("βοΈ Advanced Settings", open=False):
|
| 159 |
with gr.Tab("STTN"):
|
| 160 |
sttn_skip = gr.Checkbox(
|
|
|
|
| 202 |
with gr.Column():
|
| 203 |
# Output
|
| 204 |
video_output = gr.Video(label="β¨ Output Video")
|
| 205 |
+
srt_output = gr.File(label="π Extracted Subtitles (SRT)", visible=True)
|
| 206 |
status_output = gr.Textbox(label="π Status", lines=3)
|
| 207 |
|
| 208 |
gr.Markdown("""
|
|
|
|
| 223 |
process_btn.click(
|
| 224 |
fn=process_video,
|
| 225 |
inputs=[
|
| 226 |
+
video_input, algorithm, extract_subs,
|
| 227 |
sttn_skip, sttn_max_load,
|
| 228 |
lama_fast,
|
| 229 |
sd_steps, sd_guidance,
|
| 230 |
diffueraser_steps, diffueraser_max_load
|
| 231 |
],
|
| 232 |
+
outputs=[video_output, srt_output, status_output]
|
| 233 |
)
|
| 234 |
|
| 235 |
# Examples
|
| 236 |
gr.Examples(
|
| 237 |
examples=[
|
| 238 |
+
["STTN (Fast)", False, True, 40, False, 50, 7.5, 50, 40],
|
| 239 |
+
["DiffuEraser (Recommended)", True, True, 80, False, 50, 7.5, 50, 40],
|
| 240 |
],
|
| 241 |
inputs=[
|
| 242 |
+
algorithm, extract_subs,
|
| 243 |
sttn_skip, sttn_max_load,
|
| 244 |
lama_fast,
|
| 245 |
sd_steps, sd_guidance,
|