Spaces:
Runtime error
Runtime error
File size: 2,534 Bytes
daf919b 60c3989 76e5e1a 60c3989 76e5e1a a9f32fb 43a5bfe 20809a7 a9f32fb |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
import gradio as gr
# make function using import pip to install torch
import pip
pip.main(['install', 'torch'])
pip.main(['install', 'transformers'])
import torch
import transformers
# saved_model
def load_model(model_path):
saved_data = torch.load(
model_path,
map_location="cpu"
)
bart_best = saved_data["model"]
train_config = saved_data["config"]
tokenizer = transformers.PreTrainedTokenizerFast.from_pretrained('gogamza/kobart-base-v1')
## Load weights.
model = transformers.BartForConditionalGeneration.from_pretrained('gogamza/kobart-base-v1')
model.load_state_dict(bart_best)
return model, tokenizer
# main
def inference(prompt):
model_path = "./kobart-model-logical.pth"
model, tokenizer = load_model(
model_path=model_path
)
input_ids = tokenizer.encode(prompt)
input_ids = torch.tensor(input_ids)
input_ids = input_ids.unsqueeze(0)
output = model.generate(input_ids)
output = tokenizer.decode(output[0], skip_special_tokens=True)
return output
demo = gr.Interface(
fn=inference,
inputs="text",
outputs="text", #return ๊ฐ
examples=[
"๊ฐ์๋ ์์๊ตฐ์์ ์ ์ฒญํ ์ค์
์ฐ๊ตญ๋ฆฝ๊ณต์ ์ผ์ด๋ธ์นด ์ฌ์
์ด 7๊ฐ์ง ๋ถ๋์กฐ๊ฑด์ ์งํค๋ ์กฐ๊ฑด์ผ๋ก 2015๋
8์ 28์ผ ํ๊ฒฝ๋ถ ์ฐํ ๊ตญ๋ฆฝ๊ณต์์์ํ์ ์ฌ์๋ฅผ ํต๊ณผํ์๋ค. ์ 113์ฐจ ๊ตญ๋ฆฝ๊ณต์์์ํ์์ ๋ด๋ ค์ง ์ด ๊ฒฐ์ ์ผ๋ก ์ค์
์ค์-๋์ฒญ ํ๋จ์ ์ฐ๊ฒฐํ๋ 3,492km์ ์ผ์ด๋ธ์นด๊ณผ ๊ฑด๋ฆฝ๋ ์์ ์ด๋ฉฐ, ์ค์
์ฐ ๋์ฒญ๋ด๊ณผ 1.4km ๋จ์ด์ง ์ง์ ๊น์ง ์ผ์ด๋ธ์นด๋ฅผ ์ด์ฉํ์ฌ ์ ๊ทผํ ์ ์๊ฒ ๋์๋ค. ์ฌ์
๋น๋ ์ด 460์ต์ด๋ฉฐ, ๊ตญ๋น 50%, ๊ตฐ๋น 35%, ๋๋น 15%๋ก ๊ฒฐ์ ๋์๋ค. ์ด ์ฌ์
์ ์ด ์ธ์ฐจ๋ก์ ๊ฑธ์น ๋ฐ๋ ค์ ๋ถ๊ฒฐ ๋ฑ์ ํตํด ๊ธฐํ์ ์์ ๋์ด๊ฐ๋ค ๊ฒฐ๊ตญ ์ฌ์
ํ๋น์ฑ๊ณผ ์ ์ ์ฑ์ ํฅ์์์ผฐ๋ค๋ ํ๊ฐ๋ฅผ ๋ฐ์ผ๋ฉฐ ํ์ ๋์๋ค. ๊ทธ๋ฌ๋ ๋ง์ ์๋ฏผ๋จ์ฒด์ ํ๊ฒฝ๋จ์ฒด๋ ์ด์ ๊ฐ์ ๊ฒฐ์ ์๋ ๋ถ๊ตฌํ๊ณ ๊ตญ๋ฆฝ๊ณต์์ ํ๊ฒฝํ๊ดด๋ฅผ ์ด์ ๋ก ์ฌ์ ํ ์ด๋ฅผ ๋ฐ๋ํ๊ณ ์์ผ๋ฉฐ, โ์ฐ์ผ๋ก ๊ฐ 4๋๊ฐ ์ฌ์
โ์ด๋ผ๋ ๋น๋๊ณผ ํจ๊ป ๊ตญ๋ฆฝ๊ณต์์ด ์ ์์งํ ๋๋ ๋น๊ทน์ ๋ง์๊ณ ์ฃผ์ฅํ๋ค. ํธ์์ฑ๊ณผ ๊ฒฝ์ ์ฑ์ ๋
ผ๋ฆฌ์ ํจ๊ป ํ๊ฒฝ๋ณด์กด์ ๋
ผ๋ฆฌ๊ฐ ๋ถ๋ชํ๋ ์ค์
์ฐ๊ตญ๋ฆฝ๊ณต์์ ์ผ์ด๋ธ์นด๋ ๊ฑด์ค๋์ด์ผ ํ๋๊ฐ."
]
).launch() # launch(share=True)๋ฅผ ์ค์ ํ๋ฉด ์ธ๋ถ์์ ์ ์ ๊ฐ๋ฅํ ๋งํฌ๊ฐ ์์ฑ๋จ
demo.launch() |