File size: 2,417 Bytes
9fd257d
8c0bbb3
9822941
83239e8
232bfe2
 
 
1de6b92
fa8dfd1
2588869
aa6883f
232bfe2
 
 
 
 
 
0ed3433
232bfe2
 
 
 
 
 
 
7a4fffa
a4c568e
67af7f1
 
 
 
1de6b92
 
a4c568e
faea98c
 
a4c568e
100a421
2bd22ae
bfc8030
67af7f1
a49c2de
ad27618
 
1dbe626
11b1ae5
a00efea
791fddb
14a3a73
d2a8971
a49c2de
ad27618
 
d2a8971
1345d55
ad27618
1dbe626
 
936a2cc
760a417
819290f
ad27618
 
bafff02
ad27618
bafff02
ad27618
 
5883c21
ad27618
11b1ae5
ad27618
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# 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("<center><h2>Omdena AI Chatbot For Mental Health and Well Being</h2></center>")
    
    gr.HTML("WELCOME<br>"
            "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."     
        )
        
    with gr.Row():
        message = gr.Textbox(
            label="What would you like to talk about?",
            type = "text",
        )

    with gr.Row():
        submit = gr.Button(value="Send", variant="secondary").style(full_width=False)
        submit.click(chat, inputs=[message], outputs=[chat])
    
    gr.Examples(
        examples=[
            "I feel lonely",
            "I'm having problems at home",
            "I am looking for some resources",
                 ],
        inputs=message,
    ) 


block.launch(debug=True)