Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,304 +1,91 @@
|
|
1 |
import gradio as gr
|
2 |
-
import
|
3 |
-
import re
|
4 |
-
|
5 |
-
def validate_token(token):
|
6 |
-
"""ํ ํฐ ํ์ ์ ํจ์ฑ ๊ฒ์ฌ"""
|
7 |
-
if not token:
|
8 |
-
return False
|
9 |
-
# ํ๊น
ํ์ด์ค ํ ํฐ์ ๋ณดํต hf_๋ก ์์ํ๊ณ ์ํ๋ฒณ๊ณผ ์ซ์๋ก ๊ตฌ์ฑ
|
10 |
-
return bool(re.match(r'^hf_[a-zA-Z0-9]{34,}$', token))
|
11 |
-
|
12 |
-
def safe_tokenizer_load(model_name, hf_token=None):
|
13 |
-
"""์์ ํ ํ ํฌ๋์ด์ ๋ก๋ฉ"""
|
14 |
-
from transformers import AutoTokenizer
|
15 |
-
|
16 |
-
# ๋ค์ํ ๋ก๋ฉ ์ ๋ต ์๋
|
17 |
-
strategies = [
|
18 |
-
{"trust_remote_code": True, "use_fast": False},
|
19 |
-
{"trust_remote_code": True, "use_fast": True},
|
20 |
-
{"trust_remote_code": False, "use_fast": False},
|
21 |
-
{"trust_remote_code": False, "use_fast": True},
|
22 |
-
]
|
23 |
-
|
24 |
-
for strategy in strategies:
|
25 |
-
try:
|
26 |
-
tokenizer_kwargs = strategy.copy()
|
27 |
-
if hf_token and hf_token.strip():
|
28 |
-
tokenizer_kwargs["token"] = hf_token.strip()
|
29 |
-
|
30 |
-
tokenizer = AutoTokenizer.from_pretrained(model_name, **tokenizer_kwargs)
|
31 |
-
return tokenizer, None
|
32 |
-
except Exception as e:
|
33 |
-
last_error = e
|
34 |
-
continue
|
35 |
-
|
36 |
-
return None, last_error
|
37 |
|
38 |
def count_tokens(model_name, text, hf_token=None):
|
39 |
-
"""ํ ํฐ
|
40 |
try:
|
41 |
if not model_name or not text:
|
42 |
return "๋ชจ๋ธ๋ช
๊ณผ ํ
์คํธ๋ฅผ ๋ชจ๋ ์
๋ ฅํด์ฃผ์ธ์."
|
43 |
|
44 |
-
#
|
45 |
-
|
46 |
-
|
47 |
-
if
|
48 |
-
|
49 |
-
|
50 |
-
# ์์ ํ ํ ํฌ๋์ด์ ๋ก๋ฉ
|
51 |
-
tokenizer, error = safe_tokenizer_load(model_name, hf_token)
|
52 |
-
if tokenizer is None:
|
53 |
-
raise error
|
54 |
-
|
55 |
-
# ํจ๋ฉ ํ ํฐ์ด ์๋ ๊ฒฝ์ฐ ์ถ๊ฐ
|
56 |
-
if tokenizer.pad_token is None:
|
57 |
-
if tokenizer.eos_token:
|
58 |
-
tokenizer.pad_token = tokenizer.eos_token
|
59 |
-
elif tokenizer.unk_token:
|
60 |
-
tokenizer.pad_token = tokenizer.unk_token
|
61 |
-
|
62 |
-
# ํ ํฐํ - ์ฌ๋ฌ ๋ฐฉ๋ฒ ์๋
|
63 |
-
try:
|
64 |
-
tokens = tokenizer.encode(text, add_special_tokens=True)
|
65 |
-
except:
|
66 |
-
# ๋ ์์ ํ ๋ฐฉ๋ฒ์ผ๋ก ์๋
|
67 |
-
tokens = tokenizer.encode(text, add_special_tokens=False)
|
68 |
|
|
|
|
|
69 |
token_count = len(tokens)
|
70 |
|
71 |
-
#
|
72 |
-
|
73 |
-
for i, token in enumerate(tokens[:50]): # ์ฒ์ 50๊ฐ๋ง
|
74 |
-
try:
|
75 |
-
decoded = tokenizer.decode([token])
|
76 |
-
if decoded.strip() == '':
|
77 |
-
decoded_tokens.append(f"<empty_{token}>")
|
78 |
-
elif decoded.strip() == tokenizer.pad_token:
|
79 |
-
decoded_tokens.append(f"<pad_{token}>")
|
80 |
-
elif decoded.strip() == tokenizer.eos_token:
|
81 |
-
decoded_tokens.append(f"<eos_{token}>")
|
82 |
-
elif decoded.strip() == tokenizer.bos_token:
|
83 |
-
decoded_tokens.append(f"<bos_{token}>")
|
84 |
-
else:
|
85 |
-
decoded_tokens.append(repr(decoded))
|
86 |
-
except:
|
87 |
-
decoded_tokens.append(f"<token_{token}>")
|
88 |
-
|
89 |
-
result = f"โ
ํ ํฐ ์: {token_count}\n\n"
|
90 |
result += f"๋ชจ๋ธ: {model_name}\n"
|
91 |
-
result += f"ํ
์คํธ ๊ธธ์ด: {len(text)}
|
92 |
-
result += f"ํ ํฌ๋์ด์ ํ์
: {type(tokenizer).__name__}\n\n"
|
93 |
-
result += f"ํ ํฐ๋ค (์ฒ์ 50๊ฐ):\n{decoded_tokens}"
|
94 |
-
|
95 |
-
if len(tokens) > 50:
|
96 |
-
result += f"\n\n... (์ด {len(tokens)}๊ฐ ํ ํฐ ์ค 50๊ฐ๋ง ํ์)"
|
97 |
|
98 |
return result
|
99 |
|
100 |
except Exception as e:
|
101 |
-
|
102 |
-
error_msg = f"โ ์ค๋ฅ ๋ฐ์: {error_str}\n\n"
|
103 |
-
|
104 |
-
if "401" in error_str and "Unauthorized" in error_str:
|
105 |
-
error_msg += "๐ ์ธ์ฆ ์ค๋ฅ:\n"
|
106 |
-
error_msg += "1. ํ๊น
ํ์ด์ค ํ ํฐ์ด ์ฌ๋ฐ๋ฅธ์ง ํ์ธํ์ธ์\n"
|
107 |
-
error_msg += "2. ํ ํฐ์ด 'hf_'๋ก ์์ํ๋์ง ํ์ธํ์ธ์\n"
|
108 |
-
error_msg += "3. ํด๋น ๋ชจ๋ธ์ ๋ํ ์ ๊ทผ ๊ถํ์ด ์๋์ง ํ์ธํ์ธ์\n"
|
109 |
-
error_msg += f"4. ๋ชจ๋ธ ํ์ด์ง ๋ฐฉ๋ฌธ: https://huggingface.co/{model_name}\n"
|
110 |
-
elif "gated repo" in error_str:
|
111 |
-
error_msg += "๐ ์ ๊ทผ ์ ํ๋ ๋ชจ๋ธ:\n"
|
112 |
-
error_msg += f"1. https://huggingface.co/{model_name} ์์ ์ ๊ทผ ๊ถํ์ ์์ฒญํ์ธ์\n"
|
113 |
-
error_msg += "2. ์น์ธ ํ ์ ํจํ ํ๊น
ํ์ด์ค ํ ํฐ์ ์
๋ ฅํ์ธ์\n"
|
114 |
-
elif "does not exist" in error_str or "not found" in error_str:
|
115 |
-
error_msg += "๐ ๋ชจ๋ธ์ ์ฐพ์ ์ ์์ต๋๋ค:\n"
|
116 |
-
error_msg += "1. ๋ชจ๋ธ๋ช
์ ํ์ธํด์ฃผ์ธ์\n"
|
117 |
-
error_msg += "2. ๊ณต๊ฐ ๋ชจ๋ธ ์์: 'klue/bert-base', 'beomi/KcELECTRA-base', 'gpt2'\n"
|
118 |
-
elif "data did not match any variant" in error_str:
|
119 |
-
error_msg += "โ ๏ธ ๋ชจ๋ธ ํ์ผ ๊ตฌ์กฐ ๋ฌธ์ :\n"
|
120 |
-
error_msg += "1. ์ด ๋ชจ๋ธ์ ํ์ฌ ์ง์๋์ง ์๋ ํ์์
๋๋ค\n"
|
121 |
-
error_msg += "2. ๋ค๋ฅธ ๋ชจ๋ธ์ ์๋ํด๋ณด์ธ์\n"
|
122 |
-
error_msg += "3. ์ถ์ฒ ๋ชจ๋ธ: 'gpt2', 'microsoft/DialoGPT-medium', 'klue/bert-base'\n"
|
123 |
-
elif "Tokenizer class" in error_str:
|
124 |
-
error_msg += "๐ง ํ ํฌ๋์ด์ ํด๋์ค ๋ฌธ์ :\n"
|
125 |
-
error_msg += "1. ์ด ๋ชจ๋ธ์ ์ต์ transformers ๋ผ์ด๋ธ๋ฌ๋ฆฌ๊ฐ ํ์ํ ์ ์์ต๋๋ค\n"
|
126 |
-
error_msg += "2. ๋ค๋ฅธ ๋ชจ๋ธ์ ์๋ํด๋ณด์ธ์\n"
|
127 |
-
else:
|
128 |
-
error_msg += "๐ง ๊ฐ๋ฅํ ํด๊ฒฐ ๋ฐฉ๋ฒ:\n"
|
129 |
-
error_msg += "1. ๋ชจ๋ธ๋ช
์ ํ์ธํด์ฃผ์ธ์\n"
|
130 |
-
error_msg += "2. ๋คํธ์ํฌ ์ฐ๊ฒฐ์ ํ์ธํด์ฃผ์ธ์\n"
|
131 |
-
error_msg += "3. ๋ค๋ฅธ ๋ชจ๋ธ์ ์๋ํด๋ณด์ธ์\n"
|
132 |
-
|
133 |
-
return error_msg
|
134 |
|
135 |
-
def
|
136 |
-
"""๋ชจ๋ธ ์ ๊ทผ
|
137 |
try:
|
138 |
if not model_name:
|
139 |
return "๋ชจ๋ธ๋ช
์ ์
๋ ฅํด์ฃผ์ธ์."
|
140 |
|
141 |
-
|
142 |
-
|
143 |
-
if
|
144 |
-
|
145 |
-
|
146 |
-
# ์์ ํ ํ ํฌ๋์ด์ ๋ก๋ฉ
|
147 |
-
tokenizer, error = safe_tokenizer_load(model_name, hf_token)
|
148 |
-
if tokenizer is None:
|
149 |
-
raise error
|
150 |
-
|
151 |
-
# ํ ํฌ๋์ด์ ์ ๋ณด ํ์
|
152 |
-
vocab_size = getattr(tokenizer, 'vocab_size', "์ ์ ์์")
|
153 |
-
model_max_length = getattr(tokenizer, 'model_max_length', "์ ์ ์์")
|
154 |
-
|
155 |
-
result = f"โ
{model_name} ๋ชจ๋ธ ์ ๊ทผ ๊ฐ๋ฅํฉ๋๋ค!\n\n"
|
156 |
-
result += f"ํ ํฌ๋์ด์ ์ ๋ณด:\n"
|
157 |
-
result += f"- ์ดํ ํฌ๊ธฐ: {vocab_size}\n"
|
158 |
-
result += f"- ์ต๋ ๊ธธ์ด: {model_max_length}\n"
|
159 |
-
result += f"- ํ ํฌ๋์ด์ ํ์
: {type(tokenizer).__name__}\n"
|
160 |
-
|
161 |
-
# ํน์ ํ ํฐ ์ ๋ณด
|
162 |
-
special_tokens = []
|
163 |
-
if hasattr(tokenizer, 'pad_token') and tokenizer.pad_token:
|
164 |
-
special_tokens.append(f"PAD: {tokenizer.pad_token}")
|
165 |
-
if hasattr(tokenizer, 'eos_token') and tokenizer.eos_token:
|
166 |
-
special_tokens.append(f"EOS: {tokenizer.eos_token}")
|
167 |
-
if hasattr(tokenizer, 'bos_token') and tokenizer.bos_token:
|
168 |
-
special_tokens.append(f"BOS: {tokenizer.bos_token}")
|
169 |
-
if hasattr(tokenizer, 'unk_token') and tokenizer.unk_token:
|
170 |
-
special_tokens.append(f"UNK: {tokenizer.unk_token}")
|
171 |
-
|
172 |
-
if special_tokens:
|
173 |
-
result += f"- ํน์ ํ ํฐ: {', '.join(special_tokens)}"
|
174 |
|
175 |
-
return
|
176 |
|
177 |
except Exception as e:
|
178 |
-
|
179 |
-
|
180 |
-
if "401" in error_str and "Unauthorized" in error_str:
|
181 |
-
return f"๐ {model_name}: ์ธ์ฆ ์ค๋ฅ์
๋๋ค. ํ ํฐ์ ํ์ธํ๊ฑฐ๋ ๋ชจ๋ธ ์ ๊ทผ ๊ถํ์ ์์ฒญํ์ธ์."
|
182 |
-
elif "gated repo" in error_str:
|
183 |
-
return f"๐ {model_name}์ ์ ๊ทผ ๊ถํ์ด ํ์ํ ๋ชจ๋ธ์
๋๋ค."
|
184 |
-
elif "does not exist" in error_str:
|
185 |
-
return f"โ {model_name} ๋ชจ๋ธ์ ์ฐพ์ ์ ์์ต๋๋ค."
|
186 |
-
elif "data did not match any variant" in error_str:
|
187 |
-
return f"โ ๏ธ {model_name} ๋ชจ๋ธ์ ํ์ฌ ์ง์๋์ง ์๋ ํ์์
๋๋ค."
|
188 |
-
else:
|
189 |
-
return f"โ ์ค๋ฅ: {error_str}"
|
190 |
|
191 |
-
# Gradio ์ธํฐํ์ด์ค
|
192 |
def create_interface():
|
193 |
-
with gr.Blocks(title="ํ ํฐ ๊ณ์ฐ๊ธฐ"
|
194 |
-
gr.Markdown("# ๐ข
|
195 |
-
gr.Markdown("ํ๊น
ํ์ด์ค์ ์ฌ๋ผ์จ ๋ชจ๋ธ์ ํ ํฌ๋์ด์ ๋ฅผ ์ฌ์ฉํด ํ
์คํธ์ ํ ํฐ ์๋ฅผ ๊ณ์ฐํฉ๋๋ค.")
|
196 |
|
197 |
with gr.Row():
|
198 |
with gr.Column():
|
199 |
model_input = gr.Textbox(
|
200 |
label="๋ชจ๋ธ๋ช
",
|
201 |
-
placeholder="์: klue/bert-base
|
202 |
-
value="
|
203 |
)
|
204 |
|
205 |
token_input = gr.Textbox(
|
206 |
-
label="
|
207 |
-
placeholder="gated ๋ชจ๋ธ ์ฌ์ฉ์ ํ์ (hf_xxx...)",
|
208 |
type="password"
|
209 |
)
|
210 |
|
211 |
text_input = gr.Textbox(
|
212 |
label="ํ
์คํธ",
|
213 |
-
placeholder="ํ ํฐ ์๋ฅผ ๊ณ์ฐํ ํ
์คํธ๋ฅผ ์
๋ ฅํ์ธ์...",
|
214 |
lines=5,
|
215 |
-
value="์๋
ํ์ธ์!
|
216 |
)
|
217 |
|
218 |
with gr.Row():
|
219 |
-
check_btn = gr.Button("๋ชจ๋ธ
|
220 |
-
|
221 |
|
222 |
with gr.Column():
|
223 |
-
output = gr.Textbox(
|
224 |
-
label="๊ฒฐ๊ณผ",
|
225 |
-
lines=15,
|
226 |
-
show_copy_button=True
|
227 |
-
)
|
228 |
-
|
229 |
-
# ๋ชจ๋ธ ์นดํ
๊ณ ๋ฆฌ๋ณ ์์
|
230 |
-
with gr.Tabs():
|
231 |
-
with gr.TabItem("โ
์์ ์ ์ธ ๋ชจ๋ธ"):
|
232 |
-
gr.Markdown("### ํ์คํ ์๋ํ๋ ๋ชจ๋ธ๋ค:")
|
233 |
-
with gr.Row():
|
234 |
-
stable_models = [
|
235 |
-
"klue/bert-base",
|
236 |
-
"beomi/KcELECTRA-base",
|
237 |
-
"gpt2",
|
238 |
-
"microsoft/DialoGPT-medium",
|
239 |
-
"distilbert-base-uncased",
|
240 |
-
"t5-small"
|
241 |
-
]
|
242 |
-
|
243 |
-
for model in stable_models:
|
244 |
-
btn = gr.Button(model, size="sm")
|
245 |
-
btn.click(lambda x=model: x, outputs=model_input)
|
246 |
-
|
247 |
-
with gr.TabItem("โ ๏ธ ๋ฌธ์ ๊ฐ ์์ ์ ์๋ ๋ชจ๋ธ"):
|
248 |
-
gr.Markdown("### ์ง์๋์ง ์๊ฑฐ๋ ๋ฌธ์ ๊ฐ ์์ ์ ์๋ ๋ชจ๋ธ๋ค:")
|
249 |
-
gr.Markdown("์ด ๋ชจ๋ธ๋ค์ ํ์ฌ ๋ฒ์ ์์ ์๋ํ์ง ์์ ์ ์์ต๋๋ค.")
|
250 |
-
with gr.Row():
|
251 |
-
problematic_models = [
|
252 |
-
"google/gemma-3-12b-it",
|
253 |
-
"meta-llama/Llama-2-7b-hf",
|
254 |
-
"mistralai/Mistral-7B-v0.1"
|
255 |
-
]
|
256 |
-
|
257 |
-
for model in problematic_models:
|
258 |
-
btn = gr.Button(model, size="sm")
|
259 |
-
btn.click(lambda x=model: x, outputs=model_input)
|
260 |
|
261 |
-
#
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
### ํ ํฐ์ด ํ์ํ ๊ฒฝ์ฐ:
|
270 |
-
- Gated ๋ชจ๋ธ (Meta Llama, Google Gemma ๋ฑ)
|
271 |
-
- ๋น๊ณต๊ฐ ๋ชจ๋ธ
|
272 |
-
|
273 |
-
### ํ ํฐ ์์ฑ:
|
274 |
-
1. [ํ๊น
ํ์ด์ค ํ ํฐ ํ์ด์ง](https://huggingface.co/settings/tokens) ๋ฐฉ๋ฌธ
|
275 |
-
2. "New token" ์์ฑ (Read ๊ถํ)
|
276 |
-
3. ํ ํฐ์ ์์ ํ๋์ ์
๋ ฅ
|
277 |
-
|
278 |
-
### ๋ฌธ์ ํด๊ฒฐ:
|
279 |
-
- ๋ชจ๋ธ์ด ์ง์๋์ง ์๋ ๊ฒฝ์ฐ ๋ค๋ฅธ ๋ชจ๋ธ ์๋
|
280 |
-
- ๋คํธ์ํฌ ๋ฌธ์ ์ ์ ์ ํ ์ฌ์๋
|
281 |
-
- ์์ ์ ์ธ ๋ชจ๋ธ ํญ์ ๋ชจ๋ธ๋ค ์ฌ์ฉ ๊ถ์ฅ
|
282 |
-
""")
|
283 |
|
284 |
# ์ด๋ฒคํธ ํธ๋ค๋ฌ
|
285 |
-
check_btn.click(
|
286 |
-
|
287 |
-
|
288 |
-
outputs=output
|
289 |
-
)
|
290 |
-
|
291 |
-
calculate_btn.click(
|
292 |
-
count_tokens,
|
293 |
-
inputs=[model_input, text_input, token_input],
|
294 |
-
outputs=output
|
295 |
-
)
|
296 |
-
|
297 |
-
text_input.submit(
|
298 |
-
count_tokens,
|
299 |
-
inputs=[model_input, text_input, token_input],
|
300 |
-
outputs=output
|
301 |
-
)
|
302 |
|
303 |
return demo
|
304 |
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import AutoTokenizer
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
|
4 |
def count_tokens(model_name, text, hf_token=None):
|
5 |
+
"""ํ ํฐ ์ ๊ณ์ฐ"""
|
6 |
try:
|
7 |
if not model_name or not text:
|
8 |
return "๋ชจ๋ธ๋ช
๊ณผ ํ
์คํธ๋ฅผ ๋ชจ๋ ์
๋ ฅํด์ฃผ์ธ์."
|
9 |
|
10 |
+
# ํ ํฌ๋์ด์ ๋ก๋
|
11 |
+
tokenizer = AutoTokenizer.from_pretrained(
|
12 |
+
model_name,
|
13 |
+
token=hf_token.strip() if hf_token and hf_token.strip() else None
|
14 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
|
16 |
+
# ํ ํฐ ์ธ์ฝ๋ฉ
|
17 |
+
tokens = tokenizer.encode(text)
|
18 |
token_count = len(tokens)
|
19 |
|
20 |
+
# ๊ฒฐ๊ณผ ๋ฐํ
|
21 |
+
result = f"โ
ํ ํฐ ์: {token_count}\n"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
result += f"๋ชจ๋ธ: {model_name}\n"
|
23 |
+
result += f"ํ
์คํธ ๊ธธ์ด: {len(text)} ๊ธ์"
|
|
|
|
|
|
|
|
|
|
|
24 |
|
25 |
return result
|
26 |
|
27 |
except Exception as e:
|
28 |
+
return f"โ ์ค๋ฅ: {str(e)}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
|
30 |
+
def check_model(model_name, hf_token=None):
|
31 |
+
"""๋ชจ๋ธ ์ ๊ทผ ํ์ธ"""
|
32 |
try:
|
33 |
if not model_name:
|
34 |
return "๋ชจ๋ธ๋ช
์ ์
๋ ฅํด์ฃผ์ธ์."
|
35 |
|
36 |
+
tokenizer = AutoTokenizer.from_pretrained(
|
37 |
+
model_name,
|
38 |
+
token=hf_token.strip() if hf_token and hf_token.strip() else None
|
39 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
|
41 |
+
return f"โ
{model_name} ๋ชจ๋ธ ์ ๊ทผ ๊ฐ๋ฅ!"
|
42 |
|
43 |
except Exception as e:
|
44 |
+
return f"โ ์ค๋ฅ: {str(e)}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
|
46 |
+
# Gradio ์ธํฐํ์ด์ค
|
47 |
def create_interface():
|
48 |
+
with gr.Blocks(title="ํ ํฐ ๊ณ์ฐ๊ธฐ") as demo:
|
49 |
+
gr.Markdown("# ๐ข ํ ํฐ ๊ณ์ฐ๊ธฐ")
|
|
|
50 |
|
51 |
with gr.Row():
|
52 |
with gr.Column():
|
53 |
model_input = gr.Textbox(
|
54 |
label="๋ชจ๋ธ๋ช
",
|
55 |
+
placeholder="์: gpt2, klue/bert-base",
|
56 |
+
value="gpt2"
|
57 |
)
|
58 |
|
59 |
token_input = gr.Textbox(
|
60 |
+
label="HF ํ ํฐ (์ ํ์ฌํญ)",
|
|
|
61 |
type="password"
|
62 |
)
|
63 |
|
64 |
text_input = gr.Textbox(
|
65 |
label="ํ
์คํธ",
|
|
|
66 |
lines=5,
|
67 |
+
value="์๋
ํ์ธ์! ํ
์คํธ ํ
์คํธ์
๋๋ค."
|
68 |
)
|
69 |
|
70 |
with gr.Row():
|
71 |
+
check_btn = gr.Button("๋ชจ๋ธ ํ์ธ")
|
72 |
+
calc_btn = gr.Button("ํ ํฐ ๊ณ์ฐ", variant="primary")
|
73 |
|
74 |
with gr.Column():
|
75 |
+
output = gr.Textbox(label="๊ฒฐ๊ณผ", lines=10)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
76 |
|
77 |
+
# ์ถ์ฒ ๋ชจ๋ธ
|
78 |
+
gr.Markdown("### ์ถ์ฒ ๋ชจ๋ธ")
|
79 |
+
with gr.Row():
|
80 |
+
models = ["gpt2", "klue/bert-base", "microsoft/DialoGPT-medium"]
|
81 |
+
for model in models:
|
82 |
+
btn = gr.Button(model, size="sm")
|
83 |
+
btn.click(lambda x=model: x, outputs=model_input)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
84 |
|
85 |
# ์ด๋ฒคํธ ํธ๋ค๋ฌ
|
86 |
+
check_btn.click(check_model, [model_input, token_input], output)
|
87 |
+
calc_btn.click(count_tokens, [model_input, text_input, token_input], output)
|
88 |
+
text_input.submit(count_tokens, [model_input, text_input, token_input], output)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
89 |
|
90 |
return demo
|
91 |
|