Spaces:
Runtime error
Runtime error
Update app.py
Browse files
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(
|
| 9 |
-
#
|
| 10 |
-
|
|
|
|
| 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
|
| 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
|