Win19840531 commited on
Commit
9bee04d
·
verified ·
1 Parent(s): fc0d433

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -2
app.py CHANGED
@@ -50,7 +50,8 @@ def reassemble_srt(subtitles):
50
 
51
  def process_file(file_obj, src_lang, tgt_lang, output_dir, error_log):
52
  try:
53
- raw_text = file_obj.read().decode("utf-8", errors="ignore")
 
54
  subtitles = parse_srt(raw_text)
55
  translated_subs = []
56
 
@@ -62,6 +63,7 @@ def process_file(file_obj, src_lang, tgt_lang, output_dir, error_log):
62
  output_path = os.path.join(output_dir, os.path.basename(file_obj.name))
63
  with open(output_path, "w", encoding="utf-8") as f:
64
  f.write(reassemble_srt(translated_subs))
 
65
  except Exception as e:
66
  error_log.append(f"File {file_obj.name} failed: {str(e)}\n{traceback.format_exc()}")
67
 
@@ -86,7 +88,6 @@ def batch_translate(files, src_lang, tgt_lang):
86
  zipf.write(log_path, arcname="log.txt")
87
  return zip_path
88
  except Exception as e:
89
- # fallback error
90
  fail_zip = os.path.join(tmp_dir, "fail.zip")
91
  with zipfile.ZipFile(fail_zip, 'w') as zipf:
92
  with open(os.path.join(tmp_dir, "log.txt"), "w") as logf:
 
50
 
51
  def process_file(file_obj, src_lang, tgt_lang, output_dir, error_log):
52
  try:
53
+ with open(file_obj.name, "r", encoding="utf-8", errors="ignore") as f:
54
+ raw_text = f.read()
55
  subtitles = parse_srt(raw_text)
56
  translated_subs = []
57
 
 
63
  output_path = os.path.join(output_dir, os.path.basename(file_obj.name))
64
  with open(output_path, "w", encoding="utf-8") as f:
65
  f.write(reassemble_srt(translated_subs))
66
+
67
  except Exception as e:
68
  error_log.append(f"File {file_obj.name} failed: {str(e)}\n{traceback.format_exc()}")
69
 
 
88
  zipf.write(log_path, arcname="log.txt")
89
  return zip_path
90
  except Exception as e:
 
91
  fail_zip = os.path.join(tmp_dir, "fail.zip")
92
  with zipfile.ZipFile(fail_zip, 'w') as zipf:
93
  with open(os.path.join(tmp_dir, "log.txt"), "w") as logf: