File size: 2,522 Bytes
6ccd417
 
 
dae67e9
 
69570eb
10c5e96
dae67e9
6ccd417
 
 
 
 
 
 
 
 
 
 
 
 
4db1eca
6ccd417
 
 
 
 
 
4db1eca
 
 
6ccd417
 
 
 
 
 
 
 
4db1eca
6ccd417
 
 
 
 
 
 
 
0533c1e
 
aa0f2ec
 
 
dae67e9
bbc20a6
dae67e9
 
bbc20a6
6ccd417
aa0f2ec
c8a4b93
bbc20a6
 
 
 
 
 
 
7ffda7a
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
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 = []

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_primary="*neutral_950",
        background_fill_primary_dark="*neutral_950",
        
        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

if __name__=='__main__':
    theme = prepare_theme()
    with open('README.txt', 'r') as f:
        readme = f.read()
        
    MODELS.append(T5())
    MODELS[0].placeholder = '์—ฐ์•  ๊ด€๋ จ ์งˆ๋ฌธ์„ ์ž…๋ ฅํ•˜์„ธ์š”!'
    if not LOCAL_TEST:
        MODELS.append(KoAlpaca())
        MODELS[1].placeholder = '์—ฐ์•  ๊ด€๋ จ ์งˆ๋ฌธ์„ ์ž…๋ ฅํ•˜์„ธ์š”. (KoAlpaca๋Š” ์ถ”๋ก  ์‹œ 1๋ถ„ ์ด์ƒ ์†Œ์š”๋ฉ๋‹ˆ๋‹ค!)'

    with gr.Blocks(theme=prepare_theme()) as demo:
        gr.HTML("<h1>KOMUChat : Korean community-style relationship counseling chatbot</h1>")
        with gr.Tab("์†Œ๊ฐœ"):
            gr.Markdown(readme)
        for i in range(len(MODELS)):
            with gr.Tab(MODEL_STRS[i]):
                chatbot = gr.Chatbot(label=MODEL_STRS[i], bubble_full_width=False)
                txt = gr.Textbox(show_label=False, placeholder=MODELS[i].placeholder, container=False, elem_id=i)
                txt.submit(MODELS[i].chat, [txt, chatbot], [txt, chatbot])

    demo.launch(debug=True, share=True)