AutoGeneralAI commited on
Commit
8cb5e9c
1 Parent(s): 7b9b548

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -0
app.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import openai
2
+ import gradio as gr
3
+
4
+ openai.api_key = "sk-" # Replace this with your API key: https://beta.openai.com/docs/quickstart/add-your-api-key
5
+
6
+ def openai_chat(prompt):
7
+ completions = openai.Completion.create(
8
+ engine="text-davinci-003",
9
+ prompt=prompt,
10
+ max_tokens=1024,
11
+ n=1,
12
+ temperature=0.5,
13
+ )
14
+
15
+ message = completions.choices[0].text
16
+ return message.strip()
17
+
18
+ def chatbot(key, input, history=[]):
19
+ openai.api_key = key
20
+ output = openai_chat(input)
21
+ history.append((input, output))
22
+ return history, history
23
+
24
+ gr.Interface(fn = chatbot,
25
+ inputs = ["text","text",'state'],
26
+ outputs = ["chatbot",'state']).launch(debug = True)