LeeKinXUn
commited on
Commit
•
2345f47
1
Parent(s):
9df842b
Add application file
Browse files- app.py +28 -0
- requirements.txt +1 -0
app.py
ADDED
@@ -0,0 +1,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)
|
requirements.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
openai
|