Spaces:
VAH6002
/
Sleeping

File size: 4,282 Bytes
f898b47
 
 
 
81a2eb4
f898b47
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
853da81
f898b47
 
 
 
 
66f7207
 
 
 
 
 
 
d9f5ffa
 
66f7207
d9f5ffa
 
66f7207
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d9f5ffa
 
66f7207
d9f5ffa
f898b47
45a93fc
f898b47
12cbeae
f898b47
 
 
 
 
d9f5ffa
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
import streamlit as st
from backend import generate_response

# --- Page Config ---
st.set_page_config(page_title="Accesssories Mobile Bot", layout="wide")

# --- Custom CSS for ChatGPT-like look ---
st.markdown(
    """
    <style>
    .stApp {
        background-color: #343541;
        color: #e0e0e0;
    }

    .stTextInput input {
        background-color: #40414f;
        color: #fff;
        border-radius: 8px;
        padding: 12px;
        border: none;
        font-size: 16px;
    }

    .stButton>button {
        background-color: #19c37d;
        color: white;
        border-radius: 8px;
        padding: 10px 20px;
        border: none;
        font-weight: bold;
        margin-top: 10px;
    }

    .stButton>button:hover {
        background-color: #15a96e;
    }

    .chat-container {
        max-height: 75vh;
        overflow-y: auto;
        padding: 1rem;
    }

    .message {
        padding: 15px;
        border-radius: 12px;
        margin-bottom: 12px;
        line-height: 1.5;
        width: fit-content;
        max-width: 80%;
    }

    .user {
        background-color: #0e639c;
        align-self: flex-end;
        margin-left: auto;
        text-align: right;
        color: white;
    }

    .bot {
        background-color: #444654;
        align-self: flex-start;
        margin-right: auto;
        text-align: left;
        color: white;
    }

    .chat-wrapper {
        display: flex;
        flex-direction: column;
    }

    </style>
    """,
    unsafe_allow_html=True
)

# st.title("🤖 ChatGPT-style Mobile Accessories Bot")

# --- Session State ---
if "chat_history" not in st.session_state:
    st.session_state.chat_history = []

# --- Chat Display (on top) ---
# st.markdown('<div class="chat-container"><div class="chat-wrapper">', unsafe_allow_html=True)
# for role, msg in st.session_state.chat_history:
#     css_class = "user" if role == "user" else "bot"
#     st.markdown(f'<div class="message {css_class}">{msg}</div>', unsafe_allow_html=True)
# st.markdown('</div></div>', unsafe_allow_html=True)

# --- Chat Display (on top) ---
st.markdown('<div class="chat-container"><div class="chat-wrapper">', unsafe_allow_html=True)

for role, msg in st.session_state.chat_history:
    css_class = "user" if role == "user" else "bot"

    if role == "user":
        st.markdown(f'<div class="message {css_class}">{msg}</div>', unsafe_allow_html=True)

    elif isinstance(msg, dict) and msg.get("type") == "products":
        st.markdown(f'<div class="message {css_class}"><div style="display: flex; overflow-x: auto; gap: 16px;">', unsafe_allow_html=True)

        for product in msg["items"]:
            st.markdown(f'''
                <div style="flex: 0 0 auto; width: 200px; background-color: #202123; padding: 12px; border-radius: 10px; text-align: center;">
                    <img src="{product['image_url']}" width="100%" style="border-radius: 8px;" />
                    <h4 style="color: #fff; margin-top: 10px;">{product['name']}</h4>
                    <p style="color: #19c37d; font-weight: bold;">{product['price']}</p>
                    <a href="{product['buy_link']}" target="_blank">
                        <button style="margin-top: 8px; background-color: #19c37d; color: white; border: none; padding: 6px 12px; border-radius: 5px;">Buy Now</button>
                    </a>
                </div>
            ''', unsafe_allow_html=True)

        st.markdown('</div></div>', unsafe_allow_html=True)

    else:
        # Simple text reply
        content = msg["content"] if isinstance(msg, dict) else msg
        st.markdown(f'<div class="message {css_class}">{content}</div>', unsafe_allow_html=True)

st.markdown('</div></div>', unsafe_allow_html=True)


# --- Chat Input (below) ---
with st.form("chat_form", clear_on_submit=True):
    user_input = st.text_input("🧠 Your mobile accessories AI expert is ready. Ask anything!", key="input")
    send = st.form_submit_button("Send")
    st.title("🤖 Mobile Accessory AI-BoT")

if send and user_input:
    response = generate_response(user_input)
    st.session_state.chat_history.append(("user", user_input))
    st.session_state.chat_history.append(("bot", response))
    st.rerun()  # Optional: Keeps scroll to bottom after each input