Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -371,146 +371,121 @@ I'm here to help and chat! What would you like to do? π"""
|
|
| 371 |
|
| 372 |
**What would you like to try first? π**"""
|
| 373 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 374 |
# Modern UI with custom styling
|
| 375 |
def create_chatbot():
|
| 376 |
"""Create a beautiful modern UI for the chatbot"""
|
| 377 |
|
| 378 |
bot = ModernChatbot()
|
| 379 |
|
| 380 |
-
# Custom CSS for modern look
|
| 381 |
-
custom_css = """
|
| 382 |
-
<style>
|
| 383 |
-
/* Modern gradient background */
|
| 384 |
-
.gradio-container {
|
| 385 |
-
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
| 386 |
-
min-height: 100vh;
|
| 387 |
-
}
|
| 388 |
-
|
| 389 |
-
/* Modern card design */
|
| 390 |
-
.main-container {
|
| 391 |
-
background: rgba(255, 255, 255, 0.95);
|
| 392 |
-
border-radius: 20px;
|
| 393 |
-
padding: 20px;
|
| 394 |
-
box-shadow: 0 20px 60px rgba(0,0,0,0.3);
|
| 395 |
-
margin: 20px;
|
| 396 |
-
}
|
| 397 |
-
|
| 398 |
-
/* Header styling */
|
| 399 |
-
.gradio-header {
|
| 400 |
-
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
| 401 |
-
border-radius: 15px;
|
| 402 |
-
padding: 20px;
|
| 403 |
-
margin-bottom: 20px;
|
| 404 |
-
box-shadow: 0 10px 30px rgba(0,0,0,0.2);
|
| 405 |
-
}
|
| 406 |
-
|
| 407 |
-
/* Animated title */
|
| 408 |
-
.animated-title {
|
| 409 |
-
text-align: center;
|
| 410 |
-
animation: fadeInDown 0.8s ease-out;
|
| 411 |
-
}
|
| 412 |
-
|
| 413 |
-
@keyframes fadeInDown {
|
| 414 |
-
from {
|
| 415 |
-
opacity: 0;
|
| 416 |
-
transform: translateY(-20px);
|
| 417 |
-
}
|
| 418 |
-
to {
|
| 419 |
-
opacity: 1;
|
| 420 |
-
transform: translateY(0);
|
| 421 |
-
}
|
| 422 |
-
}
|
| 423 |
-
|
| 424 |
-
/* Feature cards */
|
| 425 |
-
.feature-grid {
|
| 426 |
-
display: grid;
|
| 427 |
-
grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
|
| 428 |
-
gap: 15px;
|
| 429 |
-
margin: 20px 0;
|
| 430 |
-
}
|
| 431 |
-
|
| 432 |
-
.feature-card {
|
| 433 |
-
background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
|
| 434 |
-
color: white;
|
| 435 |
-
padding: 15px;
|
| 436 |
-
border-radius: 15px;
|
| 437 |
-
text-align: center;
|
| 438 |
-
font-weight: bold;
|
| 439 |
-
cursor: pointer;
|
| 440 |
-
transition: all 0.3s ease;
|
| 441 |
-
box-shadow: 0 5px 15px rgba(0,0,0,0.2);
|
| 442 |
-
}
|
| 443 |
-
|
| 444 |
-
.feature-card:hover {
|
| 445 |
-
transform: translateY(-5px);
|
| 446 |
-
box-shadow: 0 10px 25px rgba(0,0,0,0.3);
|
| 447 |
-
}
|
| 448 |
-
|
| 449 |
-
/* Chat message styling */
|
| 450 |
-
.message-container {
|
| 451 |
-
border-radius: 15px;
|
| 452 |
-
padding: 20px;
|
| 453 |
-
margin-bottom: 15px;
|
| 454 |
-
}
|
| 455 |
-
|
| 456 |
-
/* Input field styling */
|
| 457 |
-
textarea {
|
| 458 |
-
border: 2px solid #667eea !important;
|
| 459 |
-
border-radius: 25px !important;
|
| 460 |
-
padding: 12px 20px !important;
|
| 461 |
-
font-size: 16px !important;
|
| 462 |
-
transition: all 0.3s ease !important;
|
| 463 |
-
}
|
| 464 |
-
|
| 465 |
-
textarea:focus {
|
| 466 |
-
border-color: #764ba2 !important;
|
| 467 |
-
box-shadow: 0 0 10px rgba(118, 75, 162, 0.3) !important;
|
| 468 |
-
outline: none !important;
|
| 469 |
-
}
|
| 470 |
-
|
| 471 |
-
/* Button styling */
|
| 472 |
-
button {
|
| 473 |
-
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
|
| 474 |
-
border: none !important;
|
| 475 |
-
border-radius: 25px !important;
|
| 476 |
-
padding: 10px 25px !important;
|
| 477 |
-
color: white !important;
|
| 478 |
-
font-weight: bold !important;
|
| 479 |
-
transition: all 0.3s ease !important;
|
| 480 |
-
}
|
| 481 |
-
|
| 482 |
-
button:hover {
|
| 483 |
-
transform: scale(1.05) !important;
|
| 484 |
-
box-shadow: 0 5px 15px rgba(0,0,0,0.2) !important;
|
| 485 |
-
}
|
| 486 |
-
|
| 487 |
-
/* Footer styling */
|
| 488 |
-
.modern-footer {
|
| 489 |
-
text-align: center;
|
| 490 |
-
padding: 20px;
|
| 491 |
-
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
| 492 |
-
border-radius: 15px;
|
| 493 |
-
color: white;
|
| 494 |
-
margin-top: 20px;
|
| 495 |
-
}
|
| 496 |
-
</style>
|
| 497 |
-
"""
|
| 498 |
-
|
| 499 |
with gr.Blocks(title="π€ Nova AI - Smart Rule-Based Chatbot") as demo:
|
| 500 |
|
| 501 |
# Header Section
|
| 502 |
-
|
| 503 |
-
|
| 504 |
-
|
| 505 |
-
|
| 506 |
-
|
| 507 |
-
|
| 508 |
-
|
| 509 |
-
|
| 510 |
-
|
| 511 |
-
|
| 512 |
-
</div>
|
| 513 |
-
""")
|
| 514 |
|
| 515 |
# Quick Feature Cards
|
| 516 |
gr.HTML("""
|
|
@@ -525,56 +500,48 @@ def create_chatbot():
|
|
| 525 |
""")
|
| 526 |
|
| 527 |
# Main Chat Interface
|
| 528 |
-
|
| 529 |
-
|
| 530 |
-
|
| 531 |
-
|
| 532 |
-
|
| 533 |
-
|
| 534 |
-
|
| 535 |
-
|
| 536 |
-
|
| 537 |
-
|
| 538 |
-
|
| 539 |
-
|
| 540 |
-
|
| 541 |
-
|
| 542 |
-
|
| 543 |
-
|
| 544 |
-
|
| 545 |
-
|
| 546 |
-
|
| 547 |
-
|
| 548 |
-
|
| 549 |
-
|
| 550 |
-
|
| 551 |
-
|
| 552 |
-
|
| 553 |
-
|
| 554 |
-
|
| 555 |
-
|
| 556 |
-
|
| 557 |
-
|
| 558 |
-
|
| 559 |
-
|
| 560 |
-
gr.HTML("""
|
| 561 |
-
<div class="modern-footer">
|
| 562 |
-
<div style="display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap;">
|
| 563 |
-
<div>
|
| 564 |
-
<strong>π€ Nova AI</strong> | Rule-Based Chatbot
|
| 565 |
-
</div>
|
| 566 |
-
<div>
|
| 567 |
-
π Python | β‘ Gradio | π¨ Modern UI
|
| 568 |
-
</div>
|
| 569 |
-
<div>
|
| 570 |
-
π‘ Built with β€οΈ for Great Conversations
|
| 571 |
-
</div>
|
| 572 |
-
</div>
|
| 573 |
-
<div style="margin-top: 15px; font-size: 0.9em;">
|
| 574 |
-
β¨ The conversation continues until you type <strong>'bye'</strong> | I remember your name during our chat β¨
|
| 575 |
-
</div>
|
| 576 |
</div>
|
| 577 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 578 |
|
| 579 |
# JavaScript for feature card clicks
|
| 580 |
gr.HTML("""
|
|
@@ -591,37 +558,30 @@ def create_chatbot():
|
|
| 591 |
const inputEvent = new Event('input', { bubbles: true });
|
| 592 |
inputField.dispatchEvent(inputEvent);
|
| 593 |
|
| 594 |
-
// Find and click the send button
|
| 595 |
const buttons = document.querySelectorAll('button');
|
| 596 |
const sendButtons = Array.from(buttons).filter(btn =>
|
| 597 |
btn.textContent.includes('Send') ||
|
| 598 |
btn.textContent.includes('Submit') ||
|
| 599 |
-
btn.querySelector('svg')
|
| 600 |
);
|
| 601 |
|
| 602 |
if (sendButtons.length > 0) {
|
| 603 |
-
// Click the last send button
|
| 604 |
sendButtons[sendButtons.length - 1].click();
|
| 605 |
}
|
| 606 |
}
|
| 607 |
}
|
| 608 |
-
|
| 609 |
-
// Add CSS for feature cards
|
| 610 |
-
const style = document.createElement('style');
|
| 611 |
-
style.textContent = `
|
| 612 |
-
.feature-card {
|
| 613 |
-
cursor: pointer;
|
| 614 |
-
user-select: none;
|
| 615 |
-
}
|
| 616 |
-
`;
|
| 617 |
-
document.head.appendChild(style);
|
| 618 |
</script>
|
| 619 |
""")
|
| 620 |
|
| 621 |
-
# Apply theme and CSS in launch
|
| 622 |
return demo
|
| 623 |
|
| 624 |
# Launch the app
|
| 625 |
if __name__ == "__main__":
|
| 626 |
demo = create_chatbot()
|
| 627 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 371 |
|
| 372 |
**What would you like to try first? π**"""
|
| 373 |
|
| 374 |
+
# Define custom CSS as a global variable
|
| 375 |
+
CUSTOM_CSS = """
|
| 376 |
+
<style>
|
| 377 |
+
/* Modern gradient background */
|
| 378 |
+
.gradio-container {
|
| 379 |
+
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
| 380 |
+
min-height: 100vh;
|
| 381 |
+
}
|
| 382 |
+
|
| 383 |
+
/* Header styling */
|
| 384 |
+
.animated-title {
|
| 385 |
+
text-align: center;
|
| 386 |
+
animation: fadeInDown 0.8s ease-out;
|
| 387 |
+
padding: 20px;
|
| 388 |
+
}
|
| 389 |
+
|
| 390 |
+
@keyframes fadeInDown {
|
| 391 |
+
from {
|
| 392 |
+
opacity: 0;
|
| 393 |
+
transform: translateY(-20px);
|
| 394 |
+
}
|
| 395 |
+
to {
|
| 396 |
+
opacity: 1;
|
| 397 |
+
transform: translateY(0);
|
| 398 |
+
}
|
| 399 |
+
}
|
| 400 |
+
|
| 401 |
+
/* Feature cards */
|
| 402 |
+
.feature-grid {
|
| 403 |
+
display: grid;
|
| 404 |
+
grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
|
| 405 |
+
gap: 15px;
|
| 406 |
+
margin: 20px 0;
|
| 407 |
+
padding: 0 20px;
|
| 408 |
+
}
|
| 409 |
+
|
| 410 |
+
.feature-card {
|
| 411 |
+
background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
|
| 412 |
+
color: white;
|
| 413 |
+
padding: 15px;
|
| 414 |
+
border-radius: 15px;
|
| 415 |
+
text-align: center;
|
| 416 |
+
font-weight: bold;
|
| 417 |
+
cursor: pointer;
|
| 418 |
+
transition: all 0.3s ease;
|
| 419 |
+
box-shadow: 0 5px 15px rgba(0,0,0,0.2);
|
| 420 |
+
}
|
| 421 |
+
|
| 422 |
+
.feature-card:hover {
|
| 423 |
+
transform: translateY(-5px);
|
| 424 |
+
box-shadow: 0 10px 25px rgba(0,0,0,0.3);
|
| 425 |
+
}
|
| 426 |
+
|
| 427 |
+
/* Input field styling */
|
| 428 |
+
textarea {
|
| 429 |
+
border: 2px solid #667eea !important;
|
| 430 |
+
border-radius: 25px !important;
|
| 431 |
+
padding: 12px 20px !important;
|
| 432 |
+
font-size: 16px !important;
|
| 433 |
+
transition: all 0.3s ease !important;
|
| 434 |
+
}
|
| 435 |
+
|
| 436 |
+
textarea:focus {
|
| 437 |
+
border-color: #764ba2 !important;
|
| 438 |
+
box-shadow: 0 0 10px rgba(118, 75, 162, 0.3) !important;
|
| 439 |
+
outline: none !important;
|
| 440 |
+
}
|
| 441 |
+
|
| 442 |
+
/* Button styling */
|
| 443 |
+
button {
|
| 444 |
+
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
|
| 445 |
+
border: none !important;
|
| 446 |
+
border-radius: 25px !important;
|
| 447 |
+
padding: 10px 25px !important;
|
| 448 |
+
color: white !important;
|
| 449 |
+
font-weight: bold !important;
|
| 450 |
+
transition: all 0.3s ease !important;
|
| 451 |
+
}
|
| 452 |
+
|
| 453 |
+
button:hover {
|
| 454 |
+
transform: scale(1.05) !important;
|
| 455 |
+
box-shadow: 0 5px 15px rgba(0,0,0,0.2) !important;
|
| 456 |
+
}
|
| 457 |
+
|
| 458 |
+
/* Footer styling */
|
| 459 |
+
.modern-footer {
|
| 460 |
+
text-align: center;
|
| 461 |
+
padding: 20px;
|
| 462 |
+
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
| 463 |
+
border-radius: 15px;
|
| 464 |
+
color: white;
|
| 465 |
+
margin-top: 20px;
|
| 466 |
+
}
|
| 467 |
+
</style>
|
| 468 |
+
"""
|
| 469 |
+
|
| 470 |
# Modern UI with custom styling
|
| 471 |
def create_chatbot():
|
| 472 |
"""Create a beautiful modern UI for the chatbot"""
|
| 473 |
|
| 474 |
bot = ModernChatbot()
|
| 475 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 476 |
with gr.Blocks(title="π€ Nova AI - Smart Rule-Based Chatbot") as demo:
|
| 477 |
|
| 478 |
# Header Section
|
| 479 |
+
gr.HTML("""
|
| 480 |
+
<div class="animated-title">
|
| 481 |
+
<h1 style="font-size: 3em; margin-bottom: 0; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); -webkit-background-clip: text; -webkit-text-fill-color: transparent;">
|
| 482 |
+
π€ Nova AI Assistant
|
| 483 |
+
</h1>
|
| 484 |
+
<p style="font-size: 1.2em; color: #667eea; margin-top: 5px;">
|
| 485 |
+
Intelligent Conversations | Instant Responses | Always Here for You
|
| 486 |
+
</p>
|
| 487 |
+
</div>
|
| 488 |
+
""")
|
|
|
|
|
|
|
| 489 |
|
| 490 |
# Quick Feature Cards
|
| 491 |
gr.HTML("""
|
|
|
|
| 500 |
""")
|
| 501 |
|
| 502 |
# Main Chat Interface
|
| 503 |
+
gr.ChatInterface(
|
| 504 |
+
fn=bot.process_message,
|
| 505 |
+
title="π¬ Chat with Nova",
|
| 506 |
+
description="""
|
| 507 |
+
β¨ **Modern AI Assistant** - I understand natural language and respond intelligently!
|
| 508 |
+
|
| 509 |
+
π‘ **Pro Tip:** Type **'help'** to see all commands | Say **'bye'** to end conversation
|
| 510 |
+
""",
|
| 511 |
+
examples=[
|
| 512 |
+
["hello π"],
|
| 513 |
+
["My name is Sarah"],
|
| 514 |
+
["how are you?"],
|
| 515 |
+
["tell me a joke π"],
|
| 516 |
+
["I'm feeling sad today π"],
|
| 517 |
+
["recommend an action movie π¬"],
|
| 518 |
+
["I'm hungry for italian food π"],
|
| 519 |
+
["motivate me please πͺ"],
|
| 520 |
+
["what can you do?"],
|
| 521 |
+
["help π"],
|
| 522 |
+
["bye π"]
|
| 523 |
+
]
|
| 524 |
+
)
|
| 525 |
+
|
| 526 |
+
# Footer
|
| 527 |
+
gr.HTML("""
|
| 528 |
+
<div class="modern-footer">
|
| 529 |
+
<div style="display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap;">
|
| 530 |
+
<div>
|
| 531 |
+
<strong>π€ Nova AI</strong> | Rule-Based Chatbot
|
| 532 |
+
</div>
|
| 533 |
+
<div>
|
| 534 |
+
π Python | β‘ Gradio | π¨ Modern UI
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 535 |
</div>
|
| 536 |
+
<div>
|
| 537 |
+
π‘ Built with β€οΈ for Great Conversations
|
| 538 |
+
</div>
|
| 539 |
+
</div>
|
| 540 |
+
<div style="margin-top: 15px; font-size: 0.9em;">
|
| 541 |
+
β¨ The conversation continues until you type <strong>'bye'</strong> | I remember your name during our chat β¨
|
| 542 |
+
</div>
|
| 543 |
+
</div>
|
| 544 |
+
""")
|
| 545 |
|
| 546 |
# JavaScript for feature card clicks
|
| 547 |
gr.HTML("""
|
|
|
|
| 558 |
const inputEvent = new Event('input', { bubbles: true });
|
| 559 |
inputField.dispatchEvent(inputEvent);
|
| 560 |
|
| 561 |
+
// Find and click the send button
|
| 562 |
const buttons = document.querySelectorAll('button');
|
| 563 |
const sendButtons = Array.from(buttons).filter(btn =>
|
| 564 |
btn.textContent.includes('Send') ||
|
| 565 |
btn.textContent.includes('Submit') ||
|
| 566 |
+
btn.querySelector('svg')
|
| 567 |
);
|
| 568 |
|
| 569 |
if (sendButtons.length > 0) {
|
|
|
|
| 570 |
sendButtons[sendButtons.length - 1].click();
|
| 571 |
}
|
| 572 |
}
|
| 573 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 574 |
</script>
|
| 575 |
""")
|
| 576 |
|
|
|
|
| 577 |
return demo
|
| 578 |
|
| 579 |
# Launch the app
|
| 580 |
if __name__ == "__main__":
|
| 581 |
demo = create_chatbot()
|
| 582 |
+
# Apply theme and CSS in launch
|
| 583 |
+
demo.launch(
|
| 584 |
+
share=True,
|
| 585 |
+
theme=gr.themes.Soft(primary_hue="purple", secondary_hue="pink"),
|
| 586 |
+
css=CUSTOM_CSS
|
| 587 |
+
)
|