Lenylvt commited on
Commit
7c82987
·
verified ·
1 Parent(s): faab2de

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -5
app.py CHANGED
@@ -5,21 +5,21 @@ import re
5
  # Initialize the InferenceClient with the Mixtral model
6
  client = InferenceClient("mistralai/Mixtral-8x7B-Instruct-v0.1")
7
 
8
- def translate_srt(file, target_language):
9
- # Read the content of the SRT file
10
- srt_content = file.read().decode("utf-8")
 
11
  lines = srt_content.split('\n')
12
 
13
  translated_lines = []
14
  for line in lines:
15
- # Check if the line is a timestamp or a subtitle number
16
  if re.match(r"^\d+$", line) or re.match(r"^\d{2}:\d{2}:\d{2},\d{3} --> \d{2}:\d{2}:\d{2},\d{3}$", line):
17
  translated_lines.append(line) # Copy timestamps and numbers directly
18
  elif line.strip() == "":
19
  translated_lines.append(line) # Preserve empty lines for formatting
20
  else:
21
  # Translate the text line
22
- response = client(inputs=line, parameters={"target_language": target_language})
23
  translated_lines.append(response[0]["generated_text"])
24
 
25
  # Join the translated lines back into a single string
 
5
  # Initialize the InferenceClient with the Mixtral model
6
  client = InferenceClient("mistralai/Mixtral-8x7B-Instruct-v0.1")
7
 
8
+ def translate_srt(file_info, target_language):
9
+ # file_info is a dictionary containing information about the file
10
+ # including its content
11
+ srt_content = file_info["content"].decode("utf-8")
12
  lines = srt_content.split('\n')
13
 
14
  translated_lines = []
15
  for line in lines:
 
16
  if re.match(r"^\d+$", line) or re.match(r"^\d{2}:\d{2}:\d{2},\d{3} --> \d{2}:\d{2}:\d{2},\d{3}$", line):
17
  translated_lines.append(line) # Copy timestamps and numbers directly
18
  elif line.strip() == "":
19
  translated_lines.append(line) # Preserve empty lines for formatting
20
  else:
21
  # Translate the text line
22
+ response = client(inputs={"inputs": line, "parameters": {"target_language": target_language}})
23
  translated_lines.append(response[0]["generated_text"])
24
 
25
  # Join the translated lines back into a single string