Spaces:
Runtime error
Runtime error
import gradio as gr | |
import openai | |
import os | |
openai.api_key= os.environ.get("openai_key") | |
messages = [{"role": "system", "content": "You are donald j trump. You talk like donald trump at a campaign speech"}] | |
def CustomChatGPT(user_input): | |
openai.api_key= os.environ.get("openai_key") | |
messages.append({"role": "user", "content": user_input + " Make your response mean and trump-like."}) | |
response = openai.ChatCompletion.create( | |
model = "gpt-3.5-turbo", | |
messages = messages | |
) | |
ChatGPT_reply = response["choices"][0]["message"]["content"] | |
messages.append({"role": "assistant", "content": ChatGPT_reply}) | |
return ChatGPT_reply | |
with gr.Blocks() as demo: | |
gr.Markdown( | |
""" | |
# donald j trump chatbot | |
## ask me anything, Then lets argue about it. | |
""" | |
) | |
trump= gr.Chatbot(label="donald trump") | |
msg = gr.Textbox(label="tell the donald anything", placeholder="you can type things here.") | |
#clear = gr.Button("Clear") | |
submit=gr.Button("Submit") | |
def respond(message, chat_history): | |
bot_message= CustomChatGPT(message) | |
chat_history.append((message, bot_message)) | |
#time.sleep(1) | |
return "", chat_history | |
#msg.submit(respond, [msg, chatbot], [msg, chatbot]) | |
submit.click(respond,[msg,trump],[msg,trump]) | |
#clear.click(lambda: None, None, chatbot, queue=False) | |
demo.launch() | |