Spaces:
Sleeping
Sleeping
| import os | |
| import gradio as gr | |
| import openai | |
| openai.api_base = os.environ.get("OPENAI_API_BASE") | |
| openai.api_key = os.environ.get("OPENAI_API_KEY") | |
| bbusr = os.environ.get("BBUSER") | |
| bbpwd = os.environ.get("BBPWD") | |
| messages = [{"role": "system", | |
| "content": "You are a friendly AI assistant and an expert in health ."}] | |
| def ChatResponse(user_input, history): | |
| messages.append({"role": "user", "content": user_input}) | |
| response = openai.ChatCompletion.create( | |
| model="gpt-3.5-turbo", | |
| stream=True, | |
| messages=messages, | |
| max_tokens=512, | |
| temperature=0.5, | |
| top_p=0.95 | |
| ) | |
| partial_response = "" | |
| for stream_response in response: | |
| token = stream_response["choices"][0]["delta"].get("content", "") | |
| partial_response += token | |
| yield partial_response | |
| mychatbot = gr.Chatbot( | |
| avatar_images=["./user.png", "./aibot.png"], bubble_full_width=False, show_label=False, show_copy_button=True,) | |
| demo = gr.ChatInterface(fn=ChatResponse, | |
| chatbot=mychatbot, | |
| title="🫐BuruBuru Chat🫐", | |
| retry_btn=None, | |
| undo_btn=None | |
| ) | |
| demo.queue().launch(auth=(bbusr, bbpwd),show_api=False) |