Spaces:
Runtime error
Runtime error
Create chat_ai.py
Browse files- chat_ai.py +19 -0
chat_ai.py
ADDED
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import openai
|
3 |
+
|
4 |
+
openai.api_key = "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"
|
5 |
+
|
6 |
+
def chatbot(user_input):
|
7 |
+
response = openai.ChatCompletion.create(
|
8 |
+
model="gpt-3.5-turbo",
|
9 |
+
messages=[{"role": "user", "content": user_input}]
|
10 |
+
)
|
11 |
+
return response.choices[0].message['content']
|
12 |
+
|
13 |
+
iface = gr.Interface(
|
14 |
+
chatbot,
|
15 |
+
gr.Textbox(label="User Input"),
|
16 |
+
gr.Textbox(label="Chatbot Response")
|
17 |
+
)
|
18 |
+
|
19 |
+
iface.launch()
|