ZookChatBot / app.py
JeffJing's picture
Update app.py
81fd3b9
raw
history blame
1.5 kB
import os
import gradio as gr
from revChatGPT.V1 import Chatbot
#if you have OpenAI API key as an environment variable, enable the below
#openai.api_key = os.getenv("OPENAI_API_KEY")
#if you have OpenAI API key as a string, enable the below
#openai.api_key = "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"
start_sequence = "\nAI:"
restart_sequence = "\nHuman: "
prompt = "您好,我是做客ChatBot,基于ChatGPT官网反向工程接口实现的智能对话机器人。\n\n请放心使用,和我对话与在官网直接对ChatGPT对话,得的的回答会完全一样。\n\n您有什么需要?~"
chatbot1 = Chatbot(config={
"email": "jeffjing4@gmail.com",
"password": "Chatgpt!123",
"paid": "True"
})
def openai_create(prompt):
for data in chatbot1.ask(
prompt
):
response = data["message"]
return response
def chatgpt_clone(input, history):
history = history or []
s = list(sum(history, ()))
s.append(input)
inp = ' '.join(s)
output = openai_create(input)
history.append((input, output))
return history, history
block = gr.Blocks()
with block:
gr.Markdown("""<h1><center>做客ChatBot</center></h1>
""")
chatbot = gr.Chatbot()
message = gr.Textbox(placeholder=prompt,label="开聊:")
state = gr.State()
submit = gr.Button("提交")
submit.click(chatgpt_clone, inputs=[message, state], outputs=[chatbot, state])
block.launch(debug = False,auth=("Zookchatbot", "12345678"))