Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
openai.api_key = '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'
|
2 |
+
#ref: https://beta.openai.com/docs/quickstart/start-with-an-instruction
|
3 |
+
#ref: https://beta.openai.com/account/api-keys
|
4 |
+
|
5 |
+
#1: OpenAI Chat
|
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 |
+
#2: Gradio Interface Function
|
19 |
+
def chatbot(input, history=[]):
|
20 |
+
output = openai_chat(input)
|
21 |
+
history.append((input, output))
|
22 |
+
return history, history
|
23 |
+
|
24 |
+
#3: Launch Interface
|
25 |
+
gr.Interface(fn = chatbot,
|
26 |
+
inputs = ["text",'state'],
|
27 |
+
outputs = ["chatbot",'state']).launch(debug = True)
|