Spaces:
Runtime error
Runtime error
add comments
Browse files
app.py
CHANGED
|
@@ -2,14 +2,29 @@ import gradio as gr
|
|
| 2 |
import os
|
| 3 |
import requests
|
| 4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
key = os.getenv("baixing_key")
|
| 6 |
url = "https://gpt.baixing.com/"
|
| 7 |
|
|
|
|
|
|
|
| 8 |
def chat(p, qid, uid):
|
| 9 |
-
result = requests.get(url, params={"p": p, "k": key}).json()['data']
|
| 10 |
return ["text", result]
|
| 11 |
|
| 12 |
iface = gr.Interface(fn=chat,
|
| 13 |
inputs=["text", "text", "text"],
|
| 14 |
-
outputs=["text", "text"]
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
iface.launch()
|
|
|
|
| 2 |
import os
|
| 3 |
import requests
|
| 4 |
|
| 5 |
+
# 如果你只打算通过 prompt 来定制机器人的行为,只需要修改这段 prompt 就够了。
|
| 6 |
+
prompt = """请将下述文字改成只用emoji来表达,不要输出任何其它字符
|
| 7 |
+
然后空两行,给出emoji表达的回复
|
| 8 |
+
########
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
"""
|
| 12 |
+
|
| 13 |
+
|
| 14 |
key = os.getenv("baixing_key")
|
| 15 |
url = "https://gpt.baixing.com/"
|
| 16 |
|
| 17 |
+
# 此处只是最简单的实现单轮对话,qid 和 uid 可以忽略
|
| 18 |
+
# 如果要实现多轮对话,可以用本地 sqlite 等方式存储数据,并根据 uid 找到对话历史。
|
| 19 |
def chat(p, qid, uid):
|
| 20 |
+
result = requests.get(url, params={"p": prompt + p, "k": key}).json()['data']
|
| 21 |
return ["text", result]
|
| 22 |
|
| 23 |
iface = gr.Interface(fn=chat,
|
| 24 |
inputs=["text", "text", "text"],
|
| 25 |
+
outputs=["text", "text"],
|
| 26 |
+
description="""这是一个极其简单的示范程序,把你的问话翻译成 emoji 并只用 emoji 来回答。
|
| 27 |
+
[参考文档](https://huggingface.co/spaces/baixing/hackathon_test/blob/main/bot-api.md) [极简 bot 示例](https://huggingface.co/spaces/baixing/hackathon_chatbot_simple) [Q & A](https://huggingface.co/spaces/baixing/hackathon_test/blob/main/qna.md)
|
| 28 |
+
"""
|
| 29 |
+
)
|
| 30 |
iface.launch()
|