File size: 4,426 Bytes
6ccd417
 
 
dae67e9
 
69570eb
10c5e96
dae67e9
 
6ccd417
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0533c1e
dae67e9
6ccd417
10c5e96
6ccd417
94ea8ae
dae67e9
 
94ea8ae
 
dae67e9
0533c1e
 
dae67e9
 
 
 
6ccd417
0533c1e
e58f7cf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7ffda7a
0533c1e
94ea8ae
0533c1e
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import gradio as gr
from gradio.themes.utils import colors
from t5 import T5
from koalpaca import KoAlpaca

LOCAL_TEST = False
MODEL_STRS = ['T5', 'KoAlpaca']
MODELS = []
cur_index = 0

def prepare_theme():
    theme = gr.themes.Default(primary_hue=colors.gray, 
                            secondary_hue=colors.emerald,
                            neutral_hue=colors.emerald).set(
        body_background_fill="*primary_800",
        body_background_fill_dark="*primary_800",
        
        block_background_fill="*primary_700",
        block_background_fill_dark="*primary_700",
        
        border_color_primary="*secondary_300",
        border_color_primary_dark="*secondary_300",
        block_border_width="3px",
        input_border_width="2px",
        
        input_background_fill="*primary_700",
        input_background_fill_dark="*primary_700",
        
        background_fill_secondary="*primary_700",
        background_fill_secondary_dark="*primary_700",
        
        body_text_color="white",
        body_text_color_dark="white",
        
        block_label_text_color="*secondary_300",
        block_label_text_color_dark="*secondary_300",
        block_label_background_fill="*primary_800",
        block_label_background_fill_dark="*primary_800",
        
        color_accent_soft="*primary_600",
        color_accent_soft_dark="*primary_600",
    )
    return theme

def chat(message, chat_history):
    response = MODELS[cur_index].generate(message)
    chat_history.append((message, response))
    return "", gr.Chatbot(chat_history, label=MODEL_STRS[cur_index], bubble_full_width=False)

def change_model_index(idx, chatbot):
    global cur_index
    cur_index = idx
    # print(cur_index)
    return gr.Chatbot(chatbot, label=MODEL_STRS[cur_index], bubble_full_width=False)

if __name__=='__main__':
    theme = prepare_theme()
    
    MODELS.append(T5())
    if not LOCAL_TEST:
        MODELS.append(KoAlpaca())

    with gr.Blocks(theme=theme) as demo:
        with gr.Tab("์†Œ๊ฐœ"):
            gr.Markdown(
        """
        # KOMUCHAT : Korean community-style relationship counseling chabot
        KOMUChat: ์˜จ๋ผ์ธ ์ปค๋ฎค๋‹ˆํ‹ฐ ์Šคํƒ€์ผ์˜ ์—ฐ์• ์ƒ๋‹ด์ฑ—๋ด‡
        ### ๊ฐœ์š”
        ์‚ฌ๋žŒ๋“ค์˜ ์‹ค์ œ ๋Œ€ํ™”๋ฅผ ๋ฐ˜์˜ํ•˜๊ธฐ ์œ„ํ•ด ํ•œ๊ตญ ์ปค๋ฎค๋‹ˆํ‹ฐ ์—ํŽจ์ฝ”๋ฆฌ์•„ + ์ธ์Šคํ‹ฐ์ฆˆ์—์„œ ์ˆ˜์ง‘ํ•œ ์•ฝ 3๋งŒ๊ฑด์˜ ์งˆ๋ฌธ-๋‹ต๋ณ€ ๋Œ€ํ™” ๋ฐ์ดํ„ฐ์…‹์œผ๋กœ ํ•™์Šต์‹œํ‚จ ์ฑ—๋ด‡<br>
        ์ด๋ณ„, ๋ฐ์ดํŠธ์ฝ”์Šค, ์„ ๋ฌผ ๋“ฑ ์—ฐ์• ์™€ ๊ด€๋ จ๋œ ์งˆ๋ฌธ์— ๋Œ€ํ•ด ์˜จ๋ผ์ธ ์ปค๋ฎค๋‹ˆํ‹ฐ์—์„œ ์ƒ๋‹ดํ•˜๋Š” ๊ฒƒ ๊ฐ™์ด ์‘๋‹ตํ•ฉ๋‹ˆ๋‹ค.<br>
        <b>paust-t5-large</b>๋ชจ๋ธ(ํ‰๊ท  ์‘๋‹ต์‹œ๊ฐ„ n์ดˆ)๊ณผ <b>polyglot-ko-12.8b-safetensors</b> ๋ชจ๋ธ(ํ‰๊ท  ์‘๋‹ต์‹œ๊ฐ„ n์ดˆ)์„ ํŒŒ์ธํŠœ๋‹ํ•˜์—ฌ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค.<br> 
        ๋ฐ๋ชจ์—์„œ ์„ ํƒํ•˜์—ฌ ์ด์šฉํ•ด๋ณด์‹ค ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

        ### ์‘๋‹ต์˜ˆ์‹œ
        | Question | Answer |
        | --- | --- |
        | ํ—ค์–ด์กŒ์๋‹ˆ๋‹ค | ํž˜๋‚ด ๋” ์ข‹์€ ์ธ์—ฐ ๋‚˜ํƒ€๋‚ ๊ฑฐ์•ผ |
        | ๋“œ๋ผ๋งˆ๋งŒ ์ฃผ๊ตฌ์žฅ์ฐฝ ๋ณด๋Š”์ค‘ | ๋ญ ๋ณด๊ณ  ์žˆ์œผ์‹ ๊ฐ€์š” |
        | ๊ฒฐํ˜ผ๊นŒ์ง€ ์ƒ๊ฐํ•˜๋Š” ์ƒํƒœ์ผ์ˆ˜๋ก ๋” ๊น๊นํ•˜๊ฒŒ ๋”ฐ์ง€๊ฒŒ ๋ผ? | ์•„๋ฌด๋ž˜๋„ ๊ทธ๋Ÿฐ ๊ฑฐ ๊ฐ™์•„ |
        | ISTJ ์—ฌ์ž๊ฐ€ ๋‚จ์žํ•œํ…Œ ๊ด€์‹ฌ์žˆ์œผ๋ฉด ์–ด๋–ป๊ฒŒ ํ•ด? | ์—ฐ๋ฝ ์ž์ฃผ ํ•˜๊ณ  ์ทจํ–ฅ ๋งŽ์ด ๋ฌผ์–ด๋ณด๊ณ  ์ž์ฃผ๋Š” ์•„๋‹ˆ์–ด๋„ ๊พธ์ค€ํžˆ ๋งŒ๋‚˜๋ ค ํ•จ |
        | #์ฒญ์ž#๋“ค์•„ ์—ฐ์• ๋Š” ๊ฐ‘์ž๊ธฐ ์‹œ์ž‘ํ•œ๋‹ค๊ณ  ์ƒ๊ฐํ•ด? | ๋‚˜๋Š” ์ง„์ž ์‹ ๊ธฐํ•œ ๊ฒŒ ์—ฐ์• ์— ๋Œ€ํ•œ ๊ธฐ๋Œ€๊ฐ€ ๋–จ์–ด์ง€๋ฉด ํ•˜๊ณ  ์žˆ๋”๋ž”ใ…‹ใ…‹ใ…‹ |

        ### ์‚ฌ์šฉ๊ธฐ์ˆ 
        <img src="https://img.shields.io/badge/Python-3776AB?style=for-the-badge&logo=Python&logoColor=white"><img src="https://img.shields.io/badge/PyTorch-EE4C2C?style=for-the-badge&logo=PyTorch&logoColor=white">
        """)
        with gr.Tab("๋ฐ๋ชจ"):
            with gr.Row():
                rd = gr.Radio(MODEL_STRS, value='T5', type='index', label='Model Selection', show_label=True, interactive=True)
                with gr.Column(scale=5): # ์ฑ—๋ด‡ ๋ถ€๋ถ„ 
                    chatbot = gr.Chatbot(label="T5", bubble_full_width=False)
                    with gr.Row():
                        txt = gr.Textbox(show_label=False, placeholder='์—ฐ์•  ๊ด€๋ จ ์งˆ๋ฌธ์„ ์ž…๋ ฅํ•˜์„ธ์š”!', container=False)

        txt.submit(chat, [txt, chatbot], [txt, chatbot])
        rd.select(change_model_index, [rd, chatbot], [chatbot])
    demo.launch(debug=True, share=True)