roger33303's picture
Update app.py
7f488d2 verified
# 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)