Spaces:
No application file
No application file
baotoan2002
commited on
Commit
•
0bd325c
1
Parent(s):
cabccda
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import openai
|
2 |
+
import gradio as gr
|
3 |
+
|
4 |
+
openai.api_key = "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"
|
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(input, history=[]):
|
19 |
+
output = openai_chat(input)
|
20 |
+
history.append((input, output))
|
21 |
+
return history, history
|
22 |
+
|
23 |
+
gr.Interface(fn = chatbot,
|
24 |
+
inputs = ["text",'state'],
|
25 |
+
outputs = ["chatbot",'state']).launch(debug = False, inline = False)
|