Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -5,15 +5,15 @@ client = InferenceClient(
|
|
5 |
"mistralai/Mixtral-8x7B-Instruct-v0.1"
|
6 |
)
|
7 |
|
8 |
-
def format_prompt(message, history):
|
9 |
prompt = "<s>"
|
10 |
for user_prompt, bot_response in history:
|
11 |
prompt += f"[INST] {user_prompt} [/INST]"
|
12 |
prompt += f" {bot_response}</s> "
|
13 |
-
prompt += f"[INST] {message} [/INST]"
|
14 |
return prompt
|
15 |
|
16 |
-
def generate_from_srt(file_content, temperature=0.9, max_new_tokens=256, top_p=0.95, repetition_penalty=1.0):
|
17 |
# Process the SRT file content as needed before using it as a prompt
|
18 |
# For example, extracting text and removing timestamps if necessary
|
19 |
# Directly using the file content for simplicity here
|
@@ -32,7 +32,7 @@ def generate_from_srt(file_content, temperature=0.9, max_new_tokens=256, top_p=0
|
|
32 |
seed=42,
|
33 |
)
|
34 |
|
35 |
-
formatted_prompt = format_prompt(file_content, [])
|
36 |
stream = client.text_generation(formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=False)
|
37 |
output = ""
|
38 |
|
@@ -40,7 +40,7 @@ def generate_from_srt(file_content, temperature=0.9, max_new_tokens=256, top_p=0
|
|
40 |
output += response.token.text
|
41 |
return output
|
42 |
|
43 |
-
def handle_file(file_info):
|
44 |
# Directly use the file content if it's a text file
|
45 |
if isinstance(file_info, str):
|
46 |
file_content = file_info
|
@@ -48,14 +48,15 @@ def handle_file(file_info):
|
|
48 |
# If file_info is not a string, it might be a binary file
|
49 |
file_content = file_info.decode('utf-8')
|
50 |
|
51 |
-
return generate_from_srt(file_content)
|
52 |
|
53 |
iface = gr.Interface(
|
54 |
fn=handle_file,
|
55 |
-
inputs=gr.File(label="Upload SRT File"),
|
56 |
outputs="text",
|
57 |
title="SRT File Translation",
|
|
|
58 |
concurrency_limit=20,
|
59 |
)
|
60 |
|
61 |
-
iface.launch()
|
|
|
5 |
"mistralai/Mixtral-8x7B-Instruct-v0.1"
|
6 |
)
|
7 |
|
8 |
+
def format_prompt(message, history, target_language):
|
9 |
prompt = "<s>"
|
10 |
for user_prompt, bot_response in history:
|
11 |
prompt += f"[INST] {user_prompt} [/INST]"
|
12 |
prompt += f" {bot_response}</s> "
|
13 |
+
prompt += f"[INST] {message} [/INST] [Translate to: {target_language}]"
|
14 |
return prompt
|
15 |
|
16 |
+
def generate_from_srt(file_content, target_language, temperature=0.9, max_new_tokens=256, top_p=0.95, repetition_penalty=1.0):
|
17 |
# Process the SRT file content as needed before using it as a prompt
|
18 |
# For example, extracting text and removing timestamps if necessary
|
19 |
# Directly using the file content for simplicity here
|
|
|
32 |
seed=42,
|
33 |
)
|
34 |
|
35 |
+
formatted_prompt = format_prompt(file_content, [], target_language)
|
36 |
stream = client.text_generation(formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=False)
|
37 |
output = ""
|
38 |
|
|
|
40 |
output += response.token.text
|
41 |
return output
|
42 |
|
43 |
+
def handle_file(file_info, target_language):
|
44 |
# Directly use the file content if it's a text file
|
45 |
if isinstance(file_info, str):
|
46 |
file_content = file_info
|
|
|
48 |
# If file_info is not a string, it might be a binary file
|
49 |
file_content = file_info.decode('utf-8')
|
50 |
|
51 |
+
return generate_from_srt(file_content, target_language)
|
52 |
|
53 |
iface = gr.Interface(
|
54 |
fn=handle_file,
|
55 |
+
inputs=[gr.File(label="Upload SRT File"), gr.Textbox(label="Target Language", placeholder="Enter target language (e.g., Spanish, French)")],
|
56 |
outputs="text",
|
57 |
title="SRT File Translation",
|
58 |
+
description="Translate the content of SRT files to the specified language.",
|
59 |
concurrency_limit=20,
|
60 |
)
|
61 |
|
62 |
+
iface.launch()
|