Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,28 +1,28 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
4 |
|
5 |
-
os.environ[
|
6 |
-
os.environ[
|
7 |
-
openai.api_key = '
|
8 |
|
9 |
-
|
10 |
-
{
|
11 |
]
|
12 |
|
13 |
-
def
|
14 |
-
|
15 |
-
messages.append({
|
16 |
-
|
17 |
-
|
18 |
)
|
19 |
-
|
20 |
-
messages.append({
|
21 |
-
|
22 |
|
23 |
-
inputs = Textbox(lines=
|
24 |
-
outputs = Textbox(lines=
|
25 |
|
26 |
-
gr.Interface(fn=ChatGPT_Bot, inputs=inputs, outputs=outputs, title=
|
27 |
-
description=
|
28 |
-
|
|
|
1 |
+
import openai,os
|
2 |
+
import gradio as gr
|
3 |
+
from gradio.components import Textbox
|
4 |
|
5 |
+
os.environ["http_proxy"] = "http://localhost:7890"
|
6 |
+
os.environ["https_proxy"] = "http://localhost:7890"
|
7 |
+
openai.api_key = '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'
|
8 |
|
9 |
+
messages = [
|
10 |
+
{"role": "system", "content": "You are a helpful and kind AI Assistant."},
|
11 |
]
|
12 |
|
13 |
+
def ChatGPT_Bot(input):
|
14 |
+
if input:
|
15 |
+
messages.append({"role": "user", "content": input})
|
16 |
+
chat = openai.ChatCompletion.create(
|
17 |
+
model="gpt-3.5-turbo", messages=messages
|
18 |
)
|
19 |
+
reply = chat.choices[0].message.content
|
20 |
+
messages.append({"role": "assistant", "content": reply})
|
21 |
+
return reply
|
22 |
|
23 |
+
inputs = Textbox(lines=7, label="请输入你的问题")
|
24 |
+
outputs = Textbox(lines=7, label="来自ChatGPT的回答")
|
25 |
|
26 |
+
gr.Interface(fn=ChatGPT_Bot, inputs=inputs, outputs=outputs, title="ChatGPT AI助理",
|
27 |
+
description="我是您的AI助理,您可以问任何你想知道的问题",
|
28 |
+
theme=gr.themes.Default()).launch(share=True)
|