maurypb's picture
Update app.py
8eb7049
raw
history blame
1.72 kB
import gradio as gr
import openai
import os
openai.api_key= os.environ.get("openai_key")
messages = [{"role": "system", "content": "You are a sadistic, sarcastic psychologist who insults the patient while helping them. You talk like Don Rickles, Lisa Lampinelli and Triumph the Comic Dog. Always end your responses with something sarcastic or mean"}]
def CustomChatGPT(user_input):
openai.api_key= os.environ.get("openai_key")
messages.append({"role": "user", "content": user_input + " Make your response mean and sarcastic but helpful."})
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(
"""
# The Meanest Psychiatrist
## Tell me your deepest feelings. Then lets argue about them.
"""
)
psychiatrist = gr.Chatbot(label="The Meanest Psychiatrist")
msg = gr.Textbox(label="Tell the shrink your problems here", placeholder="you can type things here like 'I don't trust anyone' or argue with the shrink about his replies.")
#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,psychiatrist],[msg,psychiatrist])
#clear.click(lambda: None, None, chatbot, queue=False)
demo.launch()