Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import openai
|
2 |
+
|
3 |
+
import gradio as gr
|
4 |
+
|
5 |
+
|
6 |
+
|
7 |
+
openai.api_key = "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"
|
8 |
+
|
9 |
+
|
10 |
+
|
11 |
+
messages = [
|
12 |
+
|
13 |
+
{"role": "system", "content": "You are a helpful and kind AI Assistant."},
|
14 |
+
|
15 |
+
]
|
16 |
+
|
17 |
+
|
18 |
+
|
19 |
+
def chatbot(input):
|
20 |
+
|
21 |
+
if input:
|
22 |
+
|
23 |
+
messages.append({"role": "user", "content": input})
|
24 |
+
|
25 |
+
chat = openai.ChatCompletion.create(
|
26 |
+
|
27 |
+
model="gpt-3.5-turbo", messages=messages
|
28 |
+
|
29 |
+
)
|
30 |
+
|
31 |
+
reply = chat.choices[0].message.content
|
32 |
+
|
33 |
+
messages.append({"role": "assistant", "content": reply})
|
34 |
+
|
35 |
+
return reply
|
36 |
+
|
37 |
+
|
38 |
+
|
39 |
+
inputs = gr.inputs.Textbox(lines=7, label="Chat with AI")
|
40 |
+
|
41 |
+
outputs = gr.outputs.Textbox(label="Reply")
|
42 |
+
|
43 |
+
|
44 |
+
|
45 |
+
gr.Interface(fn=chatbot, inputs=inputs, outputs=outputs, title="AI Chatbot",
|
46 |
+
|
47 |
+
description="Ask anything you want",
|
48 |
+
|
49 |
+
theme="compact").launch(share=True)
|