Spaces:
Paused
Paused
ElPlaguister
commited on
Commit
โข
aa0f2ec
1
Parent(s):
aff19eb
Feat New Design with Dynamic Tabs
Browse files- README.txt +19 -0
- app.py +15 -46
- koalpaca.py +3 -1
- model.py +10 -2
- t5.py +2 -0
README.txt
ADDED
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# KOMUCHAT : Korean community-style relationship counseling chabot
|
2 |
+
KOMUChat: ์จ๋ผ์ธ ์ปค๋ฎค๋ํฐ ์คํ์ผ์ ์ฐ์ ์๋ด์ฑ๋ด
|
3 |
+
### ๊ฐ์
|
4 |
+
์ฌ๋๋ค์ ์ค์ ๋ํ๋ฅผ ๋ฐ์ํ๊ธฐ ์ํด ํ๊ตญ ์ปค๋ฎค๋ํฐ ์ํจ์ฝ๋ฆฌ์ + ์ธ์คํฐ์ฆ์์ ์์งํ ์ฝ 3๋ง๊ฑด์ ์ง๋ฌธ-๋ต๋ณ ๋ํ ๋ฐ์ดํฐ์
์ผ๋ก ํ์ต์ํจ ์ฑ๋ด<br>
|
5 |
+
์ด๋ณ, ๋ฐ์ดํธ์ฝ์ค, ์ ๋ฌผ ๋ฑ ์ฐ์ ์ ๊ด๋ จ๋ ์ง๋ฌธ์ ๋ํด ์จ๋ผ์ธ ์ปค๋ฎค๋ํฐ์์ ์๋ดํ๋ ๊ฒ ๊ฐ์ด ์๋ตํฉ๋๋ค.<br>
|
6 |
+
<b>paust-t5-large</b>๋ชจ๋ธ(ํ๊ท ์๋ต์๊ฐ n์ด)๊ณผ <b>polyglot-ko-12.8b-safetensors</b> ๋ชจ๋ธ(ํ๊ท ์๋ต์๊ฐ n์ด)์ ํ์ธํ๋ํ์ฌ ์ ๊ณตํฉ๋๋ค.<br>
|
7 |
+
๋ฐ๋ชจ์์ ์ ํํ์ฌ ์ด์ฉํด๋ณด์ค ์ ์์ต๋๋ค.
|
8 |
+
|
9 |
+
### ์๋ต์์
|
10 |
+
| Question | Answer |
|
11 |
+
| --- | --- |
|
12 |
+
| ํค์ด์ก์๋๋ค | ํ๋ด ๋ ์ข์ ์ธ์ฐ ๋ํ๋ ๊ฑฐ์ผ |
|
13 |
+
| ๋๋ผ๋ง๋ง ์ฃผ๊ตฌ์ฅ์ฐฝ ๋ณด๋์ค | ๋ญ ๋ณด๊ณ ์์ผ์ ๊ฐ์ |
|
14 |
+
| ๊ฒฐํผ๊น์ง ์๊ฐํ๋ ์ํ์ผ์๋ก ๋ ๊น๊นํ๊ฒ ๋ฐ์ง๊ฒ ๋ผ? | ์๋ฌด๋๋ ๊ทธ๋ฐ ๊ฑฐ ๊ฐ์ |
|
15 |
+
| ISTJ ์ฌ์๊ฐ ๋จ์ํํ
๊ด์ฌ์์ผ๋ฉด ์ด๋ป๊ฒ ํด? | ์ฐ๋ฝ ์์ฃผ ํ๊ณ ์ทจํฅ ๋ง์ด ๋ฌผ์ด๋ณด๊ณ ์์ฃผ๋ ์๋์ด๋ ๊พธ์คํ ๋ง๋๋ ค ํจ |
|
16 |
+
| #์ฒญ์#๋ค์ ์ฐ์ ๋ ๊ฐ์๊ธฐ ์์ํ๋ค๊ณ ์๊ฐํด? | ๋๋ ์ง์ ์ ๊ธฐํ ๊ฒ ์ฐ์ ์ ๋ํ ๊ธฐ๋๊ฐ ๋จ์ด์ง๋ฉด ํ๊ณ ์๋๋ใ
ใ
ใ
|
|
17 |
+
|
18 |
+
### ์ฌ์ฉ๊ธฐ์
|
19 |
+
<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">
|
app.py
CHANGED
@@ -6,7 +6,6 @@ from koalpaca import KoAlpaca
|
|
6 |
LOCAL_TEST = False
|
7 |
MODEL_STRS = ['T5', 'KoAlpaca']
|
8 |
MODELS = []
|
9 |
-
cur_index = 0
|
10 |
|
11 |
def prepare_theme():
|
12 |
theme = gr.themes.Default(primary_hue=colors.gray,
|
@@ -42,56 +41,26 @@ def prepare_theme():
|
|
42 |
)
|
43 |
return theme
|
44 |
|
45 |
-
def chat(message, chat_history):
|
46 |
-
response = MODELS[cur_index].generate(message)
|
47 |
-
chat_history.append((message, response))
|
48 |
-
return "", gr.Chatbot(chat_history, label=MODEL_STRS[cur_index], bubble_full_width=False)
|
49 |
-
|
50 |
-
def change_model_index(idx, chatbot):
|
51 |
-
global cur_index
|
52 |
-
cur_index = idx
|
53 |
-
# print(cur_index)
|
54 |
-
return gr.Chatbot(chatbot, label=MODEL_STRS[cur_index], bubble_full_width=False)
|
55 |
-
|
56 |
if __name__=='__main__':
|
57 |
theme = prepare_theme()
|
58 |
-
|
|
|
|
|
59 |
MODELS.append(T5())
|
60 |
if not LOCAL_TEST:
|
61 |
MODELS.append(KoAlpaca())
|
62 |
|
63 |
-
with gr.Blocks(theme=
|
64 |
-
with gr.
|
65 |
-
gr.
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
### ์๋ต์์
|
76 |
-
| Question | Answer |
|
77 |
-
| --- | --- |
|
78 |
-
| ํค์ด์ก์๋๋ค | ํ๋ด ๋ ์ข์ ์ธ์ฐ ๋ํ๋ ๊ฑฐ์ผ |
|
79 |
-
| ๋๋ผ๋ง๋ง ์ฃผ๊ตฌ์ฅ์ฐฝ ๋ณด๋์ค | ๋ญ ๋ณด๊ณ ์์ผ์ ๊ฐ์ |
|
80 |
-
| ๊ฒฐํผ๊น์ง ์๊ฐํ๋ ์ํ์ผ์๋ก ๋ ๊น๊นํ๊ฒ ๋ฐ์ง๊ฒ ๋ผ? | ์๋ฌด๋๋ ๊ทธ๋ฐ ๊ฑฐ ๊ฐ์ |
|
81 |
-
| ISTJ ์ฌ์๊ฐ ๋จ์ํํ
๊ด์ฌ์์ผ๋ฉด ์ด๋ป๊ฒ ํด? | ์ฐ๋ฝ ์์ฃผ ํ๊ณ ์ทจํฅ ๋ง์ด ๋ฌผ์ด๋ณด๊ณ ์์ฃผ๋ ์๋์ด๋ ๊พธ์คํ ๋ง๋๋ ค ํจ |
|
82 |
-
| #์ฒญ์#๋ค์ ์ฐ์ ๋ ๊ฐ์๊ธฐ ์์ํ๋ค๊ณ ์๊ฐํด? | ๋๋ ์ง์ ์ ๊ธฐํ ๊ฒ ์ฐ์ ์ ๋ํ ๊ธฐ๋๊ฐ ๋จ์ด์ง๋ฉด ํ๊ณ ์๋๋ใ
ใ
ใ
|
|
83 |
-
|
84 |
-
### ์ฌ์ฉ๊ธฐ์
|
85 |
-
<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">
|
86 |
-
""")
|
87 |
-
with gr.Tab("๋ฐ๋ชจ"):
|
88 |
-
with gr.Row():
|
89 |
-
rd = gr.Radio(MODEL_STRS, value='T5', type='index', label='Model Selection', show_label=True, interactive=True)
|
90 |
-
with gr.Column(scale=5): # ์ฑ๋ด ๋ถ๋ถ
|
91 |
-
chatbot = gr.Chatbot(label="T5", bubble_full_width=False)
|
92 |
-
with gr.Row():
|
93 |
-
txt = gr.Textbox(show_label=False, placeholder='์ฐ์ ๊ด๋ จ ์ง๋ฌธ์ ์
๋ ฅํ์ธ์!', container=False)
|
94 |
|
95 |
-
txt.submit(chat, [txt, chatbot], [txt, chatbot])
|
96 |
-
rd.select(change_model_index, [rd, chatbot], [chatbot])
|
97 |
demo.launch(debug=True, share=True)
|
|
|
6 |
LOCAL_TEST = False
|
7 |
MODEL_STRS = ['T5', 'KoAlpaca']
|
8 |
MODELS = []
|
|
|
9 |
|
10 |
def prepare_theme():
|
11 |
theme = gr.themes.Default(primary_hue=colors.gray,
|
|
|
41 |
)
|
42 |
return theme
|
43 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
if __name__=='__main__':
|
45 |
theme = prepare_theme()
|
46 |
+
with open('README.txt', 'r') as f:
|
47 |
+
readme = f.read()
|
48 |
+
|
49 |
MODELS.append(T5())
|
50 |
if not LOCAL_TEST:
|
51 |
MODELS.append(KoAlpaca())
|
52 |
|
53 |
+
with gr.Blocks(theme=prepare_theme()) as demo:
|
54 |
+
with gr.Column():
|
55 |
+
gr.HTML("<h1>KOMUChat</h1>")
|
56 |
+
with gr.Tab("์๊ฐ"):
|
57 |
+
gr.Markdown(readme)
|
58 |
+
for i in range(len(MODELS)):
|
59 |
+
with gr.Tab(MODEL_STRS[i], id=i):
|
60 |
+
with gr.Column():
|
61 |
+
chatbot = gr.Chatbot(label=MODEL_STRS[i], bubble_full_width=False)
|
62 |
+
txt = gr.Textbox(show_label=False, placeholder='์ฐ์ ๊ด๋ จ ์ง๋ฌธ์ ์
๋ ฅํ์ธ์!', container=False, elem_id=i)
|
63 |
+
|
64 |
+
txt.submit(MODELS[i].chat, [txt, chatbot], [txt, chatbot])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
65 |
|
|
|
|
|
66 |
demo.launch(debug=True, share=True)
|
koalpaca.py
CHANGED
@@ -4,7 +4,9 @@ from peft import PeftModel, PeftConfig
|
|
4 |
from model import Model
|
5 |
|
6 |
class KoAlpaca(Model):
|
7 |
-
def __init__(self
|
|
|
|
|
8 |
peft_model_id = "4n3mone/Komuchat-koalpaca-polyglot-12.8B"
|
9 |
config = PeftConfig.from_pretrained(peft_model_id)
|
10 |
self.bnb_config = BitsAndBytesConfig(
|
|
|
4 |
from model import Model
|
5 |
|
6 |
class KoAlpaca(Model):
|
7 |
+
def __init__(self,
|
8 |
+
name:str='KoAlpaca'):
|
9 |
+
self.name = name
|
10 |
peft_model_id = "4n3mone/Komuchat-koalpaca-polyglot-12.8B"
|
11 |
config = PeftConfig.from_pretrained(peft_model_id)
|
12 |
self.bnb_config = BitsAndBytesConfig(
|
model.py
CHANGED
@@ -1,5 +1,8 @@
|
|
|
|
1 |
class Model:
|
2 |
-
def __init__(self
|
|
|
|
|
3 |
self.model = None
|
4 |
self.tokenizer = None
|
5 |
self.gen_config = None
|
@@ -7,4 +10,9 @@ class Model:
|
|
7 |
|
8 |
def generate(self, inputs:str) -> str:
|
9 |
outputs = inputs
|
10 |
-
return outputs
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
class Model:
|
3 |
+
def __init__(self,
|
4 |
+
name:str="Model"):
|
5 |
+
self.name = name
|
6 |
self.model = None
|
7 |
self.tokenizer = None
|
8 |
self.gen_config = None
|
|
|
10 |
|
11 |
def generate(self, inputs:str) -> str:
|
12 |
outputs = inputs
|
13 |
+
return outputs
|
14 |
+
|
15 |
+
def chat(self, message, chat_history):
|
16 |
+
response = self.generate(message)
|
17 |
+
chat_history.append((message, response))
|
18 |
+
return "", gr.Chatbot(chat_history, label=self.name, bubble_full_width=False)
|
t5.py
CHANGED
@@ -2,10 +2,12 @@ from transformers import T5TokenizerFast, T5ForConditionalGeneration, Generation
|
|
2 |
from model import Model
|
3 |
class T5(Model):
|
4 |
def __init__(self,
|
|
|
5 |
model_dir:str='./models/pko_t5_COMU_patience10',
|
6 |
max_input_length:int=64,
|
7 |
max_target_length:int=64
|
8 |
):
|
|
|
9 |
self.model = T5ForConditionalGeneration.from_pretrained(model_dir)
|
10 |
self.tokenizer = T5TokenizerFast.from_pretrained(model_dir)
|
11 |
self.gen_config = GenerationConfig.from_pretrained(model_dir, 'gen_config.json')
|
|
|
2 |
from model import Model
|
3 |
class T5(Model):
|
4 |
def __init__(self,
|
5 |
+
name:str='T5',
|
6 |
model_dir:str='./models/pko_t5_COMU_patience10',
|
7 |
max_input_length:int=64,
|
8 |
max_target_length:int=64
|
9 |
):
|
10 |
+
self.name = name
|
11 |
self.model = T5ForConditionalGeneration.from_pretrained(model_dir)
|
12 |
self.tokenizer = T5TokenizerFast.from_pretrained(model_dir)
|
13 |
self.gen_config = GenerationConfig.from_pretrained(model_dir, 'gen_config.json')
|