Update app.py
Browse files
app.py
CHANGED
|
@@ -49,173 +49,182 @@ def chatbot(history, query):
|
|
| 49 |
history.append((query, response))
|
| 50 |
return history, history
|
| 51 |
|
| 52 |
-
# Custom CSS for a
|
| 53 |
custom_css = """
|
| 54 |
/* General container styling */
|
| 55 |
.gradio-container {
|
| 56 |
font-family: 'Segoe UI', Arial, sans-serif;
|
| 57 |
-
background:
|
| 58 |
min-height: 100vh;
|
| 59 |
-
padding:
|
|
|
|
| 60 |
}
|
| 61 |
|
| 62 |
/* Header styling */
|
| 63 |
h1 {
|
| 64 |
-
color: #
|
| 65 |
-
font-size:
|
| 66 |
text-align: center;
|
| 67 |
-
margin
|
| 68 |
-
text-shadow:
|
| 69 |
-
animation: fadeInDown 1s ease-in-out;
|
| 70 |
}
|
| 71 |
|
| 72 |
p {
|
| 73 |
-
color: #
|
| 74 |
-
font-size:
|
| 75 |
text-align: center;
|
| 76 |
-
margin-bottom:
|
| 77 |
}
|
| 78 |
|
| 79 |
-
/* Chatbot container:
|
| 80 |
.chatbot {
|
| 81 |
-
border-radius:
|
| 82 |
-
box-shadow:
|
| 83 |
-
background:
|
| 84 |
-
padding:
|
| 85 |
-
max-width:
|
| 86 |
-
margin: 0
|
| 87 |
-
height:
|
| 88 |
overflow-y: auto !important;
|
|
|
|
|
|
|
| 89 |
}
|
| 90 |
|
| 91 |
-
/*
|
| 92 |
-
@media (max-width: 768px) {
|
| 93 |
-
.chatbot {
|
| 94 |
-
max-width: 100% !important;
|
| 95 |
-
height: 400px !important; /* Reduced height for mobile */
|
| 96 |
-
margin: 0 !important;
|
| 97 |
-
}
|
| 98 |
-
}
|
| 99 |
-
|
| 100 |
-
/* Chat bubbles */
|
| 101 |
.chatbot .bubble {
|
| 102 |
-
border-radius:
|
| 103 |
-
padding:
|
| 104 |
-
margin:
|
| 105 |
-
max-width:
|
| 106 |
-
|
|
|
|
| 107 |
transition: transform 0.2s ease;
|
| 108 |
}
|
| 109 |
|
| 110 |
.chatbot .bubble:hover {
|
| 111 |
-
transform: scale(1.
|
| 112 |
}
|
| 113 |
|
|
|
|
| 114 |
.chatbot .bubble:nth-child(odd) {
|
| 115 |
-
background: #
|
| 116 |
-
color:
|
| 117 |
margin-left: auto !important;
|
|
|
|
| 118 |
}
|
| 119 |
|
|
|
|
| 120 |
.chatbot .bubble:nth-child(even) {
|
| 121 |
-
background: #
|
| 122 |
-
color: #
|
| 123 |
margin-right: auto !important;
|
|
|
|
| 124 |
}
|
| 125 |
|
| 126 |
-
/*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 127 |
input[type="text"] {
|
| 128 |
-
border:
|
| 129 |
-
border-radius:
|
| 130 |
-
padding:
|
| 131 |
-
font-size:
|
| 132 |
-
box-shadow:
|
| 133 |
-
transition: border-color 0.3s ease, box-shadow 0.3s ease;
|
| 134 |
flex-grow: 1 !important;
|
|
|
|
| 135 |
}
|
| 136 |
|
| 137 |
input[type="text"]:focus {
|
| 138 |
-
border-color: #
|
| 139 |
-
box-shadow: 0 4px 12px rgba(21, 101, 192, 0.3) !important;
|
| 140 |
outline: none !important;
|
| 141 |
}
|
| 142 |
|
| 143 |
-
/*
|
| 144 |
button {
|
| 145 |
-
border-radius:
|
| 146 |
-
background: #
|
| 147 |
color: white !important;
|
| 148 |
-
padding:
|
| 149 |
-
font-size:
|
| 150 |
border: none !important;
|
| 151 |
-
|
| 152 |
-
transition: background 0.3s ease
|
| 153 |
-
min-width: 120px !important; /* Minimum width for Send button */
|
| 154 |
}
|
| 155 |
|
| 156 |
button:hover {
|
| 157 |
-
background: #
|
| 158 |
-
transform: translateY(-2px) !important;
|
| 159 |
-
}
|
| 160 |
-
|
| 161 |
-
button:active {
|
| 162 |
-
transform: translateY(0) !important;
|
| 163 |
}
|
| 164 |
|
| 165 |
-
/* Clear button: Reduced size */
|
| 166 |
button[aria-label="Clear Chat"] {
|
| 167 |
-
background: #
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
}
|
| 174 |
|
| 175 |
button[aria-label="Clear Chat"]:hover {
|
| 176 |
-
background: #
|
| 177 |
}
|
| 178 |
|
| 179 |
/* Animations */
|
| 180 |
-
@keyframes fadeInDown {
|
| 181 |
-
from {
|
| 182 |
-
opacity: 0;
|
| 183 |
-
transform: translateY(-20px);
|
| 184 |
-
}
|
| 185 |
-
to {
|
| 186 |
-
opacity: 1;
|
| 187 |
-
transform: translateY(0);
|
| 188 |
-
}
|
| 189 |
-
}
|
| 190 |
-
|
| 191 |
@keyframes slideIn {
|
| 192 |
from {
|
| 193 |
opacity: 0;
|
| 194 |
-
transform:
|
| 195 |
}
|
| 196 |
to {
|
| 197 |
opacity: 1;
|
| 198 |
-
transform:
|
| 199 |
}
|
| 200 |
}
|
| 201 |
|
| 202 |
/* Scrollbar styling */
|
| 203 |
.chatbot::-webkit-scrollbar {
|
| 204 |
-
width:
|
| 205 |
}
|
| 206 |
|
| 207 |
.chatbot::-webkit-scrollbar-track {
|
| 208 |
-
background: #
|
| 209 |
-
border-radius: 10px;
|
| 210 |
}
|
| 211 |
|
| 212 |
.chatbot::-webkit-scrollbar-thumb {
|
| 213 |
-
background: #
|
| 214 |
-
border-radius:
|
| 215 |
}
|
| 216 |
|
| 217 |
.chatbot::-webkit-scrollbar-thumb:hover {
|
| 218 |
-
background: #
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 219 |
}
|
| 220 |
"""
|
| 221 |
|
|
@@ -227,7 +236,7 @@ with gr.Blocks(title="LIC Agent Chatbot", css=custom_css) as demo:
|
|
| 227 |
|
| 228 |
chatbot_ui = gr.Chatbot(
|
| 229 |
label="LIC Assistant",
|
| 230 |
-
height=600, #
|
| 231 |
bubble_full_width=False,
|
| 232 |
avatar_images=("🧑", "🤖"),
|
| 233 |
show_copy_button=True
|
|
@@ -254,7 +263,7 @@ with gr.Blocks(title="LIC Agent Chatbot", css=custom_css) as demo:
|
|
| 254 |
return history, query
|
| 255 |
|
| 256 |
send.click(fn=send_message, inputs=[state, msg], outputs=[chatbot_ui, msg])
|
| 257 |
-
msg.submit(fn=send_message, inputs=[state, msg], outputs=[chatbot_ui, msg]) #
|
| 258 |
clear.click(lambda: ([], []), None, [chatbot_ui, state], queue=False)
|
| 259 |
|
| 260 |
demo.launch()
|
|
|
|
| 49 |
history.append((query, response))
|
| 50 |
return history, history
|
| 51 |
|
| 52 |
+
# Custom CSS for a WhatsApp-like mobile view
|
| 53 |
custom_css = """
|
| 54 |
/* General container styling */
|
| 55 |
.gradio-container {
|
| 56 |
font-family: 'Segoe UI', Arial, sans-serif;
|
| 57 |
+
background: #e5ddd5; /* WhatsApp-inspired light background */
|
| 58 |
min-height: 100vh;
|
| 59 |
+
padding: 0;
|
| 60 |
+
margin: 0;
|
| 61 |
}
|
| 62 |
|
| 63 |
/* Header styling */
|
| 64 |
h1 {
|
| 65 |
+
color: #075e54 !important; /* WhatsApp green */
|
| 66 |
+
font-size: 1.8em !important;
|
| 67 |
text-align: center;
|
| 68 |
+
margin: 10px 0;
|
| 69 |
+
text-shadow: none;
|
|
|
|
| 70 |
}
|
| 71 |
|
| 72 |
p {
|
| 73 |
+
color: #075e54 !important;
|
| 74 |
+
font-size: 1em !important;
|
| 75 |
text-align: center;
|
| 76 |
+
margin-bottom: 10px;
|
| 77 |
}
|
| 78 |
|
| 79 |
+
/* Chatbot container: Mimics WhatsApp chat window */
|
| 80 |
.chatbot {
|
| 81 |
+
border-radius: 0 !important;
|
| 82 |
+
box-shadow: none !important;
|
| 83 |
+
background: #e5ddd5 !important;
|
| 84 |
+
padding: 0 !important;
|
| 85 |
+
max-width: 100% !important;
|
| 86 |
+
margin: 0 !important;
|
| 87 |
+
height: 80vh !important; /* Full height for mobile */
|
| 88 |
overflow-y: auto !important;
|
| 89 |
+
display: flex;
|
| 90 |
+
flex-direction: column-reverse; /* Bottom-up chat like WhatsApp */
|
| 91 |
}
|
| 92 |
|
| 93 |
+
/* Chat bubbles: WhatsApp-style design */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
.chatbot .bubble {
|
| 95 |
+
border-radius: 10px !important;
|
| 96 |
+
padding: 10px 15px !important;
|
| 97 |
+
margin: 5px 10px !important;
|
| 98 |
+
max-width: 65% !important;
|
| 99 |
+
font-size: 0.9em !important;
|
| 100 |
+
animation: slideIn 0.3s ease-in-out;
|
| 101 |
transition: transform 0.2s ease;
|
| 102 |
}
|
| 103 |
|
| 104 |
.chatbot .bubble:hover {
|
| 105 |
+
transform: scale(1.01);
|
| 106 |
}
|
| 107 |
|
| 108 |
+
/* User bubble: Right-aligned, green like WhatsApp sender */
|
| 109 |
.chatbot .bubble:nth-child(odd) {
|
| 110 |
+
background: #dcf8c6 !important; /* WhatsApp sender bubble color */
|
| 111 |
+
color: #000 !important;
|
| 112 |
margin-left: auto !important;
|
| 113 |
+
align-self: flex-end !important;
|
| 114 |
}
|
| 115 |
|
| 116 |
+
/* Bot bubble: Left-aligned, light gray like WhatsApp receiver */
|
| 117 |
.chatbot .bubble:nth-child(even) {
|
| 118 |
+
background: #fff !important; /* WhatsApp receiver bubble color */
|
| 119 |
+
color: #000 !important;
|
| 120 |
margin-right: auto !important;
|
| 121 |
+
align-self: flex-start !important;
|
| 122 |
}
|
| 123 |
|
| 124 |
+
/* Input area: Bottom navigation bar style */
|
| 125 |
+
.gradio-row:last-child {
|
| 126 |
+
position: fixed !important;
|
| 127 |
+
bottom: 0 !important;
|
| 128 |
+
width: 100% !important;
|
| 129 |
+
max-width: 100% !important;
|
| 130 |
+
background: #f0f0f0 !important; /* Light gray for input area */
|
| 131 |
+
padding: 10px !important;
|
| 132 |
+
box-shadow: 0 -2px 5px rgba(0,0,0,0.1) !important;
|
| 133 |
+
z-index: 1000 !important;
|
| 134 |
+
display: flex !important;
|
| 135 |
+
align-items: center !important;
|
| 136 |
+
}
|
| 137 |
+
|
| 138 |
+
/* Textbox styling: Compact and WhatsApp-like */
|
| 139 |
input[type="text"] {
|
| 140 |
+
border: 1px solid #ccc !important;
|
| 141 |
+
border-radius: 20px !important;
|
| 142 |
+
padding: 10px 15px !important;
|
| 143 |
+
font-size: 0.9em !important;
|
| 144 |
+
box-shadow: none !important;
|
|
|
|
| 145 |
flex-grow: 1 !important;
|
| 146 |
+
margin-right: 10px !important;
|
| 147 |
}
|
| 148 |
|
| 149 |
input[type="text"]:focus {
|
| 150 |
+
border-color: #075e54 !important;
|
|
|
|
| 151 |
outline: none !important;
|
| 152 |
}
|
| 153 |
|
| 154 |
+
/* Send button: Large and prominent */
|
| 155 |
button {
|
| 156 |
+
border-radius: 20px !important;
|
| 157 |
+
background: #075e54 !important; /* WhatsApp green */
|
| 158 |
color: white !important;
|
| 159 |
+
padding: 12px 25px !important; /* Larger size */
|
| 160 |
+
font-size: 0.9em !important;
|
| 161 |
border: none !important;
|
| 162 |
+
min-width: 100px !important;
|
| 163 |
+
transition: background 0.3s ease !important;
|
|
|
|
| 164 |
}
|
| 165 |
|
| 166 |
button:hover {
|
| 167 |
+
background: #054d44 !important;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 168 |
}
|
| 169 |
|
| 170 |
+
/* Clear button: Reduced size and WhatsApp-like placement */
|
| 171 |
button[aria-label="Clear Chat"] {
|
| 172 |
+
background: #e0e0e0 !important;
|
| 173 |
+
padding: 8px 15px !important;
|
| 174 |
+
font-size: 0.8em !important;
|
| 175 |
+
min-width: 80px !important;
|
| 176 |
+
margin-top: 10px !important;
|
| 177 |
+
align-self: center !important;
|
| 178 |
}
|
| 179 |
|
| 180 |
button[aria-label="Clear Chat"]:hover {
|
| 181 |
+
background: #d0d0d0 !important;
|
| 182 |
}
|
| 183 |
|
| 184 |
/* Animations */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 185 |
@keyframes slideIn {
|
| 186 |
from {
|
| 187 |
opacity: 0;
|
| 188 |
+
transform: translateY(10px);
|
| 189 |
}
|
| 190 |
to {
|
| 191 |
opacity: 1;
|
| 192 |
+
transform: translateY(0);
|
| 193 |
}
|
| 194 |
}
|
| 195 |
|
| 196 |
/* Scrollbar styling */
|
| 197 |
.chatbot::-webkit-scrollbar {
|
| 198 |
+
width: 5px;
|
| 199 |
}
|
| 200 |
|
| 201 |
.chatbot::-webkit-scrollbar-track {
|
| 202 |
+
background: #e5ddd5;
|
|
|
|
| 203 |
}
|
| 204 |
|
| 205 |
.chatbot::-webkit-scrollbar-thumb {
|
| 206 |
+
background: #075e54;
|
| 207 |
+
border-radius: 5px;
|
| 208 |
}
|
| 209 |
|
| 210 |
.chatbot::-webkit-scrollbar-thumb:hover {
|
| 211 |
+
background: #054d44;
|
| 212 |
+
}
|
| 213 |
+
|
| 214 |
+
/* Mobile-specific adjustments (already optimized, but ensuring consistency) */
|
| 215 |
+
@media (max-width: 768px) {
|
| 216 |
+
.chatbot {
|
| 217 |
+
height: 80vh !important;
|
| 218 |
+
}
|
| 219 |
+
.gradio-row:last-child {
|
| 220 |
+
padding: 5px !important;
|
| 221 |
+
}
|
| 222 |
+
input[type="text"] {
|
| 223 |
+
padding: 8px 12px !important;
|
| 224 |
+
}
|
| 225 |
+
button {
|
| 226 |
+
padding: 10px 20px !important;
|
| 227 |
+
}
|
| 228 |
}
|
| 229 |
"""
|
| 230 |
|
|
|
|
| 236 |
|
| 237 |
chatbot_ui = gr.Chatbot(
|
| 238 |
label="LIC Assistant",
|
| 239 |
+
height=600, # Default height, adjusted by CSS
|
| 240 |
bubble_full_width=False,
|
| 241 |
avatar_images=("🧑", "🤖"),
|
| 242 |
show_copy_button=True
|
|
|
|
| 263 |
return history, query
|
| 264 |
|
| 265 |
send.click(fn=send_message, inputs=[state, msg], outputs=[chatbot_ui, msg])
|
| 266 |
+
msg.submit(fn=send_message, inputs=[state, msg], outputs=[chatbot_ui, msg]) # Enter key support
|
| 267 |
clear.click(lambda: ([], []), None, [chatbot_ui, state], queue=False)
|
| 268 |
|
| 269 |
demo.launch()
|