Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -4,35 +4,6 @@ from transformers import pipeline
|
|
4 |
from PIL import Image
|
5 |
import os
|
6 |
|
7 |
-
st.title("LLM Translate for ko->eng")
|
8 |
-
|
9 |
-
# adding the text that will show in the text box as default
|
10 |
-
|
11 |
-
text_default = """
|
12 |
-
๊ทธ๋ฅผ ์ค์ฌ์ผ๋ก ํ๋ชฐ์์น๋ ๋ง๋ํ๋ง๋. ํ๊ณต์์ ํผ์ด์ค๋ฅธ ๋ค์ฏ ๊ฐ์๋ถ๊ฝ์ด ํฌ๊ธฐ๋ฅผ ๋ถํ๋ฆฌ๊ณ , ์ด๋ด ํฌํ์ฒ๋ผ ์์์ก๋ค.
|
13 |
-
|
14 |
-
ํ์ฐ์ฐ์ฐ์
, ๊น์!
|
15 |
-
|
16 |
-
์๋ง์ ๋ชฌ์คํฐ๋ก ์ด๋ฃจ์ด์ง ๊ฒ์ ํ๋๊ฐ ๊ฐ๋ผ์ก๋ค. ์ด๊ณ ์จ์ ์ด๊ธฐ๊ฐ ์ด๊ณผ ๋ผ๋ฅผ ํ์ฐ๊ณ ์ง๋ฉด์ ๋
น์๋ค."""
|
17 |
-
|
18 |
-
hf_token = os.getenv("HF_ACCESS_TOKEN")
|
19 |
-
|
20 |
-
from peft import AutoPeftModelForCausalLM
|
21 |
-
from transformers import AutoTokenizer
|
22 |
-
import torch
|
23 |
-
|
24 |
-
# attn_implementation = None
|
25 |
-
# USE_FLASH_ATTENTION = False
|
26 |
-
# if USE_FLASH_ATTENTION:
|
27 |
-
# attn_implementation="flash_attention_2"
|
28 |
-
|
29 |
-
|
30 |
-
model_id = "r1208/c4ai-command-r-v01-4bit_32r"
|
31 |
-
|
32 |
-
model = AutoPeftModelForCausalLM.from_pretrained(model_id, torch_dtype=torch.bfloat16, use_auth_token=hf_token)
|
33 |
-
tokenizer = AutoTokenizer.from_pretrained(model_id, token = access_token, use_auth_token=hf_token)
|
34 |
-
|
35 |
-
tokenizer_with_prefix_space = AutoTokenizer.from_pretrained(model_id, add_prefix_space=True, use_auth_token=hf_token)
|
36 |
|
37 |
def get_tokens_as_list(word_list):
|
38 |
"Converts a sequence of words into a list of tokens"
|
@@ -41,12 +12,7 @@ def get_tokens_as_list(word_list):
|
|
41 |
tokenized_word = tokenizer_with_prefix_space([word], add_special_tokens=False).input_ids[0]
|
42 |
tokens_list.append(tokenized_word)
|
43 |
return tokens_list
|
44 |
-
bad_words_ids = get_tokens_as_list( word_list=["\n", "\n\n", "\ ", " \ ", "\\", "'\n'"] )
|
45 |
|
46 |
-
max_new_tokens = st.sidebar.slider("Max Length", value=100, min_value=10, max_value=1000)
|
47 |
-
temperature = st.sidebar.slider("Temperature", value=0.3, min_value=0.0, max_value=1.0, step=0.05)
|
48 |
-
top_k = st.sidebar.slider("Top-k", min_value=0, max_value=50, value=0)
|
49 |
-
top_p = st.sidebar.slider("Top-p", min_value=0.75, max_value=1.0, step=0.05, value=0.9)
|
50 |
|
51 |
def translate(text):
|
52 |
# Prepare the prompt
|
@@ -64,6 +30,48 @@ def translate(text):
|
|
64 |
return translation
|
65 |
|
66 |
def main():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
67 |
st.subheader("Enter text to translate")
|
68 |
input_text = st.text_area("", height=300)
|
69 |
|
|
|
4 |
from PIL import Image
|
5 |
import os
|
6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
|
8 |
def get_tokens_as_list(word_list):
|
9 |
"Converts a sequence of words into a list of tokens"
|
|
|
12 |
tokenized_word = tokenizer_with_prefix_space([word], add_special_tokens=False).input_ids[0]
|
13 |
tokens_list.append(tokenized_word)
|
14 |
return tokens_list
|
|
|
15 |
|
|
|
|
|
|
|
|
|
16 |
|
17 |
def translate(text):
|
18 |
# Prepare the prompt
|
|
|
30 |
return translation
|
31 |
|
32 |
def main():
|
33 |
+
|
34 |
+
st.title("LLM Translate for ko->eng")
|
35 |
+
|
36 |
+
# adding the text that will show in the text box as default
|
37 |
+
|
38 |
+
text_default = """
|
39 |
+
๊ทธ๋ฅผ ์ค์ฌ์ผ๋ก ํ๋ชฐ์์น๋ ๋ง๋ํ๋ง๋. ํ๊ณต์์ ํผ์ด์ค๋ฅธ ๋ค์ฏ ๊ฐ์๋ถ๊ฝ์ด ํฌ๊ธฐ๋ฅผ ๋ถํ๋ฆฌ๊ณ , ์ด๋ด ํฌํ์ฒ๋ผ ์์์ก๋ค.
|
40 |
+
|
41 |
+
ํ์ฐ์ฐ์ฐ์
, ๊น์!
|
42 |
+
|
43 |
+
์๋ง์ ๋ชฌ์คํฐ๋ก ์ด๋ฃจ์ด์ง ๊ฒ์ ํ๋๊ฐ ๊ฐ๋ผ์ก๋ค. ์ด๊ณ ์จ์ ์ด๊ธฐ๊ฐ ์ด๊ณผ ๋ผ๋ฅผ ํ์ฐ๊ณ ์ง๋ฉด์ ๋
น์๋ค."""
|
44 |
+
|
45 |
+
hf_token = os.getenv("HF_ACCESS_TOKEN")
|
46 |
+
|
47 |
+
from peft import AutoPeftModelForCausalLM
|
48 |
+
from transformers import AutoTokenizer
|
49 |
+
import torch
|
50 |
+
|
51 |
+
# attn_implementation = None
|
52 |
+
# USE_FLASH_ATTENTION = False
|
53 |
+
# if USE_FLASH_ATTENTION:
|
54 |
+
# attn_implementation="flash_attention_2"
|
55 |
+
|
56 |
+
|
57 |
+
model_id = "r1208/c4ai-command-r-v01-4bit_32r"
|
58 |
+
|
59 |
+
model = AutoPeftModelForCausalLM.from_pretrained(model_id, torch_dtype=torch.bfloat16, use_auth_token=hf_token)
|
60 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id, token = access_token, use_auth_token=hf_token)
|
61 |
+
|
62 |
+
tokenizer_with_prefix_space = AutoTokenizer.from_pretrained(model_id, add_prefix_space=True, use_auth_token=hf_token)
|
63 |
+
|
64 |
+
|
65 |
+
|
66 |
+
|
67 |
+
bad_words_ids = get_tokens_as_list( word_list=["\n", "\n\n", "\ ", " \ ", "\\", "'\n'"] )
|
68 |
+
|
69 |
+
max_new_tokens = st.sidebar.slider("Max Length", value=100, min_value=10, max_value=1000)
|
70 |
+
temperature = st.sidebar.slider("Temperature", value=0.3, min_value=0.0, max_value=1.0, step=0.05)
|
71 |
+
top_k = st.sidebar.slider("Top-k", min_value=0, max_value=50, value=0)
|
72 |
+
top_p = st.sidebar.slider("Top-p", min_value=0.75, max_value=1.0, step=0.05, value=0.9)
|
73 |
+
|
74 |
+
|
75 |
st.subheader("Enter text to translate")
|
76 |
input_text = st.text_area("", height=300)
|
77 |
|