File size: 1,397 Bytes
aa6883f
 
53a2deb
aa6883f
ad27618
67af7f1
 
 
 
 
faea98c
 
 
 
67af7f1
100a421
 
 
67af7f1
ad27618
 
 
d2a8971
 
 
 
 
ad27618
 
d2a8971
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
import gradio as gr

gr.HTML("Omdena AI Chatbot For Mental Health and Well Being")


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, history

chatbot = gr.Chatbot()

chat = ChatWrapper()

block = gr.Blocks(css=".gradio-container {background-color: gray}")

with block:
    with gr.Row():
        disclaimer = gr.Textbox(
            "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?",
            placeholder="Ask questions about the most recent state of the union",
            lines=1,
        )
        submit = gr.Button(value="Send", variant="secondary").style(full_width=False)

    gr.Examples(
        examples=[
            "I'm having problems at home",
            "I am jumpy when I hear a loud noise and I feel scared all the time",
                 ],
        inputs=message,
    )

    submit.click(chat, inputs=[message], outputs=[chatbot])
   
block.launch(debug=True)