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()