File size: 1,509 Bytes
0e3fcba
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import os
import openai
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": "[email protected]",
  "password": "Chatgpt!123"
})

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 = True,share=True,auth=("Zookchatbot", "12345678"))