Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -4,9 +4,11 @@ import torch
|
|
4 |
|
5 |
MODEL_NAME = "lcw99/ko-dialoGPT-korean-chit-chat"
|
6 |
|
|
|
7 |
tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
|
8 |
model = AutoModelForCausalLM.from_pretrained(MODEL_NAME)
|
9 |
|
|
|
10 |
def chat_with_ai(history, message):
|
11 |
input_text = message + tokenizer.eos_token
|
12 |
input_ids = tokenizer.encode(input_text, return_tensors="pt")
|
@@ -14,17 +16,22 @@ def chat_with_ai(history, message):
|
|
14 |
response_ids = model.generate(input_ids, max_length=100, pad_token_id=tokenizer.eos_token_id)
|
15 |
response_text = tokenizer.decode(response_ids[:, input_ids.shape[-1]:][0], skip_special_tokens=True)
|
16 |
|
17 |
-
history.append(
|
18 |
-
history.append({"role": "assistant", "content": response_text})
|
19 |
|
20 |
-
return history, ""
|
21 |
|
|
|
22 |
with gr.Blocks() as demo:
|
23 |
-
|
24 |
-
|
|
|
|
|
25 |
clear_btn = gr.Button("์ด๊ธฐํ")
|
26 |
|
|
|
27 |
message.submit(chat_with_ai, [chatbot, message], [chatbot, message])
|
|
|
|
|
28 |
clear_btn.click(lambda: [], [], chatbot)
|
29 |
|
30 |
# โ
์๋ฒ ํฌํธ ๋ฐ ์ฃผ์ ์ถ๊ฐ
|
|
|
4 |
|
5 |
MODEL_NAME = "lcw99/ko-dialoGPT-korean-chit-chat"
|
6 |
|
7 |
+
# ํ ํฌ๋์ด์ ๋ฐ ๋ชจ๋ธ ๋ก๋
|
8 |
tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
|
9 |
model = AutoModelForCausalLM.from_pretrained(MODEL_NAME)
|
10 |
|
11 |
+
# ์ฑ๋ด ์๋ต ํจ์
|
12 |
def chat_with_ai(history, message):
|
13 |
input_text = message + tokenizer.eos_token
|
14 |
input_ids = tokenizer.encode(input_text, return_tensors="pt")
|
|
|
16 |
response_ids = model.generate(input_ids, max_length=100, pad_token_id=tokenizer.eos_token_id)
|
17 |
response_text = tokenizer.decode(response_ids[:, input_ids.shape[-1]:][0], skip_special_tokens=True)
|
18 |
|
19 |
+
history.append((message, response_text)) # Gradio Chatbot ํ์ ์ ์ง
|
|
|
20 |
|
21 |
+
return history, "" # ์
๋ ฅ์ฐฝ ๋น์ฐ๊ธฐ
|
22 |
|
23 |
+
# Gradio ์ธํฐํ์ด์ค ์ค์
|
24 |
with gr.Blocks() as demo:
|
25 |
+
gr.Markdown("## ๐จ๏ธ Ko-DialoGPT Chatbot")
|
26 |
+
|
27 |
+
chatbot = gr.Chatbot(label="Ko-DialoGPT Chatbot")
|
28 |
+
message = gr.Textbox(label="์
๋ ฅ ๋ฉ์์ง", placeholder="๋ฉ์์ง๋ฅผ ์
๋ ฅํ์ธ์...")
|
29 |
clear_btn = gr.Button("์ด๊ธฐํ")
|
30 |
|
31 |
+
# ๋ฉ์์ง ์
๋ ฅ ์ ์ฑํ
๊ธฐ๋ก ์
๋ฐ์ดํธ ๋ฐ ์
๋ ฅ์ฐฝ ์ด๊ธฐํ
|
32 |
message.submit(chat_with_ai, [chatbot, message], [chatbot, message])
|
33 |
+
|
34 |
+
# ์ด๊ธฐํ ๋ฒํผ ํด๋ฆญ ์ ์ฑํ
๊ธฐ๋ก ์ญ์
|
35 |
clear_btn.click(lambda: [], [], chatbot)
|
36 |
|
37 |
# โ
์๋ฒ ํฌํธ ๋ฐ ์ฃผ์ ์ถ๊ฐ
|