Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,52 +1,45 @@
|
|
1 |
import os
|
2 |
import gradio as gr
|
3 |
-
from
|
4 |
|
5 |
#if you have OpenAI API key as an environment variable, enable the below
|
6 |
#openai.api_key = os.getenv("OPENAI_API_KEY")
|
7 |
|
8 |
#if you have OpenAI API key as a string, enable the below
|
9 |
-
#openai.api_key = "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"
|
10 |
|
11 |
-
|
12 |
-
|
13 |
|
14 |
-
prompt = "
|
15 |
|
16 |
-
chatbot1 = Chatbot(config={
|
17 |
-
"email": "[email protected]",
|
18 |
-
"password": "Chatgpt!123",
|
19 |
-
"paid": "True"
|
20 |
-
})
|
21 |
|
22 |
def openai_create(prompt):
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
|
28 |
def chatgpt_clone(input, history):
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
|
38 |
|
39 |
block = gr.Blocks()
|
40 |
|
41 |
-
|
42 |
with block:
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
|
|
1 |
import os
|
2 |
import gradio as gr
|
3 |
+
from steamship import Steamship
|
4 |
|
5 |
#if you have OpenAI API key as an environment variable, enable the below
|
6 |
#openai.api_key = os.getenv("OPENAI_API_KEY")
|
7 |
|
8 |
#if you have OpenAI API key as a string, enable the below
|
|
|
9 |
|
10 |
+
client = Steamship(workspace="chatgpt-4")
|
11 |
+
generator = client.use_plugin('gpt-4')
|
12 |
|
13 |
+
prompt = "你好,我是做客ChatBot,当前运行在OpenAI GPT-4模型,欢迎大家通过我体验GPT-4的强大。"
|
14 |
|
|
|
|
|
|
|
|
|
|
|
15 |
|
16 |
def openai_create(prompt):
|
17 |
+
task = generator.generate(text=prompt)
|
18 |
+
task.wait()
|
19 |
+
return task.output.blocks[0].text
|
20 |
+
|
21 |
|
22 |
def chatgpt_clone(input, history):
|
23 |
+
history = history or []
|
24 |
+
s = list(sum(history, ()))
|
25 |
+
s.append(input)
|
26 |
+
inp = ' '.join(s)
|
27 |
+
output = openai_create(input)
|
28 |
+
output = output.replace("\n", "<br>")
|
29 |
+
history.append((input, output))
|
30 |
+
return history, history
|
31 |
|
32 |
|
33 |
block = gr.Blocks()
|
34 |
|
|
|
35 |
with block:
|
36 |
+
gr.Markdown("""<img src="file/ZookChatBot.png">""")
|
37 |
+
chatbot = gr.Chatbot()
|
38 |
+
message = gr.Textbox(placeholder=prompt, label="开聊:")
|
39 |
+
state = gr.State()
|
40 |
+
submit = gr.Button("提交")
|
41 |
+
submit.click(chatgpt_clone,
|
42 |
+
inputs=[message, state],
|
43 |
+
outputs=[chatbot, state])
|
44 |
+
|
45 |
+
block.launch(debug=True, share=True)
|