snoop2head
commited on
Commit
•
640c8c2
1
Parent(s):
2578776
ignore whitespace inputs
Browse files
app.py
CHANGED
@@ -39,34 +39,34 @@ print(src_text)
|
|
39 |
|
40 |
if src_text == "":
|
41 |
st.warning("Please **enter text** for translation")
|
42 |
-
|
43 |
-
# translate into english sentence
|
44 |
-
if translation_mode == translation_list[0]:
|
45 |
-
model = ko2en_model
|
46 |
else:
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
55 |
max_length=64,
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
)
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
st.write(translation_result)
|
72 |
-
print(translation_result)
|
|
|
39 |
|
40 |
if src_text == "":
|
41 |
st.warning("Please **enter text** for translation")
|
|
|
|
|
|
|
|
|
42 |
else:
|
43 |
+
# translate into english sentence
|
44 |
+
if translation_mode == translation_list[0]:
|
45 |
+
model = ko2en_model
|
46 |
+
else:
|
47 |
+
model = en2ko_model
|
48 |
+
|
49 |
+
translation_result = model.generate(
|
50 |
+
**tokenizer(
|
51 |
+
src_text,
|
52 |
+
return_tensors="pt",
|
53 |
+
padding="max_length",
|
54 |
+
truncation=True,
|
55 |
+
max_length=64,
|
56 |
+
),
|
57 |
max_length=64,
|
58 |
+
num_beams=5,
|
59 |
+
repetition_penalty=1.3,
|
60 |
+
no_repeat_ngram_size=3,
|
61 |
+
num_return_sequences=1,
|
62 |
+
)
|
63 |
+
translation_result = tokenizer.decode(
|
64 |
+
translation_result[0],
|
65 |
+
clean_up_tokenization_spaces=True,
|
66 |
+
skip_special_tokens=True,
|
67 |
+
)
|
68 |
+
|
69 |
+
print(f"{src_text} -> {translation_result}")
|
70 |
+
|
71 |
+
st.write(translation_result)
|
72 |
+
print(translation_result)
|
|
|
|