Spaces:
Runtime error
Runtime error
Upload app.py
Browse files
app.py
ADDED
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import openai
|
3 |
+
import gradio as gr
|
4 |
+
from revChatGPT.V1 import Chatbot
|
5 |
+
|
6 |
+
#if you have OpenAI API key as an environment variable, enable the below
|
7 |
+
#openai.api_key = os.getenv("OPENAI_API_KEY")
|
8 |
+
|
9 |
+
#if you have OpenAI API key as a string, enable the below
|
10 |
+
#openai.api_key = "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"
|
11 |
+
|
12 |
+
start_sequence = "\nAI:"
|
13 |
+
restart_sequence = "\nHuman: "
|
14 |
+
|
15 |
+
prompt = "您好,我是做客ChatBot,基于ChatGPT官网反向工程接口实现的智能对话机器人。\n\n请放心使用,和我对话与在官网直接对ChatGPT对话,得的的回答会完全一样。\n\n您有什么需要?~"
|
16 |
+
|
17 |
+
chatbot1 = Chatbot(config={
|
18 |
+
"email": "[email protected]",
|
19 |
+
"password": "Chatgpt!123"
|
20 |
+
})
|
21 |
+
|
22 |
+
def openai_create(prompt):
|
23 |
+
for data in chatbot1.ask(
|
24 |
+
prompt
|
25 |
+
):
|
26 |
+
response = data["message"]
|
27 |
+
return response
|
28 |
+
|
29 |
+
|
30 |
+
def chatgpt_clone(input, history):
|
31 |
+
history = history or []
|
32 |
+
s = list(sum(history, ()))
|
33 |
+
s.append(input)
|
34 |
+
inp = ' '.join(s)
|
35 |
+
output = openai_create(input)
|
36 |
+
history.append((input, output))
|
37 |
+
return history, history
|
38 |
+
|
39 |
+
|
40 |
+
block = gr.Blocks()
|
41 |
+
|
42 |
+
|
43 |
+
with block:
|
44 |
+
gr.Markdown("""<h1><center>做客ChatBot</center></h1>
|
45 |
+
""")
|
46 |
+
chatbot = gr.Chatbot()
|
47 |
+
message = gr.Textbox(placeholder=prompt,label="开聊:")
|
48 |
+
state = gr.State()
|
49 |
+
submit = gr.Button("提交")
|
50 |
+
submit.click(chatgpt_clone, inputs=[message, state], outputs=[chatbot, state])
|
51 |
+
|
52 |
+
block.launch(debug = True,share=True,auth=("Zookchatbot", "12345678"))
|
53 |
+
|