Lenylvt commited on
Commit
29b4b66
·
verified ·
1 Parent(s): 591cf68

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -5
app.py CHANGED
@@ -1,4 +1,5 @@
1
  import gradio as gr
 
2
 
3
  def text_to_srt(text):
4
  lines = text.split('\n')
@@ -14,16 +15,16 @@ def text_to_srt(text):
14
  continue # Skip lines that don't match the expected format
15
  return srt_content
16
 
17
- def download_srt(output):
18
- with open("output.srt", "w") as file:
19
- file.write(output)
20
 
21
  with gr.Blocks() as app:
22
  gr.Markdown("### Text to SRT Converter")
23
  text_input = gr.TextArea(label="Enter text in the specified format")
24
  output = gr.TextArea(label="SRT Output")
25
- download_button = gr.Button(text="Download SRT", icon="download", onclick=download_srt, inputs=output)
26
-
27
  text_input.change(fn=text_to_srt, inputs=text_input, outputs=output)
 
28
 
29
  app.launch()
 
1
  import gradio as gr
2
+ import base64
3
 
4
  def text_to_srt(text):
5
  lines = text.split('\n')
 
15
  continue # Skip lines that don't match the expected format
16
  return srt_content
17
 
18
+ def download_srt(srt_content):
19
+ b64 = base64.b64encode(srt_content.encode()).decode()
20
+ return f'<a download="output.srt" href="data:text/srt;base64,{b64}">Download SRT</a>'
21
 
22
  with gr.Blocks() as app:
23
  gr.Markdown("### Text to SRT Converter")
24
  text_input = gr.TextArea(label="Enter text in the specified format")
25
  output = gr.TextArea(label="SRT Output")
26
+ download_button = gr.Button(label="Download SRT")
 
27
  text_input.change(fn=text_to_srt, inputs=text_input, outputs=output)
28
+ download_button.click(fn=download_srt, inputs=output, outputs=download_button)
29
 
30
  app.launch()