Lenylvt commited on
Commit
591cf68
·
verified ·
1 Parent(s): 220874c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -17
app.py CHANGED
@@ -14,26 +14,16 @@ def text_to_srt(text):
14
  continue # Skip lines that don't match the expected format
15
  return srt_content
16
 
17
- def text_to_srt_file(text):
18
- srt_content = text_to_srt(text)
19
- file_path = "output.srt"
20
- with open(file_path, "w") as file:
21
- file.write(srt_content)
22
- return file_path
23
 
24
  with gr.Blocks() as app:
25
  gr.Markdown("### Text to SRT Converter")
26
  text_input = gr.TextArea(label="Enter text in the specified format")
27
- output = gr.TextArea(label="SRT Output", visible=False) # Hide the text area output
28
- download_btn = gr.File(label="Download SRT", visible=False) # Add download button
29
-
30
- def update_output(text):
31
- srt_content = text_to_srt(text)
32
- output.update(value=srt_content, visible=True)
33
- srt_file_path = text_to_srt_file(text)
34
- download_btn.update(value=srt_file_path, visible=True)
35
-
36
- text_input.change(fn=update_output, inputs=text_input, outputs=[output, download_btn])
37
 
38
- app.launch()
39
 
 
 
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()