File size: 1,755 Bytes
3b4720a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
from chat import langchainning
from checker import checking, health_keywords

def user_input(user):
   
    ans = langchainning().run(user)
    return ans

st.title("Dr. Nohin's Health Advice")
st.caption("Hi Human, How can I help you today?")

if "messages" not in st.session_state:
    st.session_state.messages = []



q = st.chat_input("Type something here....")

def checking(query):
    flag = False
    list_of_words = query.split(" ")
    for i in list_of_words:
        if i.lower() in health_keywords:
            flag = True
            break
    return flag






# 
if q is not None and len(q.strip()) > 0:  
    if checking(q):
        st.session_state.messages.append(("user", q))
        st.session_state.messages.append(("assistant", user_input(q)))

        for role, message in st.session_state.messages:
            if role == "user":
                st.chat_message("user")
                st.write(message)
            elif role == "assistant":
                st.chat_message("assistant")
                st.write(message)
    else:
        # st.session_state.messages.append(("user", q))
        # st.session_state.messages.append(("assistant", "I'm a medical and health related chatbot. Please ask me about health or medicine."))
        # for role, message in st.session_state.messages:
        #     if role == "user":
        #         st.chat_message("user")
        #         st.write(message)
        #     elif role == "assistant":
        #         st.chat_message("assistant")
        #         # st.write(message)
        st.write("I'm a medical and health related chatbot. Please ask me about health or medicine.")
        

b =  st.button("Clear Chat")
if b:
    st.session_state.messages = []