Spaces:
Runtime error
Runtime error
Commit ·
940bdb9
1
Parent(s): 0261f54
Upload 2 files
Browse files- app.py +34 -0
- requirements.txt +0 -0
app.py
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# download files
|
| 2 |
+
import openai
|
| 3 |
+
import gradio as gr
|
| 4 |
+
# import shutup
|
| 5 |
+
# shutup.please()
|
| 6 |
+
|
| 7 |
+
def chatbot(api_key, input):
|
| 8 |
+
openai.api_key = api_key
|
| 9 |
+
messages = [{"role": "system", "content": "You are a helpful and kind AI Assistant."}]
|
| 10 |
+
|
| 11 |
+
if input:
|
| 12 |
+
messages.append({"role": "user", "content": input})
|
| 13 |
+
chat = openai.ChatCompletion.create(
|
| 14 |
+
model="gpt-3.5-turbo", messages=messages
|
| 15 |
+
)
|
| 16 |
+
reply = chat.choices[0].message.content
|
| 17 |
+
messages.append({"role": "assistant", "content": reply})
|
| 18 |
+
return reply
|
| 19 |
+
|
| 20 |
+
api_key_input = gr.inputs.Textbox(lines=1, label="Enter your API key")
|
| 21 |
+
chat_input = gr.inputs.Textbox(lines=7, label="Chat with AI")
|
| 22 |
+
output_text = gr.outputs.Textbox(label="Reply")
|
| 23 |
+
|
| 24 |
+
def get_reply(api_key, input):
|
| 25 |
+
return chatbot(api_key, input)
|
| 26 |
+
|
| 27 |
+
gr.Interface(
|
| 28 |
+
fn=get_reply,
|
| 29 |
+
inputs=[api_key_input, chat_input],
|
| 30 |
+
outputs=output_text,
|
| 31 |
+
title="AI Chatbot",
|
| 32 |
+
description="Ask anything you want",
|
| 33 |
+
theme="default"
|
| 34 |
+
).launch()
|
requirements.txt
ADDED
|
Binary file (6.81 kB). View file
|
|
|