Spaces:
Sleeping
Sleeping
Commit
·
d9dc802
1
Parent(s):
5e6037d
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import gradio as gr
|
| 3 |
+
import openai
|
| 4 |
+
|
| 5 |
+
openai.api_base = os.environ.get("OPENAI_API_BASE")
|
| 6 |
+
openai.api_key = os.environ.get("OPENAI_API_KEY")
|
| 7 |
+
bbusr = os.environ.get("BBUSER")
|
| 8 |
+
bbpwd = os.environ.get("BBPWD")
|
| 9 |
+
|
| 10 |
+
messages = [{"role": "system",
|
| 11 |
+
"content": "You are a friendly AI assistant and an expert in health ."}]
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
def CustomOpenChat(user_input):
|
| 15 |
+
messages.append({"role": "user", "content": user_input})
|
| 16 |
+
response = openai.ChatCompletion.create(
|
| 17 |
+
model="gpt-3.5-turbo",
|
| 18 |
+
messages=messages,
|
| 19 |
+
max_tokens=256,
|
| 20 |
+
temperature=0.3,
|
| 21 |
+
top_p=0.95
|
| 22 |
+
)
|
| 23 |
+
OpenChat_reply = response["choices"][0]["message"]["content"]
|
| 24 |
+
messages.append({"role": "assistant", "content": OpenChat_reply})
|
| 25 |
+
return OpenChat_reply
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
def chat_response(message, history):
|
| 29 |
+
result = CustomOpenChat(message)
|
| 30 |
+
return result
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
mychatbot = gr.Chatbot(
|
| 34 |
+
avatar_images=["./user.png", "./aibot.png"], bubble_full_width=False, show_label=False, show_copy_button=True,)
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
demo = gr.ChatInterface(fn=chat_response,
|
| 38 |
+
chatbot=mychatbot,
|
| 39 |
+
title="🫐BuruBuru Chat🫐",
|
| 40 |
+
retry_btn=None,
|
| 41 |
+
undo_btn=None
|
| 42 |
+
)
|
| 43 |
+
|
| 44 |
+
demo.queue().launch(auth=(bbuser, bbpwd),show_api=False)
|