funkykong888 commited on
Commit
8e7152a
·
verified ·
1 Parent(s): 0e3305a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -3
app.py CHANGED
@@ -21,7 +21,7 @@ def chatbot(input_text, chat_history):
21
  # 応答の生成
22
  outputs = model.generate(
23
  inputs.input_ids,
24
- attention_mask=inputs.attention_mask, # attention_maskを指定
25
  max_length=512,
26
  pad_token_id=tokenizer.eos_token_id,
27
  do_sample=True,
@@ -32,7 +32,10 @@ def chatbot(input_text, chat_history):
32
 
33
  # 応答の整形
34
  response = response.split("ボット:")[-1].strip()
35
- chat_history.append((input_text, response))
 
 
 
36
 
37
  return chat_history, chat_history
38
 
@@ -44,7 +47,7 @@ interface = gr.Interface(
44
  gr.State() # チャット履歴
45
  ],
46
  outputs=[
47
- gr.Chatbot(label="ボット応答", type="messages"), # 出力形式を指定
48
  gr.State() # チャット履歴の状態
49
  ],
50
  title="日本語チャットボット",
 
21
  # 応答の生成
22
  outputs = model.generate(
23
  inputs.input_ids,
24
+ attention_mask=inputs.attention_mask,
25
  max_length=512,
26
  pad_token_id=tokenizer.eos_token_id,
27
  do_sample=True,
 
32
 
33
  # 応答の整形
34
  response = response.split("ボット:")[-1].strip()
35
+
36
+ # チャット履歴に追加(辞書形式に変換)
37
+ chat_history.append({"role": "user", "content": input_text})
38
+ chat_history.append({"role": "assistant", "content": response})
39
 
40
  return chat_history, chat_history
41
 
 
47
  gr.State() # チャット履歴
48
  ],
49
  outputs=[
50
+ gr.Chatbot(label="ボット応答", type="messages"), # 出力形式をmessagesに指定
51
  gr.State() # チャット履歴の状態
52
  ],
53
  title="日本語チャットボット",