Lenylvt commited on
Commit
335cfd2
1 Parent(s): 8e51672

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -0
app.py ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+
3
+ def text_to_srt(text):
4
+ lines = text.split('\n')
5
+ srt_content = ""
6
+ for i, line in enumerate(lines):
7
+ if line.strip() == "":
8
+ continue
9
+ try:
10
+ times, content = line.split(']', 1)
11
+ start, end = times[1:].split(' -> ')
12
+ srt_content += f"{i+1}\n{start.replace('.', ',')} --> {end.replace('.', ',')}\n{content.strip()}\n\n"
13
+ except ValueError:
14
+ continue # Skip lines that don't match the expected format
15
+ return srt_content
16
+
17
+ with gr.Blocks() as app:
18
+ gr.Markdown("### Text to SRT Converter")
19
+ text_input = gr.TextArea(label="Enter text in the specified format")
20
+ output = gr.TextArea(label="SRT Output")
21
+ text_input.change(fn=text_to_srt, inputs=text_input, outputs=output)
22
+
23
+ app.launch()