# Import dependencies import gradio as gr # from llama_index import GPTVectorStoreIndex # from query_data import get_chain from langchain.chat_models import ChatOpenAI from langchain import LLMChain from langchain.chat_models import ChatOpenAI from langchain.prompts.chat import ( ChatPromptTemplate, SystemMessagePromptTemplate, HumanMessagePromptTemplate, ) from langchain.agents import initialize_agent, AgentType # initialize OpenAI chatbot agent llm = ChatOpenAI(temperature=0) agent = initialize_agent(llm, AgentType.CHAT_CONVERSATIONAL_REACT_DESCRIPTION) # define function to get chatbot response def get_response(text): response = agent.run(text) return response # create Gradio interface iface = gr.Interface(fn=get_response, inputs="text", outputs="text") # launch interface iface.launch() """chat = ChatOpenAI(temperature=0) template = "You are a brilliant and empathic counselor. You encourage to share and provide resources when asked." system_message_prompt = SystemMessagePromptTemplate.from_template(template) human_template = "{text}" human_message_prompt = HumanMessagePromptTemplate.from_template(human_template) chat_prompt = ChatPromptTemplate.from_messages([system_message_prompt, human_message_prompt]) chain = LLMChain(llm=chat, prompt=chat_prompt) chain.run(text="I feel lonely.")""" # Execute the chat functionality. """ with gr.Blocks(theme=gr.themes.Soft()) as demo: gr.HTML("

Omdena AI Chatbot For Mental Health and Wellbeing

") gr.HTML("WELCOME
" "I am an AI ChatBot and I am here to assist you with whatever is bothering you. " "Our conversation is strictly confidential and I will not remember it when you come back another time." ) chatbot = gr.Chatbot() chat_message = gr.Textbox(label="What would you like to chat about?") response = gr.Textbox """ # define function to get chatbot response """ def get_response(text): response = agent.run(text) return response """ """ def respond(chat_message, chat_history): response = get_chain(chat_message, chat_history) chat_history.append((chat_message, response)) return "", chat_history """ """ with gr.Row(): send = gr.Button(value="Send").style(full_width=False) clear = gr.Button(value="Clear Chat").style(full_width=False) gr.Examples( examples=[ "I feel lonely", "I'm having problems at home", "I am looking for some resources", ], inputs=chat_message ) send.click(get_response(chat_message)) clear.click(lambda: None, None, chatbot, queue=False) if __name__ == "__main__": demo.launch(debug=True) """