CoolFace
Apppublic

roger33303/GenerativeAI-Chatbot.AI-Therapist

sourceHugging Facemitupdated 2y agoView on Hugging Face
6likes
app.py36 linesDownload Raw Back to root
1# import libraries2import os3import gradio as gr4from dotenv import load_dotenv, dotenv_values5import openai6 7load_dotenv()8 9openai.organization = os.getenv("ORG_KEY")10openai.api_key = os.getenv("OPENAI_API_KEY")11 12 13def ai_response(query):14    completion = openai.ChatCompletion.create(15        model="gpt-3.5-turbo",16        messages=[17            {"role": "assistant", "content": os.getenv("Prompt_doctor") },18            {"role": "user", "content": query }19        ],20        stop = [" Human:", " AI:"]21    )22    return completion["choices"][0]["message"]["content"]23 24 25def create_ui(query,past):26    output = ai_response(query)27    past.append((query,output))28    return None , past29 30 31with gr.Blocks(theme=gr.themes.Glass()) as demo:32    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> ")33    chatbot = gr.Chatbot()34    msg = gr.Textbox(placeholder="Write your message here")35    msg.submit(create_ui, inputs=[msg,chatbot] , outputs=[msg,chatbot])36demo.launch(share=False)