Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,7 +2,6 @@ import pysrt
|
|
| 2 |
import gradio as gr
|
| 3 |
import pandas as pd
|
| 4 |
from transformers import MarianMTModel, MarianTokenizer
|
| 5 |
-
from tqdm import tqdm
|
| 6 |
|
| 7 |
# Fetch and parse language options from the provided URL
|
| 8 |
url = "https://huggingface.co/Lenylvt/LanguageISO/resolve/main/iso.md"
|
|
@@ -34,30 +33,34 @@ def translate_text(text, source_language_code, target_language_code):
|
|
| 34 |
|
| 35 |
return translated_text
|
| 36 |
|
| 37 |
-
def translate_srt(input_file, source_language_code, target_language_code):
|
| 38 |
# Load SRT file
|
| 39 |
-
subs = pysrt.open(input_file)
|
| 40 |
|
| 41 |
# Initialize an empty list to store translated subtitles
|
| 42 |
translated_subs = []
|
| 43 |
|
|
|
|
|
|
|
|
|
|
| 44 |
# Translate each subtitle
|
| 45 |
-
for sub in
|
| 46 |
translated_text = translate_text(sub.text, source_language_code, target_language_code)
|
| 47 |
translated_subs.append(translated_text)
|
|
|
|
| 48 |
|
| 49 |
return "\n".join(translated_subs)
|
| 50 |
|
| 51 |
-
source_language_dropdown = gr.Dropdown(choices=language_options, label="Source Language")
|
| 52 |
-
target_language_dropdown = gr.Dropdown(choices=language_options, label="Target Language")
|
| 53 |
-
file_input = gr.File(label="Upload SRT File")
|
| 54 |
|
| 55 |
iface = gr.Interface(
|
| 56 |
fn=translate_srt,
|
| 57 |
inputs=[file_input, source_language_dropdown, target_language_dropdown],
|
| 58 |
-
outputs=gr.Textbox(label="Translated SRT"),
|
| 59 |
title="SRT Translator",
|
| 60 |
description="Translate subtitles from one language to another."
|
| 61 |
)
|
| 62 |
|
| 63 |
-
iface.launch()
|
|
|
|
| 2 |
import gradio as gr
|
| 3 |
import pandas as pd
|
| 4 |
from transformers import MarianMTModel, MarianTokenizer
|
|
|
|
| 5 |
|
| 6 |
# Fetch and parse language options from the provided URL
|
| 7 |
url = "https://huggingface.co/Lenylvt/LanguageISO/resolve/main/iso.md"
|
|
|
|
| 33 |
|
| 34 |
return translated_text
|
| 35 |
|
| 36 |
+
def translate_srt(input_file, source_language_code, target_language_code, progress=gr.Progress()):
|
| 37 |
# Load SRT file
|
| 38 |
+
subs = pysrt.open(input_file.name)
|
| 39 |
|
| 40 |
# Initialize an empty list to store translated subtitles
|
| 41 |
translated_subs = []
|
| 42 |
|
| 43 |
+
# Set total steps for progress bar
|
| 44 |
+
total_steps = len(subs)
|
| 45 |
+
|
| 46 |
# Translate each subtitle
|
| 47 |
+
for idx, sub in enumerate(subs):
|
| 48 |
translated_text = translate_text(sub.text, source_language_code, target_language_code)
|
| 49 |
translated_subs.append(translated_text)
|
| 50 |
+
progress((idx + 1) / total_steps, desc=f"Translating subtitle {idx+1}/{total_steps}")
|
| 51 |
|
| 52 |
return "\n".join(translated_subs)
|
| 53 |
|
| 54 |
+
source_language_dropdown = gr.inputs.Dropdown(choices=language_options, label="Source Language")
|
| 55 |
+
target_language_dropdown = gr.inputs.Dropdown(choices=language_options, label="Target Language")
|
| 56 |
+
file_input = gr.inputs.File(label="Upload SRT File", type="text")
|
| 57 |
|
| 58 |
iface = gr.Interface(
|
| 59 |
fn=translate_srt,
|
| 60 |
inputs=[file_input, source_language_dropdown, target_language_dropdown],
|
| 61 |
+
outputs=gr.outputs.Textbox(label="Translated SRT"),
|
| 62 |
title="SRT Translator",
|
| 63 |
description="Translate subtitles from one language to another."
|
| 64 |
)
|
| 65 |
|
| 66 |
+
iface.launch()
|