Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,8 +4,8 @@ import gradio as gr
|
|
| 4 |
# Initialize the InferenceClient with the Mixtral model
|
| 5 |
client = InferenceClient("mistralai/Mixtral-8x7B-Instruct-v0.1")
|
| 6 |
|
| 7 |
-
def translate_srt(
|
| 8 |
-
srt_content
|
| 9 |
translated_lines = []
|
| 10 |
|
| 11 |
# Split the SRT file into lines
|
|
@@ -16,19 +16,21 @@ def translate_srt(srt_file, source_lang, target_lang):
|
|
| 16 |
if line.strip().isdigit() or "-->" in line or line == "":
|
| 17 |
translated_lines.append(line)
|
| 18 |
else:
|
| 19 |
-
#
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
| 21 |
translated_text = response["generated_text"]
|
| 22 |
translated_lines.append(translated_text)
|
| 23 |
|
| 24 |
-
|
| 25 |
-
return translated_srt
|
| 26 |
|
| 27 |
# Define the Gradio interface
|
| 28 |
iface = gr.Interface(
|
| 29 |
fn=translate_srt,
|
| 30 |
inputs=[
|
| 31 |
-
gr.
|
| 32 |
gr.Textbox(label="Source Language (ISO Code)", placeholder="e.g., en for English"),
|
| 33 |
gr.Textbox(label="Target Language (ISO Code)", placeholder="e.g., es for Spanish")
|
| 34 |
],
|
|
|
|
| 4 |
# Initialize the InferenceClient with the Mixtral model
|
| 5 |
client = InferenceClient("mistralai/Mixtral-8x7B-Instruct-v0.1")
|
| 6 |
|
| 7 |
+
def translate_srt(srt_content, source_lang, target_lang):
|
| 8 |
+
# Assuming srt_content is now a string with the content of the SRT file
|
| 9 |
translated_lines = []
|
| 10 |
|
| 11 |
# Split the SRT file into lines
|
|
|
|
| 16 |
if line.strip().isdigit() or "-->" in line or line == "":
|
| 17 |
translated_lines.append(line)
|
| 18 |
else:
|
| 19 |
+
# Prepare the text for translation
|
| 20 |
+
formatted_prompt = f"Translate the following text from {source_lang} to {target_lang}: {line}"
|
| 21 |
+
# Using the Mixtral API for translation; adjust parameters as necessary
|
| 22 |
+
response = client(text=formatted_prompt)
|
| 23 |
+
# Assuming the response includes a 'generated_text' field with the translated text
|
| 24 |
translated_text = response["generated_text"]
|
| 25 |
translated_lines.append(translated_text)
|
| 26 |
|
| 27 |
+
return "\n".join(translated_lines)
|
|
|
|
| 28 |
|
| 29 |
# Define the Gradio interface
|
| 30 |
iface = gr.Interface(
|
| 31 |
fn=translate_srt,
|
| 32 |
inputs=[
|
| 33 |
+
gr.TextArea(label="SRT File Content"),
|
| 34 |
gr.Textbox(label="Source Language (ISO Code)", placeholder="e.g., en for English"),
|
| 35 |
gr.Textbox(label="Target Language (ISO Code)", placeholder="e.g., es for Spanish")
|
| 36 |
],
|