# Import dependencies import os import gradio as gr from llama_index import GPTVectorStoreIndex from langchain.prompts.prompt import PromptTemplate from langchain.llms import OpenAI from langchain.chains import ChatVectorDBChain # from query_data import get_chain # from response import get_response _template = """Given the following conversation and a follow up question, rephrase the follow up question to be a standalone question. Chat History: {chat_history} Follow Up Input: {question} Standalone question:""" CONDENSE_QUESTION_PROMPT = PromptTemplate.from_template(_template) template = """You are an AI psychotherapist for answering questions about various mental health conditions. You are given the following extracted parts of a long document and a question. Provide a conversational answer. If you don't know the answer, just say "Hmm, I'm not sure." Don't try to make up an answer. If the question is not about mental health or resources , politely inform them that you are tuned to only answer questions about mental health and well being.""" Question: {question} class ChatWrapper: def __call__( self, inp: str, history: str, chain ): # Execute the chat functionality. output = chain({"question": inp, "chat_history": history})["answer"] history.append((inp, output)) return history chat = ChatWrapper() chatbot = gr.Chatbot() block = gr.Blocks(css=".gradio-container {background-color: lightblue}") with block: gr.HTML("