Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,16 +9,16 @@ def text_to_srt(text):
|
|
| 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 |
-
#
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
|
|
|
|
|
|
| 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:
|
|
@@ -26,9 +26,10 @@ def text_to_srt(text):
|
|
| 26 |
return temp_file_path
|
| 27 |
|
| 28 |
with gr.Blocks() as app:
|
| 29 |
-
gr.Markdown("
|
| 30 |
text_input = gr.TextArea(label="Enter text")
|
| 31 |
-
output = gr.File(label="Download SRT File", file_count="single")
|
| 32 |
text_input.change(fn=text_to_srt, inputs=text_input, outputs=output)
|
| 33 |
|
| 34 |
-
|
|
|
|
|
|
| 9 |
continue
|
| 10 |
try:
|
| 11 |
times, content = line.split(']', 1)
|
|
|
|
| 12 |
start, end = times[1:].split(' -> ')
|
| 13 |
+
# Check if the timestamp includes hours; if not, prepend "00:"
|
| 14 |
+
if start.count(":") == 1:
|
| 15 |
+
start = "00:" + start
|
| 16 |
+
if end.count(":") == 1:
|
| 17 |
+
end = "00:" + end
|
| 18 |
+
# Replace '.' with ',' in timestamps for SRT format
|
| 19 |
+
srt_content += f"{i+1}\n{start.replace('.', ',')} --> {end.replace('.', ',')}\n{content.strip()}\n\n"
|
| 20 |
except ValueError:
|
| 21 |
+
continue # Skip lines that don't match the expected format
|
|
|
|
| 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:
|
|
|
|
| 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")
|
| 32 |
text_input.change(fn=text_to_srt, inputs=text_input, outputs=output)
|
| 33 |
|
| 34 |
+
if __name__ == "__main__":
|
| 35 |
+
app.launch()
|