Spaces:
VAH6002
/
Sleeping

File size: 2,629 Bytes
1b50387
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
from backend import generate_response

# Streamlit Page Configuration
st.set_page_config(page_title="Mobile Accessories Chat-Bot", layout="centered")

st.markdown(
    """

    <style>

    .stApp {

        background-color: #1a1a2e;

        color: #e0e0e0;

    }

    .stTextInput > div > div > input {

        background-color: #2e2e4a;

        color: #e0e0e0;

        border: 1px solid #4a4a6e;

        border-radius: 8px;

        padding: 10px;

    }

    .stButton > button {

        background-color: #0f3460;

        color: #e0e0e0;

        border-radius: 8px;

        padding: 10px 20px;

        border: none;

        cursor: pointer;

    }

    .stButton > button:hover {

        background-color: #16213e;

    }

    .stChatMessage {

        background-color: #2e2e4a;

        border-radius: 10px;

        padding: 15px;

        margin-bottom: 10px;

    }

    .stChatMessage.user {

        background-color: #0f3460;

        text-align: right;

    }

    .stChatMessage.assistant {

        background-color: #2e2e4a;

        text-align: left;

    }

    h1, h2, h3, h4, h5, h6 {

        color: #e0e0e0;

    }

    </style>

    """,
    unsafe_allow_html=True
)
st.title("📱 Mobile Accessories Chat-Bot")

# Initialize Chat History and session state variables
if "chat_history" not in st.session_state:
    st.session_state.chat_history = []
if "user_input" not in st.session_state:
    st.session_state.user_input = ""
if "should_clear_input" not in st.session_state:
    st.session_state.should_clear_input = False

# Clear input if flag is set
if st.session_state.should_clear_input:
    st.session_state.user_input = ""
    st.session_state.should_clear_input = False

# Form for handling input submission
with st.form(key="chat_form"):
    user_query = st.text_input(
        "Ask me anything about mobile accessories...", 
        value=st.session_state.user_input, 
        key="user_input"
    )
    submit_button = st.form_submit_button("Send")

if submit_button and user_query:
    # Generate Response
    bot_response = generate_response(user_query)

    # Store chat history
    st.session_state.chat_history.append(("You", user_query))
    st.session_state.chat_history.append(("Chatbot", bot_response))

    # Set flag to clear input and rerun
    st.session_state.should_clear_input = True
    st.rerun()

# Display Chat History in Reverse Order
st.subheader("Chat History")
for role, message in reversed(st.session_state.chat_history):
    with st.chat_message(role):
        st.markdown(message)