Spaces:
Sleeping
Sleeping
added animation
Browse files
app.py
CHANGED
|
@@ -524,8 +524,53 @@ DIETARY_OPTIONS = ["Dairy-free", "Nut-free", "Vegan", "Vegetarian", "Gluten-free
|
|
| 524 |
|
| 525 |
with gr.Blocks() as iface:
|
| 526 |
gr.Markdown("# 🤖 AI Dinner Planner")
|
| 527 |
-
gr.Markdown("Let
|
| 528 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 529 |
with gr.Row():
|
| 530 |
try_new = gr.Checkbox(label="Try Something New?", value=False)
|
| 531 |
cuisine = gr.Dropdown(CUISINE_OPTIONS, label="Cuisine", value="Any")
|
|
@@ -533,16 +578,34 @@ with gr.Blocks() as iface:
|
|
| 533 |
|
| 534 |
run_button = gr.Button("Plan My Dinners!", variant="primary")
|
| 535 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 536 |
with gr.Tabs():
|
| 537 |
with gr.TabItem("Dinner Plan"):
|
| 538 |
plan_output = gr.Markdown(label="Dinner Suggestions", sanitize_html=False)
|
| 539 |
with gr.TabItem("Grocery List"):
|
| 540 |
grocery_output = gr.Markdown(label="Shopping List", sanitize_html=False)
|
| 541 |
|
|
|
|
| 542 |
run_button.click(
|
| 543 |
fn=run_dinner_plan,
|
| 544 |
inputs=[try_new, cuisine, dietary],
|
| 545 |
-
outputs=[plan_output, grocery_output]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 546 |
)
|
| 547 |
|
| 548 |
iface.launch()
|
|
|
|
| 524 |
|
| 525 |
with gr.Blocks() as iface:
|
| 526 |
gr.Markdown("# 🤖 AI Dinner Planner")
|
| 527 |
+
gr.Markdown("Let AI plan your next three dinners. This app searches your saved recipes that your family loves. If you want to try something new, check the box to have the agent search the web for one new recipe to include in the suggestions, based on your preferences.")
|
| 528 |
|
| 529 |
+
# Add custom CSS for the loading animation
|
| 530 |
+
gr.HTML("""
|
| 531 |
+
<style>
|
| 532 |
+
.robot-loading {
|
| 533 |
+
display: none;
|
| 534 |
+
text-align: center;
|
| 535 |
+
padding: 20px;
|
| 536 |
+
margin: 20px auto;
|
| 537 |
+
max-width: 300px;
|
| 538 |
+
}
|
| 539 |
+
.robot-loading.visible {
|
| 540 |
+
display: block;
|
| 541 |
+
}
|
| 542 |
+
.robot-container {
|
| 543 |
+
background: #f0f0f0;
|
| 544 |
+
border-radius: 15px;
|
| 545 |
+
padding: 20px;
|
| 546 |
+
box-shadow: 0 4px 6px rgba(0,0,0,0.1);
|
| 547 |
+
}
|
| 548 |
+
.robot {
|
| 549 |
+
font-size: 40px;
|
| 550 |
+
animation: stir 2s infinite;
|
| 551 |
+
display: inline-block;
|
| 552 |
+
transform-origin: bottom center;
|
| 553 |
+
}
|
| 554 |
+
.pot {
|
| 555 |
+
font-size: 40px;
|
| 556 |
+
margin-left: 10px;
|
| 557 |
+
}
|
| 558 |
+
@keyframes stir {
|
| 559 |
+
0% { transform: rotate(0deg); }
|
| 560 |
+
25% { transform: rotate(-20deg); }
|
| 561 |
+
75% { transform: rotate(20deg); }
|
| 562 |
+
100% { transform: rotate(0deg); }
|
| 563 |
+
}
|
| 564 |
+
</style>
|
| 565 |
+
<div class="robot-loading" id="loading-animation">
|
| 566 |
+
<div class="robot-container">
|
| 567 |
+
<div class="robot">🤖</div>
|
| 568 |
+
<div class="pot">🥘</div>
|
| 569 |
+
<p>Cooking up your dinner plan...</p>
|
| 570 |
+
</div>
|
| 571 |
+
</div>
|
| 572 |
+
""")
|
| 573 |
+
|
| 574 |
with gr.Row():
|
| 575 |
try_new = gr.Checkbox(label="Try Something New?", value=False)
|
| 576 |
cuisine = gr.Dropdown(CUISINE_OPTIONS, label="Cuisine", value="Any")
|
|
|
|
| 578 |
|
| 579 |
run_button = gr.Button("Plan My Dinners!", variant="primary")
|
| 580 |
|
| 581 |
+
# Add JavaScript to control loading animation
|
| 582 |
+
gr.HTML("""
|
| 583 |
+
<script>
|
| 584 |
+
function showLoading() {
|
| 585 |
+
document.getElementById('loading-animation').classList.add('visible');
|
| 586 |
+
}
|
| 587 |
+
function hideLoading() {
|
| 588 |
+
document.getElementById('loading-animation').classList.remove('visible');
|
| 589 |
+
}
|
| 590 |
+
</script>
|
| 591 |
+
""")
|
| 592 |
+
|
| 593 |
with gr.Tabs():
|
| 594 |
with gr.TabItem("Dinner Plan"):
|
| 595 |
plan_output = gr.Markdown(label="Dinner Suggestions", sanitize_html=False)
|
| 596 |
with gr.TabItem("Grocery List"):
|
| 597 |
grocery_output = gr.Markdown(label="Shopping List", sanitize_html=False)
|
| 598 |
|
| 599 |
+
# Update the click handler to show/hide loading animation
|
| 600 |
run_button.click(
|
| 601 |
fn=run_dinner_plan,
|
| 602 |
inputs=[try_new, cuisine, dietary],
|
| 603 |
+
outputs=[plan_output, grocery_output],
|
| 604 |
+
_js="(x) => { showLoading(); return x; }", # Show loading before running
|
| 605 |
+
api_name=False # Ensure JavaScript runs
|
| 606 |
+
).then(
|
| 607 |
+
fn=None,
|
| 608 |
+
_js="() => { hideLoading(); }" # Hide loading after completion
|
| 609 |
)
|
| 610 |
|
| 611 |
iface.launch()
|