Lenylvt commited on
Commit
e775712
β€’
1 Parent(s): a28ebb1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -3
app.py CHANGED
@@ -40,7 +40,7 @@ def translate_srt(input_file, source_language_code, target_language_code):
40
  total_subs = len(subs)
41
  translated_subs = []
42
  progress_text = "Operation in progress. For information, the progress bar start when the translation begin."
43
- progress_bar = st.progress(0, text=progress_text) # Initialize the progress bar
44
 
45
  for idx, sub in enumerate(subs):
46
  translated_text = translate_text(sub.text, source_language_code, target_language_code)
@@ -48,7 +48,7 @@ def translate_srt(input_file, source_language_code, target_language_code):
48
  translated_subs.append(translated_sub)
49
  progress_bar.progress((idx + 1) / total_subs) # Update progress bar
50
 
51
- translated_file = pysrt.SubRipFile(translated_subs)
52
  progress_bar.empty() # Optionally clear the progress bar after completion
53
  return translated_file
54
 
@@ -74,10 +74,10 @@ if file_input is not None and source_language_code and target_language_code:
74
 
75
  translated_srt = translate_srt(temp_file_path, source_language_code, target_language_code)
76
 
 
77
  buffer = BytesIO()
78
  translated_srt.save(buffer, encoding='utf-8')
79
  buffer.seek(0)
80
-
81
  translated_srt_bytes = buffer.getvalue()
82
 
83
  st.download_button(
 
40
  total_subs = len(subs)
41
  translated_subs = []
42
  progress_text = "Operation in progress. For information, the progress bar start when the translation begin."
43
+ progress_bar = st.progress(0) # Initialize the progress bar
44
 
45
  for idx, sub in enumerate(subs):
46
  translated_text = translate_text(sub.text, source_language_code, target_language_code)
 
48
  translated_subs.append(translated_sub)
49
  progress_bar.progress((idx + 1) / total_subs) # Update progress bar
50
 
51
+ translated_file = pysrt.SubRipFile(items=translated_subs)
52
  progress_bar.empty() # Optionally clear the progress bar after completion
53
  return translated_file
54
 
 
74
 
75
  translated_srt = translate_srt(temp_file_path, source_language_code, target_language_code)
76
 
77
+ # Convert translated SRT to a string, then encode to bytes for download
78
  buffer = BytesIO()
79
  translated_srt.save(buffer, encoding='utf-8')
80
  buffer.seek(0)
 
81
  translated_srt_bytes = buffer.getvalue()
82
 
83
  st.download_button(