Spaces:
Sleeping
Sleeping
File size: 1,565 Bytes
2e8c165 |
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 |
import gradio as gr
import torch
from model_def import RNN
from name_change import hangul_to_roman, lineToTensor
import torch.nn.functional as F
# ๋ชจ๋ธ ๋ก๋
RNN(input_size=57, hidden_size=128, output_size=2)
rnn_load = torch.load('rnn_08050114.pt')
rnn_load.eval()
# ์ฃผ์ด์ง ๋ผ์ธ์ ์ถ๋ ฅ ๋ฐํ
all_categories=['์ฌ์','๋จ์']
def evaluate(line_tensor):
hidden = rnn_load.initHidden()
for i in range(line_tensor.size()[0]):
output, hidden = rnn_load(line_tensor[i], hidden)
return output
def predict(input_line, n_predictions=2):
print('\n> %s' % input_line)
input_line=hangul_to_roman(input_line)
with torch.no_grad():
output = evaluate(lineToTensor(input_line))
probabilities = F.softmax(output, dim=1)
topv, topi = torch.topk(probabilities, n_predictions)
predictions = [(round(topv[0][i].item(), 2), all_categories[topi[0][i].item()]) for i in range(n_predictions)]
return predictions
def name_classifier(name):
result=predict(name)
print(result)
return {result[0][1]: result[0][0], result[1][1]: result[1][0]}
demo = gr.Interface(
fn=name_classifier,
inputs="text",
outputs="label",
title="ํ๊ตญ์ด๋ฆ ์ฑ๋ณ ์์ธก ๋ชจ๋ธ",
description="์ด ๋ชจ๋ธ์ ์
๋ ฅ๋ ์ด๋ฆ์ ๊ธฐ๋ฐ์ผ๋ก ์ฑ๋ณ์ ์์ธกํฉ๋๋ค. ์ฑ์ ์ ์ธํ ์ด๋ฆ์ ์
๋ ฅํ๊ณ ์์ธก๋ ์ฑ๋ณ๊ณผ ๊ทธ ํ๋ฅ ์ ํ์ธํ์ธ์.",
examples=[["ํ์"], ["ํ๋ฐฐ"], ["์๊ฒฝ"]]
)
demo.launch()
|