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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 97 |
}
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
}
|
| 103 |
-
|
| 104 |
-
|
|
|
|
| 105 |
}
|
| 106 |
"""
|
| 107 |
|
| 108 |
with gr.Blocks(
|
| 109 |
-
title="AI
|
| 110 |
theme=gr.themes.Soft(),
|
| 111 |
-
css=
|
|
|
|
| 112 |
) as demo:
|
| 113 |
-
#
|
| 114 |
gr.HTML("""
|
| 115 |
-
<div
|
| 116 |
-
<h1
|
| 117 |
-
<p>Your
|
| 118 |
-
<p style="font-size: 0.9em; color: #
|
| 119 |
-
Built with <a href="https://huggingface.co/spaces/akhaliq/anycoder" target="_blank">anycoder</a>
|
| 120 |
</p>
|
| 121 |
</div>
|
| 122 |
""")
|
| 123 |
|
| 124 |
-
# Chat interface
|
| 125 |
with gr.Row():
|
| 126 |
-
|
|
|
|
| 127 |
chatbot = gr.Chatbot(
|
| 128 |
-
label="
|
| 129 |
-
height=
|
| 130 |
show_copy_button=True,
|
| 131 |
-
placeholder="Start a conversation
|
| 132 |
avatar_images=(
|
| 133 |
-
None,
|
| 134 |
-
"https://picsum.photos/seed/ai-
|
| 135 |
),
|
| 136 |
-
type="messages"
|
|
|
|
| 137 |
)
|
| 138 |
|
| 139 |
-
with
|
|
|
|
| 140 |
msg = gr.Textbox(
|
| 141 |
-
label="
|
| 142 |
-
placeholder="Type
|
| 143 |
lines=1,
|
| 144 |
-
max_lines=
|
| 145 |
container=False,
|
| 146 |
-
scale=4
|
|
|
|
| 147 |
)
|
| 148 |
submit_btn = gr.Button(
|
| 149 |
"Send",
|
| 150 |
variant="primary",
|
| 151 |
scale=1,
|
| 152 |
-
size="sm"
|
|
|
|
| 153 |
)
|
| 154 |
|
|
|
|
| 155 |
with gr.Row():
|
| 156 |
clear_btn = gr.Button(
|
| 157 |
-
"Clear
|
| 158 |
variant="secondary",
|
| 159 |
scale=1,
|
| 160 |
-
size="sm"
|
|
|
|
| 161 |
)
|
| 162 |
example_btn = gr.Button(
|
| 163 |
"Random Example",
|
| 164 |
-
variant="secondary",
|
| 165 |
scale=1,
|
| 166 |
-
size="sm"
|
|
|
|
| 167 |
)
|
| 168 |
|
| 169 |
-
with
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
|
|
|
|
|
|
| 177 |
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
|
|
|
|
|
|
| 184 |
|
| 185 |
-
|
| 186 |
-
gr.
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
|
|
|
|
|
|
| 192 |
|
| 193 |
# Event handlers
|
| 194 |
def update_message_count(history: List[Dict[str, str]]) -> int:
|
|
@@ -248,7 +421,7 @@ with gr.Blocks(
|
|
| 248 |
|
| 249 |
# Welcome message on load
|
| 250 |
demo.load(
|
| 251 |
-
lambda: [{"role": "assistant", "content": "Hello! I'm your AI
|
| 252 |
outputs=chatbot
|
| 253 |
).then(
|
| 254 |
update_message_count,
|
|
@@ -261,5 +434,5 @@ if __name__ == "__main__":
|
|
| 261 |
share=False,
|
| 262 |
show_error=True,
|
| 263 |
quiet=False,
|
| 264 |
-
show_tips=
|
| 265 |
-
)
|
|
|
|
| 83 |
["Thank you for your help!"]
|
| 84 |
]
|
| 85 |
|
| 86 |
+
# Apple-style CSS
|
| 87 |
+
APPLE_CSS = """
|
| 88 |
+
/* Apple-style design system */
|
| 89 |
+
.gradio-container {
|
| 90 |
+
font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Helvetica Neue", Helvetica, Arial, sans-serif !important;
|
| 91 |
+
background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%) !important;
|
| 92 |
+
min-height: 100vh;
|
| 93 |
}
|
| 94 |
+
|
| 95 |
+
/* Main container styling */
|
| 96 |
+
.main-container {
|
| 97 |
+
background: rgba(255, 255, 255, 0.95) !important;
|
| 98 |
+
backdrop-filter: blur(20px) !important;
|
| 99 |
+
border-radius: 20px !important;
|
| 100 |
+
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1) !important;
|
| 101 |
+
border: 1px solid rgba(255, 255, 255, 0.2) !important;
|
| 102 |
+
margin: 20px auto !important;
|
| 103 |
+
padding: 30px !important;
|
| 104 |
+
max-width: 1200px !important;
|
| 105 |
+
}
|
| 106 |
+
|
| 107 |
+
/* Header styling */
|
| 108 |
+
.header-container {
|
| 109 |
+
text-align: center;
|
| 110 |
+
margin-bottom: 30px;
|
| 111 |
+
padding: 20px 0;
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
.header-container h1 {
|
| 115 |
+
font-weight: 600 !important;
|
| 116 |
+
font-size: 2.5rem !important;
|
| 117 |
+
background: linear-gradient(45deg, #007AFF, #5856D6) !important;
|
| 118 |
+
-webkit-background-clip: text !important;
|
| 119 |
+
-webkit-text-fill-color: transparent !important;
|
| 120 |
+
margin-bottom: 10px !important;
|
| 121 |
+
}
|
| 122 |
+
|
| 123 |
+
.header-container p {
|
| 124 |
+
color: #8e8e93 !important;
|
| 125 |
+
font-size: 1.1rem !important;
|
| 126 |
+
font-weight: 400 !important;
|
| 127 |
+
}
|
| 128 |
+
|
| 129 |
+
/* Chatbot styling */
|
| 130 |
+
.chatbot-container {
|
| 131 |
+
border-radius: 16px !important;
|
| 132 |
+
overflow: hidden !important;
|
| 133 |
+
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08) !important;
|
| 134 |
+
border: 1px solid rgba(0, 0, 0, 0.05) !important;
|
| 135 |
+
}
|
| 136 |
+
|
| 137 |
+
/* Message bubbles */
|
| 138 |
+
.message.user {
|
| 139 |
+
background: linear-gradient(135deg, #007AFF 0%, #5856D6 100%) !important;
|
| 140 |
+
color: white !important;
|
| 141 |
+
border-radius: 18px !important;
|
| 142 |
+
margin-left: auto !important;
|
| 143 |
+
max-width: 70% !important;
|
| 144 |
+
box-shadow: 0 2px 8px rgba(0, 122, 255, 0.3) !important;
|
| 145 |
+
}
|
| 146 |
+
|
| 147 |
+
.message.assistant {
|
| 148 |
+
background: #f2f2f7 !important;
|
| 149 |
+
color: #1c1c1e !important;
|
| 150 |
+
border-radius: 18px !important;
|
| 151 |
+
margin-right: auto !important;
|
| 152 |
+
max-width: 70% !important;
|
| 153 |
+
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08) !important;
|
| 154 |
+
}
|
| 155 |
+
|
| 156 |
+
/* Input styling */
|
| 157 |
+
.input-container {
|
| 158 |
+
background: white !important;
|
| 159 |
+
border-radius: 16px !important;
|
| 160 |
+
padding: 12px 16px !important;
|
| 161 |
+
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05) !important;
|
| 162 |
+
border: 1px solid rgba(0, 0, 0, 0.05) !important;
|
| 163 |
+
}
|
| 164 |
+
|
| 165 |
+
/* Button styling - Apple-like */
|
| 166 |
+
.btn-primary {
|
| 167 |
+
background: linear-gradient(135deg, #007AFF 0%, #5856D6 100%) !important;
|
| 168 |
+
border: none !important;
|
| 169 |
+
border-radius: 12px !important;
|
| 170 |
+
font-weight: 600 !important;
|
| 171 |
+
font-size: 0.95rem !important;
|
| 172 |
+
padding: 12px 24px !important;
|
| 173 |
+
transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1) !important;
|
| 174 |
+
box-shadow: 0 4px 14px rgba(0, 122, 255, 0.3) !important;
|
| 175 |
+
}
|
| 176 |
+
|
| 177 |
+
.btn-primary:hover {
|
| 178 |
+
transform: translateY(-2px) !important;
|
| 179 |
+
box-shadow: 0 6px 20px rgba(0, 122, 255, 0.4) !important;
|
| 180 |
+
}
|
| 181 |
+
|
| 182 |
+
.btn-secondary {
|
| 183 |
+
background: #f2f2f7 !important;
|
| 184 |
+
color: #007AFF !important;
|
| 185 |
+
border: 1px solid #d1d1d6 !important;
|
| 186 |
+
border-radius: 12px !important;
|
| 187 |
+
font-weight: 600 !important;
|
| 188 |
+
font-size: 0.95rem !important;
|
| 189 |
+
padding: 12px 24px !important;
|
| 190 |
+
transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1) !important;
|
| 191 |
+
}
|
| 192 |
+
|
| 193 |
+
.btn-secondary:hover {
|
| 194 |
+
background: #e5e5ea !important;
|
| 195 |
+
transform: translateY(-1px) !important;
|
| 196 |
+
}
|
| 197 |
+
|
| 198 |
+
/* Sidebar styling */
|
| 199 |
+
.sidebar-container {
|
| 200 |
+
background: rgba(255, 255, 255, 0.8) !important;
|
| 201 |
+
backdrop-filter: blur(10px) !important;
|
| 202 |
+
border-radius: 16px !important;
|
| 203 |
+
padding: 20px !important;
|
| 204 |
+
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.05) !important;
|
| 205 |
+
border: 1px solid rgba(255, 255, 255, 0.3) !important;
|
| 206 |
+
}
|
| 207 |
+
|
| 208 |
+
/* Stats and info styling */
|
| 209 |
+
.stats-container {
|
| 210 |
+
background: white !important;
|
| 211 |
+
border-radius: 12px !important;
|
| 212 |
+
padding: 16px !important;
|
| 213 |
+
margin: 10px 0 !important;
|
| 214 |
+
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04) !important;
|
| 215 |
+
}
|
| 216 |
+
|
| 217 |
+
/* Examples styling */
|
| 218 |
+
.examples-container {
|
| 219 |
+
background: #f8f9fa !important;
|
| 220 |
+
border-radius: 12px !important;
|
| 221 |
+
padding: 16px !important;
|
| 222 |
+
border: 1px solid #e9ecef !important;
|
| 223 |
+
}
|
| 224 |
+
|
| 225 |
+
/* Text input styling */
|
| 226 |
+
input[type="text"], textarea {
|
| 227 |
+
background: white !important;
|
| 228 |
+
border: 1px solid #e5e5ea !important;
|
| 229 |
+
border-radius: 10px !important;
|
| 230 |
+
padding: 12px 16px !important;
|
| 231 |
+
font-size: 1rem !important;
|
| 232 |
+
transition: all 0.3s ease !important;
|
| 233 |
+
}
|
| 234 |
+
|
| 235 |
+
input[type="text"]:focus, textarea:focus {
|
| 236 |
+
outline: none !important;
|
| 237 |
+
border-color: #007AFF !important;
|
| 238 |
+
box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.1) !important;
|
| 239 |
+
}
|
| 240 |
+
|
| 241 |
+
/* Smooth transitions */
|
| 242 |
+
* {
|
| 243 |
+
transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1) !important;
|
| 244 |
+
}
|
| 245 |
+
|
| 246 |
+
/* Custom scrollbar */
|
| 247 |
+
::-webkit-scrollbar {
|
| 248 |
+
width: 8px !important;
|
| 249 |
+
height: 8px !important;
|
| 250 |
+
}
|
| 251 |
+
|
| 252 |
+
::-webkit-scrollbar-track {
|
| 253 |
+
background: #f1f1f1 !important;
|
| 254 |
+
border-radius: 4px !important;
|
| 255 |
}
|
| 256 |
+
|
| 257 |
+
::-webkit-scrollbar-thumb {
|
| 258 |
+
background: #c7c7cc !important;
|
| 259 |
+
border-radius: 4px !important;
|
| 260 |
}
|
| 261 |
+
|
| 262 |
+
::-webkit-scrollbar-thumb:hover {
|
| 263 |
+
background: #8e8e93 !important;
|
| 264 |
}
|
| 265 |
"""
|
| 266 |
|
| 267 |
with gr.Blocks(
|
| 268 |
+
title="AI Assistant",
|
| 269 |
theme=gr.themes.Soft(),
|
| 270 |
+
css=APPLE_CSS,
|
| 271 |
+
elem_classes=["main-container"]
|
| 272 |
) as demo:
|
| 273 |
+
# Apple-style header
|
| 274 |
gr.HTML("""
|
| 275 |
+
<div class="header-container">
|
| 276 |
+
<h1>AI Assistant</h1>
|
| 277 |
+
<p>Your intelligent conversation partner</p>
|
| 278 |
+
<p style="font-size: 0.9em; color: #8e8e93; margin-top: 10px;">
|
| 279 |
+
Built with <a href="https://huggingface.co/spaces/akhaliq/anycoder" target="_blank" style="color: #007AFF; text-decoration: none;">anycoder</a>
|
| 280 |
</p>
|
| 281 |
</div>
|
| 282 |
""")
|
| 283 |
|
|
|
|
| 284 |
with gr.Row():
|
| 285 |
+
# Main chat area
|
| 286 |
+
with gr.Column(scale=3, elem_classes=["chatbot-container"]):
|
| 287 |
chatbot = gr.Chatbot(
|
| 288 |
+
label="",
|
| 289 |
+
height=550,
|
| 290 |
show_copy_button=True,
|
| 291 |
+
placeholder="Start a conversation...",
|
| 292 |
avatar_images=(
|
| 293 |
+
None,
|
| 294 |
+
"https://picsum.photos/seed/ai-assistant/100/100.jpg"
|
| 295 |
),
|
| 296 |
+
type="messages",
|
| 297 |
+
elem_id="chatbot-main"
|
| 298 |
)
|
| 299 |
|
| 300 |
+
# Input area with Apple-style design
|
| 301 |
+
with gr.Row(elem_classes=["input-container"]):
|
| 302 |
msg = gr.Textbox(
|
| 303 |
+
label="",
|
| 304 |
+
placeholder="Type a message...",
|
| 305 |
lines=1,
|
| 306 |
+
max_lines=4,
|
| 307 |
container=False,
|
| 308 |
+
scale=4,
|
| 309 |
+
show_label=False
|
| 310 |
)
|
| 311 |
submit_btn = gr.Button(
|
| 312 |
"Send",
|
| 313 |
variant="primary",
|
| 314 |
scale=1,
|
| 315 |
+
size="sm",
|
| 316 |
+
elem_classes=["btn-primary"]
|
| 317 |
)
|
| 318 |
|
| 319 |
+
# Action buttons
|
| 320 |
with gr.Row():
|
| 321 |
clear_btn = gr.Button(
|
| 322 |
+
"Clear Chat",
|
| 323 |
variant="secondary",
|
| 324 |
scale=1,
|
| 325 |
+
size="sm",
|
| 326 |
+
elem_classes=["btn-secondary"]
|
| 327 |
)
|
| 328 |
example_btn = gr.Button(
|
| 329 |
"Random Example",
|
| 330 |
+
variant="secondary",
|
| 331 |
scale=1,
|
| 332 |
+
size="sm",
|
| 333 |
+
elem_classes=["btn-secondary"]
|
| 334 |
)
|
| 335 |
|
| 336 |
+
# Sidebar with Apple-style cards
|
| 337 |
+
with gr.Column(scale=1, elem_classes=["sidebar-container"]):
|
| 338 |
+
# Quick tips
|
| 339 |
+
with gr.Group(elem_classes=["stats-container"]):
|
| 340 |
+
gr.Markdown("""
|
| 341 |
+
### π¬ Quick Tips
|
| 342 |
+
β’ Press Enter to send messages
|
| 343 |
+
β’ Click messages to copy
|
| 344 |
+
β’ Use examples for inspiration
|
| 345 |
+
""")
|
| 346 |
|
| 347 |
+
# Message counter
|
| 348 |
+
with gr.Group(elem_classes=["stats-container"]):
|
| 349 |
+
message_count = gr.Number(
|
| 350 |
+
label="Messages",
|
| 351 |
+
value=0,
|
| 352 |
+
interactive=False,
|
| 353 |
+
precision=0
|
| 354 |
+
)
|
| 355 |
|
| 356 |
+
# Examples in a clean container
|
| 357 |
+
with gr.Group(elem_classes=["examples-container"]):
|
| 358 |
+
gr.Markdown("### π― Conversation Starters")
|
| 359 |
+
gr.Examples(
|
| 360 |
+
examples=EXAMPLE_CONVERSATIONS,
|
| 361 |
+
inputs=msg,
|
| 362 |
+
label="",
|
| 363 |
+
examples_per_page=5
|
| 364 |
+
)
|
| 365 |
|
| 366 |
# Event handlers
|
| 367 |
def update_message_count(history: List[Dict[str, str]]) -> int:
|
|
|
|
| 421 |
|
| 422 |
# Welcome message on load
|
| 423 |
demo.load(
|
| 424 |
+
lambda: [{"role": "assistant", "content": "π Hello! I'm your AI assistant. How can I help you today?"}],
|
| 425 |
outputs=chatbot
|
| 426 |
).then(
|
| 427 |
update_message_count,
|
|
|
|
| 434 |
share=False,
|
| 435 |
show_error=True,
|
| 436 |
quiet=False,
|
| 437 |
+
show_tips=False
|
| 438 |
+
)
|