hardsub.ocr / app.py
Wahso's picture
Update app.py
6e03d9a verified
Raw
History Blame Contribute Delete
1.55 kB
import gradio as gr
def process_video(video, language):
# Sample subtitles
subtitles = [
["00:00:01", "00:00:04", "Hello and welcome"],
["00:00:05", "00:00:08", "This is video OCR test"],
["00:00:09", "00:00:12", f"Selected language: {language}"],
]
# Create SRT content
srt_content = ""
for i, sub in enumerate(subtitles, 1):
srt_content += f"{i}\n{sub[0]},000 --> {sub[1]},000\n{sub[2]}\n\n"
# Save SRT file
with open("subtitles.srt", "w", encoding="utf-8") as f:
f.write(srt_content)
return subtitles, "subtitles.srt"
# Create interface
with gr.Blocks(title="Video OCR", theme=gr.themes.Soft()) as demo:
gr.Markdown("# 🎬 Video Hardsub OCR")
gr.Markdown("Upload video and extract hardcoded subtitles")
with gr.Row():
with gr.Column():
video_input = gr.Video(label="Upload Video")
language = gr.Dropdown(
choices=["English", "Japanese", "Thai", "Chinese"],
label="OCR Language"
)
process_btn = gr.Button("Process Video", variant="primary")
with gr.Column():
subtitle_output = gr.Dataframe(
headers=["Start", "End", "Text"],
label="Extracted Subtitles"
)
file_output = gr.File(label="Download SRT")
process_btn.click(
fn=process_video,
inputs=[video_input, language],
outputs=[subtitle_output, file_output]
)
demo.launch()