Spaces:
Sleeping
Sleeping
File size: 1,546 Bytes
2ca514e a107c25 dcd33cc a107c25 dcd33cc 6e03d9a 23c65d1 a107c25 2ca514e 6e03d9a 2ca514e a107c25 2ca514e a107c25 23c65d1 dcd33cc 4bb17c2 a107c25 23c65d1 dcd33cc a107c25 4bb17c2 e0f3ea8 4bb17c2 a107c25 e0f3ea8 2ca514e | 1 2 3 4 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 38 39 40 41 42 43 44 45 46 47 48 49 | 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() |