import gradio as gr import os 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 # Save SRT content to a temporary file temp_file_path = '/tmp/output.srt' with open(temp_file_path, 'w') as file: file.write(srt_content) return temp_file_path with gr.Blocks() as app: gr.Markdown("### Text to SRT Converter") text_input = gr.TextArea(label="Enter text from Whisper Jax Space") output = gr.File(label="Download SRT File", file_count="single") # Change output to a File component text_input.change(fn=text_to_srt, inputs=text_input, outputs=output) app.launch(share=True)