Spaces:
Build error
Build error
添加多轮对话能力:重复对方说话之前会数数,每个人分别数
Browse files
app.py
CHANGED
|
@@ -1,5 +1,7 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
|
|
|
|
|
|
|
| 3 |
# 修改本函数,来实现你自己的 chatbot
|
| 4 |
# p: 对机器人说话的内容
|
| 5 |
# qid: 当前消息的唯一标识。例如 `'bxqid-cManAtRMszw...'`。由平台生成并传递给机器人,以便机器人区分单个问题(写日志、追踪调试、异步回调等)。同步调用可忽略。
|
|
@@ -7,7 +9,14 @@ import gradio as gr
|
|
| 7 |
# 返回值:[type, content]
|
| 8 |
# 详见 https://huggingface.co/spaces/baixing/hackathon_test/blob/main/bot-api.md
|
| 9 |
def chat(p, qid, uid):
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
iface = gr.Interface(fn=chat,
|
| 13 |
inputs=["text", "text", "text"],
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
+
history = {}
|
| 4 |
+
|
| 5 |
# 修改本函数,来实现你自己的 chatbot
|
| 6 |
# p: 对机器人说话的内容
|
| 7 |
# qid: 当前消息的唯一标识。例如 `'bxqid-cManAtRMszw...'`。由平台生成并传递给机器人,以便机器人区分单个问题(写日志、追踪调试、异步回调等)。同步调用可忽略。
|
|
|
|
| 9 |
# 返回值:[type, content]
|
| 10 |
# 详见 https://huggingface.co/spaces/baixing/hackathon_test/blob/main/bot-api.md
|
| 11 |
def chat(p, qid, uid):
|
| 12 |
+
global history
|
| 13 |
+
if uid in history:
|
| 14 |
+
count = history[uid]
|
| 15 |
+
else:
|
| 16 |
+
count = 0
|
| 17 |
+
count = count+1
|
| 18 |
+
history[uid] = count # 统计每个 uid 说过的话的条数
|
| 19 |
+
return ["text", f"{count} 我听到你刚说:{p}"]
|
| 20 |
|
| 21 |
iface = gr.Interface(fn=chat,
|
| 22 |
inputs=["text", "text", "text"],
|