Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -9,19 +9,25 @@ def text_to_srt(text):
|
|
9 |
continue
|
10 |
try:
|
11 |
times, content = line.split(']', 1)
|
|
|
12 |
start, end = times[1:].split(' -> ')
|
13 |
-
|
|
|
|
|
|
|
|
|
14 |
except ValueError:
|
15 |
-
|
|
|
16 |
# Save SRT content to a temporary file
|
17 |
temp_file_path = '/tmp/output.srt'
|
18 |
-
with open(temp_file_path, 'w') as file:
|
19 |
file.write(srt_content)
|
20 |
return temp_file_path
|
21 |
|
22 |
with gr.Blocks() as app:
|
23 |
-
gr.Markdown("
|
24 |
-
text_input = gr.TextArea(label="Enter text
|
25 |
output = gr.File(label="Download SRT File", file_count="single") # Change output to a File component
|
26 |
text_input.change(fn=text_to_srt, inputs=text_input, outputs=output)
|
27 |
|
|
|
9 |
continue
|
10 |
try:
|
11 |
times, content = line.split(']', 1)
|
12 |
+
# Splitting times by ' -> ' to get start and end times
|
13 |
start, end = times[1:].split(' -> ')
|
14 |
+
# Replacing '.' with ',' for milliseconds and ensuring the time format is correct
|
15 |
+
start_formatted = start.replace('.', ',')
|
16 |
+
end_formatted = end.replace('.', ',')
|
17 |
+
# Adding the subtitle entry to the SRT content
|
18 |
+
srt_content += f"{i+1}\n{start_formatted} --> {end_formatted}\n{content.strip()}\n\n"
|
19 |
except ValueError:
|
20 |
+
# Skip lines that don't match the expected format
|
21 |
+
continue
|
22 |
# Save SRT content to a temporary file
|
23 |
temp_file_path = '/tmp/output.srt'
|
24 |
+
with open(temp_file_path, 'w', encoding='utf-8') as file:
|
25 |
file.write(srt_content)
|
26 |
return temp_file_path
|
27 |
|
28 |
with gr.Blocks() as app:
|
29 |
+
gr.Markdown("# Text to SRT Converter")
|
30 |
+
text_input = gr.TextArea(label="Enter text")
|
31 |
output = gr.File(label="Download SRT File", file_count="single") # Change output to a File component
|
32 |
text_input.change(fn=text_to_srt, inputs=text_input, outputs=output)
|
33 |
|