Spaces:
Runtime error
Runtime error
File size: 1,136 Bytes
335cfd2 29b4b66 335cfd2 29b4b66 0e3fe63 335cfd2 220874c 591cf68 29b4b66 591cf68 29b4b66 9b27f70 591cf68 |
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 |
import gradio as gr
import base64
def text_to_srt(text):
lines = text.split('\n')
srt_content = ""
for i, line in enumerate(lines):
if line.strip() == "":
continue
try:
times, content = line.split(']', 1)
start, end = times[1:].split(' -> ')
srt_content += f"{i+1}\n{start.replace('.', ',')} --> {end.replace('.', ',')}\n{content.strip()}\n\n"
except ValueError:
continue # Skip lines that don't match the expected format
return srt_content
def download_srt(srt_content):
b64 = base64.b64encode(srt_content.encode()).decode()
return f'<a download="output.srt" href="data:text/srt;base64,{b64}">Download SRT</a>'
with gr.Blocks() as app:
gr.Markdown("### Text to SRT Converter")
text_input = gr.TextArea(label="Enter text in the specified format")
output = gr.TextArea(label="SRT Output")
download_button = gr.Button(label="Download SRT")
text_input.change(fn=text_to_srt, inputs=text_input, outputs=output)
download_button.click(fn=download_srt, inputs=output, outputs=download_button)
app.launch()
|