Yuchan5386 commited on
Commit
e069dc2
ยท
verified ยท
1 Parent(s): 63caa1b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -5
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({"role": "user", "content": message})
18
- history.append({"role": "assistant", "content": response_text})
19
 
20
- return history, ""
21
 
 
22
  with gr.Blocks() as demo:
23
- chatbot = gr.Chatbot(label="Ko-DialoGPT Chatbot", type="messages")
24
- message = gr.Textbox(label="์ž…๋ ฅ ๋ฉ”์‹œ์ง€")
 
 
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
  # โœ… ์„œ๋ฒ„ ํฌํŠธ ๋ฐ ์ฃผ์†Œ ์ถ”๊ฐ€