Lenylvt commited on
Commit
caf4087
1 Parent(s): b9c3b7b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -5
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
- srt_content += f"{i+1}\n{start.replace('.', ',')} --> {end.replace('.', ',')}\n{content.strip()}\n\n"
 
 
 
 
14
  except ValueError:
15
- continue # Skip lines that don't match the expected format
 
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("### Text to SRT Converter")
24
- text_input = gr.TextArea(label="Enter text from Whisper Jax Space")
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