Spaces:
Sleeping
Sleeping
jaya-sandeep-22
commited on
Commit
•
a869cd4
1
Parent(s):
ca2eaa8
Update app.py
Browse files
app.py
CHANGED
@@ -24,13 +24,13 @@ tokenizer = AutoTokenizer.from_pretrained(language_model_name)
|
|
24 |
|
25 |
def process_input(input_text, action):
|
26 |
if action == "Translate to English":
|
27 |
-
prompt = f"Please translate the following text into English
|
28 |
lang = "en"
|
29 |
elif action == "Translate to Chinese":
|
30 |
-
prompt = f"Please translate the following text into Chinese
|
31 |
lang = "zh-cn"
|
32 |
elif action == "Translate to Japanese":
|
33 |
-
prompt = f"Please translate the following text into Japanese
|
34 |
lang = "ja"
|
35 |
else:
|
36 |
prompt = input_text
|
@@ -45,10 +45,14 @@ def process_input(input_text, action):
|
|
45 |
tokenize=False,
|
46 |
add_generation_prompt=True
|
47 |
)
|
48 |
-
|
|
|
|
|
|
|
49 |
|
50 |
generated_ids = language_model.generate(
|
51 |
-
model_inputs.input_ids,
|
|
|
52 |
max_new_tokens=512
|
53 |
)
|
54 |
generated_ids = [
|
@@ -74,17 +78,17 @@ action_options = ["Translate to English", "Translate to Chinese", "Translate to
|
|
74 |
iface = gr.Interface(
|
75 |
fn=handle_interaction,
|
76 |
inputs=[
|
77 |
-
gr.Textbox(label="
|
78 |
-
gr.Dropdown(action_options, label="
|
79 |
],
|
80 |
outputs=[
|
81 |
-
gr.Textbox(label="
|
82 |
-
gr.Audio(label="
|
83 |
],
|
84 |
title="Translation and Chat App using AI",
|
85 |
description="Translate input text or chat based on the selected action.",
|
86 |
-
theme=
|
87 |
)
|
88 |
|
89 |
if __name__ == "__main__":
|
90 |
-
iface.launch()
|
|
|
24 |
|
25 |
def process_input(input_text, action):
|
26 |
if action == "Translate to English":
|
27 |
+
prompt = f"Please translate the following text into English: {input_text}"
|
28 |
lang = "en"
|
29 |
elif action == "Translate to Chinese":
|
30 |
+
prompt = f"Please translate the following text into Chinese: {input_text}"
|
31 |
lang = "zh-cn"
|
32 |
elif action == "Translate to Japanese":
|
33 |
+
prompt = f"Please translate the following text into Japanese: {input_text}"
|
34 |
lang = "ja"
|
35 |
else:
|
36 |
prompt = input_text
|
|
|
45 |
tokenize=False,
|
46 |
add_generation_prompt=True
|
47 |
)
|
48 |
+
|
49 |
+
# Encode input with attention mask
|
50 |
+
model_inputs = tokenizer([text], return_tensors="pt", padding=True, truncation=True).to(device)
|
51 |
+
attention_mask = model_inputs["attention_mask"]
|
52 |
|
53 |
generated_ids = language_model.generate(
|
54 |
+
input_ids=model_inputs.input_ids,
|
55 |
+
attention_mask=attention_mask,
|
56 |
max_new_tokens=512
|
57 |
)
|
58 |
generated_ids = [
|
|
|
78 |
iface = gr.Interface(
|
79 |
fn=handle_interaction,
|
80 |
inputs=[
|
81 |
+
gr.Textbox(label="Input Text"),
|
82 |
+
gr.Dropdown(action_options, label="Select Action")
|
83 |
],
|
84 |
outputs=[
|
85 |
+
gr.Textbox(label="Output Text"),
|
86 |
+
gr.Audio(label="Output Audio")
|
87 |
],
|
88 |
title="Translation and Chat App using AI",
|
89 |
description="Translate input text or chat based on the selected action.",
|
90 |
+
theme="gradio/soft"
|
91 |
)
|
92 |
|
93 |
if __name__ == "__main__":
|
94 |
+
iface.launch()
|