Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,32 @@
|
|
1 |
import gradio as gr
|
|
|
|
|
2 |
|
3 |
-
def greet(name):
|
4 |
-
return "Hello " + name + "!!"
|
5 |
|
6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
iface.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
import torch
|
3 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
4 |
|
|
|
|
|
5 |
|
6 |
+
tokenizer = AutoTokenizer.from_pretrained(
|
7 |
+
'kakaobrain/kogpt', revision='KoGPT6B-ryan1.5b',
|
8 |
+
bos_token='[BOS]', eos_token='[EOS]', unk_token='[UNK]', pad_token='[PAD]', mask_token='[MASK]'
|
9 |
+
)
|
10 |
+
|
11 |
+
model = AutoModelForCausalLM.from_pretrained(
|
12 |
+
'kakaobrain/kogpt', revision='KoGPT6B-ryan1.5b',
|
13 |
+
pad_token_id=tokenizer.eos_token_id,
|
14 |
+
torch_dtype=torch.float16, low_cpu_mem_usage=True
|
15 |
+
).to(device='cpu', non_blocking=True)
|
16 |
+
_ = model.eval()
|
17 |
+
|
18 |
+
title = "KoGPT"
|
19 |
+
description = "Gradio demo for KoGPT(Korean Generative Pre-trained Transformer). To use it, simply add your text, or click one of the examples to load them. Read more at the links below."
|
20 |
+
article = "<p style='text-align: center'><a href='https://github.com/kakaobrain/kogpt' target='_blank'>KoGPT: KakaoBrain Korean(hangul) Generative Pre-trained Transformer</a> | <a href='https://huggingface.co/kakaobrain/kogpt' target='_blank'>Huggingface Model</a></p>"
|
21 |
+
examples=[['μΈκ°μ²λΌ μκ°νκ³ , νλνλ \'μ§λ₯\'μ ν΅ν΄ μΈλ₯κ° μ΄μ κΉμ§ νμ§ λͺ»νλ']]
|
22 |
+
def greet(text):
|
23 |
+
prompt = text
|
24 |
+
with torch.no_grad():
|
25 |
+
tokens = tokenizer.encode(prompt, return_tensors='pt').to(device='cpu', non_blocking=True)
|
26 |
+
gen_tokens = model.generate(tokens, do_sample=True, temperature=0.8, max_length=64)
|
27 |
+
generated = tokenizer.batch_decode(gen_tokens)[0]
|
28 |
+
|
29 |
+
return generated
|
30 |
+
|
31 |
+
iface = gr.Interface(fn=greet, inputs="text", outputs="text", title=title, description=description, article=article, examples=examples,enable_queue=True)
|
32 |
iface.launch()
|