File size: 1,656 Bytes
7b51197
53a5d44
c8b7166
7b51197
c8b7166
53a5d44
38ff233
53a5d44
 
6c70e95
53a5d44
 
 
 
 
 
 
 
 
7b51197
b3e736d
 
38ff233
e7aed4c
38ff233
b3e736d
 
7b51197
f9bbc56
7b51197
 
 
15d19d3
7b51197
08c3c48
7b51197
53a5d44
7b51197
 
 
53a5d44
7b51197
 
 
53a5d44
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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):
    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()