File size: 3,793 Bytes
71d6a35
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8f58d99
21a4e9d
71d6a35
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import streamlit as st
import pandas as pd
from model import create_agent

# Set page config at the very beginning
st.set_page_config(page_title="Appointment Booking Bot", page_icon="πŸ₯")
# Load doctor data
@st.cache_data
def load_doctor_data():
    return pd.read_csv('doctor_specialization_dummy_data.csv')

doctor_df = load_doctor_data()
API_KEY = "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"

# General prompt template
general_prompt_template = """
You are a healthcare assistant AI. Your primary responsibilities are:

- Keep the conversation friendly and provide required details too.
- Suggesting a doctor based on the user's symptoms.
- Managing doctor-related appointments (book, reschedule, delete), adhering to specific rules.
- Provide general assistance, such as greetings, if the user starts with a hello or introduction.

Appointment Rules:
- Appointments can only be scheduled/reschedule from Monday to Friday, between 10 AM and 7 PM.
- Appointments must be booked/reschedule within the next 7 days.
- Book/Reschedule the appointment for 60 minutes/1 hr.
- You are not allowed to handle appointments outside these constraints.

If the user says something like "hello," "hi," "hey," or a similar greeting, respond appropriately. 
If the user provides symptoms, suggest a doctor based on those symptoms.
If user asks details of doctor or book appointment slots without specifying symptoms, ask the user what symptoms they have.
"""

# Initialize the agent
@st.cache_resource
def get_agent():
    return create_agent(general_prompt_template)

agent = get_agent()

# Streamlit app
st.title("Appointment Booking Bot")

# Initialize chat history
if "messages" not in st.session_state:
    st.session_state.messages = []

# Display chat messages from history on app rerun
for message in st.session_state.messages:
    with st.chat_message(message["role"]):
        st.markdown(message["content"])

# React to user input
if prompt := st.chat_input("What is your query?"):
    # Display user message in chat message container
    st.chat_message("user").markdown(prompt)
    # Add user message to chat history
    st.session_state.messages.append({"role": "user", "content": prompt})

    response = agent({"input": prompt})['output']
    
    # Display assistant response in chat message container
    with st.chat_message("assistant"):
        st.markdown(response)
    # Add assistant response to chat history
    st.session_state.messages.append({"role": "assistant", "content": response})

# Main function to run the app
def main():
    st.sidebar.title("About")
    st.sidebar.info("""
        πŸ₯ **Appointment Booking Bot**

        🩺 Virtual Doctors Appointment Managing
       
        πŸ”‘ **Key Features:**
        - Symptom analysis and health advice
        - Medical information lookup
        - Appointment management:
        πŸ“… Book appointments
        πŸ”„ Reschedule appointments
        πŸ—‘οΈ Delete appointments

        ⏰ **Appointment Availability:**
        - Monday to Friday
        - 10 AM to 7 PM
        - Book up to 7 days in advance

        ⚠️ **Important Note:**
        This app is for informational purposes only and does not replace professional medical advice. 
        
        πŸ’‘ Start by describing your symptoms or managing your appointments!
        """)
    # Display a horizontal line, emoji, and the name "SIMRAN"
    col1, col2 = st.sidebar.columns([2, 1])

# Display emoji and name in the first column
    with col1:
        st.markdown("πŸ‘€ **SIMRAN**")  # Profile emoji next to the name

    # Display red logout button in the second column
    with col2:
        logout_button = st.button("Logout", key="logout", help="Click to logout", use_container_width=True)

if __name__ == "__main__":
    main()