File size: 1,226 Bytes
d051b4e
 
 
287b2b6
d051b4e
 
287b2b6
 
 
 
d051b4e
cdaff4d
 
d051b4e
 
 
cdaff4d
 
d051b4e
cdaff4d
d051b4e
 
 
 
 
 
 
 
 
 
 
7f488d2
d051b4e
 
 
 
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
# import libraries
import os
import gradio as gr
from dotenv import load_dotenv, dotenv_values
import openai

load_dotenv()

openai.organization = os.getenv("ORG_KEY")
openai.api_key = os.getenv("OPENAI_API_KEY")


def ai_response(query):
    completion = openai.ChatCompletion.create(
        model="gpt-3.5-turbo",
        messages=[
            {"role": "assistant", "content": os.getenv("Prompt_doctor") },
            {"role": "user", "content": query }
        ],
        stop = [" Human:", " AI:"]
    )
    return completion["choices"][0]["message"]["content"]


def create_ui(query,past):
    output = ai_response(query)
    past.append((query,output))
    return None , past


with gr.Blocks(theme=gr.themes.Glass()) as demo:
    gr.Markdown("<h1><center>Your AI Therapist</center></h1> <hr> <p> <h3><bold>Introduction: </bold>  This is a AI Therapist Chatbot powered by OpenAI's GPT-3.5 Turbo model, designed to engage with users in a supportive and empathetic manner, providing responses to user queries and messages.</h3> </p> ")
    chatbot = gr.Chatbot()
    msg = gr.Textbox(placeholder="Write your message here")
    msg.submit(create_ui, inputs=[msg,chatbot] , outputs=[msg,chatbot])
demo.launch(share=False)