Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -28,16 +28,12 @@ tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
|
|
28 |
|
29 |
|
30 |
@lru_cache(maxsize=100)
|
31 |
-
def translate(text: str
|
32 |
-
|
33 |
-
raise gr.Error("The source language is empty! Please choose it in the dropdown list.")
|
34 |
-
if not tgt_lang:
|
35 |
-
raise gr.Error("The target language is empty! Please choose it in the dropdown list.")
|
36 |
-
return _translate(text, src_lang, tgt_lang)
|
37 |
|
38 |
# Only assign GPU if cache not used
|
39 |
@spaces.GPU
|
40 |
-
def _translate(text: str
|
41 |
input_tokens = (
|
42 |
tokenizer(text, return_tensors="pt")
|
43 |
.input_ids[0]
|
@@ -88,7 +84,7 @@ with gr.Blocks() as demo:
|
|
88 |
output = gr.Textbox(label="Output Text", lines=6)
|
89 |
btn.click(
|
90 |
translate,
|
91 |
-
inputs=[input_text
|
92 |
outputs=output,
|
93 |
)
|
94 |
examples = gr.Examples(examples=examples_inputs,inputs=[input_text, src_lang,target_lang], fn=translate, outputs=output, cache_examples=True)
|
|
|
28 |
|
29 |
|
30 |
@lru_cache(maxsize=100)
|
31 |
+
def translate(text: str):
|
32 |
+
return _translate(text)
|
|
|
|
|
|
|
|
|
33 |
|
34 |
# Only assign GPU if cache not used
|
35 |
@spaces.GPU
|
36 |
+
def _translate(text: str):
|
37 |
input_tokens = (
|
38 |
tokenizer(text, return_tensors="pt")
|
39 |
.input_ids[0]
|
|
|
84 |
output = gr.Textbox(label="Output Text", lines=6)
|
85 |
btn.click(
|
86 |
translate,
|
87 |
+
inputs=[input_text],
|
88 |
outputs=output,
|
89 |
)
|
90 |
examples = gr.Examples(examples=examples_inputs,inputs=[input_text, src_lang,target_lang], fn=translate, outputs=output, cache_examples=True)
|