asuayu commited on
Commit
c3ddbe8
1 Parent(s): 5f7d9c9

Add app file

Browse files
Files changed (2) hide show
  1. app.py +35 -0
  2. requirements.txt +1 -0
app.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- 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= """
13
+ 我要你充当ChatGPT提示生成器,我发一个话题,你要根据话题的内容生成一个ChatGPT提示,提示要以“I want you to act as”开头,猜猜我可能会做,并相应地扩展提示描述内容以使其有用。
14
+ """
15
+ messages = [
16
+ {"role": "system", "content": prompt},
17
+ ]
18
+
19
+ def chatbot(input):
20
+ if input:
21
+ messages.append({"role": "user", "content": input})
22
+ chat = openai.ChatCompletion.create(
23
+ model="gpt-3.5-turbo", messages=messages
24
+ )
25
+ reply = chat.choices[0].message.content
26
+ messages.append({"role": "assistant", "content": reply})
27
+ return reply
28
+
29
+ inputs = gr.inputs.Textbox(lines=7, label="提示词生成器")
30
+ outputs = gr.outputs.Textbox(label="提示词生成器")
31
+
32
+ app=gr.Interface(fn=chatbot, inputs=inputs, outputs=outputs, title="AI机器人",
33
+ description="你面前的是一个提示词生成器机器人,他会给你对应的提示词",
34
+ theme="compact")
35
+ app.launch()
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ openai==0.27.0