Spaces:
Runtime error
Runtime error
Delete app.py
Browse files
app.py
DELETED
|
@@ -1,42 +0,0 @@
|
|
| 1 |
-
from huggingface_hub import InferenceClient
|
| 2 |
-
import gradio as gr
|
| 3 |
-
|
| 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
|
| 12 |
-
lines = srt_content.split("\n")
|
| 13 |
-
|
| 14 |
-
for line in lines:
|
| 15 |
-
# Check if the line is a timestamp or an empty line
|
| 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 |
-
],
|
| 37 |
-
outputs="text",
|
| 38 |
-
title="SRT Translator",
|
| 39 |
-
description="Translate SRT (SubRip subtitle) files from one language to another."
|
| 40 |
-
)
|
| 41 |
-
|
| 42 |
-
iface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|