Spaces:
Runtime error
Runtime error
asuayu
commited on
Commit
•
8f90d15
1
Parent(s):
2c6d855
first add
Browse files- app.py +33 -0
- requirements.txt +1 -0
app.py
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
0# -*- coding: utf-8-*-
|
2 |
+
import openai
|
3 |
+
import gradio as gr
|
4 |
+
import os
|
5 |
+
#机器人女友
|
6 |
+
|
7 |
+
|
8 |
+
openai.api_key = os.environ.get("OPENAI_API_KEY")
|
9 |
+
|
10 |
+
|
11 |
+
|
12 |
+
prompt= "You are a helpful assistant."
|
13 |
+
messages = [
|
14 |
+
{"role": "system", "content": prompt},
|
15 |
+
]
|
16 |
+
|
17 |
+
def chatbot(input):
|
18 |
+
if input:
|
19 |
+
messages.append({"role": "user", "content": input})
|
20 |
+
chat = openai.ChatCompletion.create(
|
21 |
+
model="gpt-3.5-turbo", messages=messages
|
22 |
+
)
|
23 |
+
reply = chat.choices[0].message.content
|
24 |
+
messages.append({"role": "assistant", "content": reply})
|
25 |
+
return reply
|
26 |
+
|
27 |
+
inputs = gr.inputs.Textbox(lines=7, label="通用机器人")
|
28 |
+
outputs = gr.outputs.Textbox(label="通用机器人")
|
29 |
+
|
30 |
+
app=gr.Interface(fn=chatbot, inputs=inputs, outputs=outputs, title="AI机器人",
|
31 |
+
description="你面前的是一个通用机器人,你可以向他提问",
|
32 |
+
theme="compact")
|
33 |
+
app.launch()
|
requirements.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
openai==0.27.0
|