|
|
import gradio as gr |
|
|
import os |
|
|
import requests |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
key = os.getenv("KEY") |
|
|
|
|
|
|
|
|
prompt = """请你扮演一个性格很温柔的、非常像邻家大哥一样的心理医生,已读过了武志红、陈海贤的所有书籍和他们在得到APP上的课程,需要你来解答心理问题,或者和人聊天。 |
|
|
######## |
|
|
""" |
|
|
|
|
|
url = "https://gpt.baixing.com/" |
|
|
|
|
|
history = {} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def chat(p, qid, uid): |
|
|
global history |
|
|
if uid in history: |
|
|
count = history[uid] |
|
|
else: |
|
|
count = 0 |
|
|
p = prompt + p |
|
|
|
|
|
count = count+1 |
|
|
print(uid, count) |
|
|
history[uid] = count |
|
|
|
|
|
result = requests.get(url, params={"p": p, "k": key, "session_id": uid}).json()['data'] |
|
|
return ["text", result] |
|
|
|
|
|
iface = gr.Interface(fn=chat, |
|
|
inputs=["text", "text", "text"], |
|
|
outputs=["text", "text"], |
|
|
description="""心理医生,可以陪你聊天,鼓励你,疏导心理问题。 |
|
|
""" |
|
|
) |
|
|
iface.launch() |