Update app.py
Browse files
app.py
CHANGED
|
@@ -284,7 +284,7 @@ def get_recipe_suggestions(api_key, image_paths, num_recipes=3, dietary_restrict
|
|
| 284 |
{"role": "system", "content": system_prompt},
|
| 285 |
{"role": "user", "content": user_prompt}
|
| 286 |
],
|
| 287 |
-
max_tokens=
|
| 288 |
temperature=0.7
|
| 289 |
)
|
| 290 |
|
|
@@ -508,7 +508,7 @@ body {
|
|
| 508 |
padding: 0;
|
| 509 |
}
|
| 510 |
.container {
|
| 511 |
-
|
| 512 |
margin: 0 auto;
|
| 513 |
padding: 20px;
|
| 514 |
}
|
|
@@ -519,6 +519,7 @@ body {
|
|
| 519 |
text-align: center;
|
| 520 |
border-radius: 0 0 30px 30px;
|
| 521 |
box-shadow: var(--box-shadow);
|
|
|
|
| 522 |
}
|
| 523 |
.app-title {
|
| 524 |
font-size: 2.8em;
|
|
@@ -537,6 +538,7 @@ body {
|
|
| 537 |
padding: 30px;
|
| 538 |
box-shadow: var(--box-shadow);
|
| 539 |
margin-bottom: 30px;
|
|
|
|
| 540 |
}
|
| 541 |
.section-header {
|
| 542 |
font-size: 1.6em;
|
|
@@ -658,43 +660,6 @@ button.download-button:hover {
|
|
| 658 |
color: var(--primary-color);
|
| 659 |
margin-bottom: 10px;
|
| 660 |
}
|
| 661 |
-
.loading-container {
|
| 662 |
-
display: flex;
|
| 663 |
-
flex-direction: column;
|
| 664 |
-
justify-content: center;
|
| 665 |
-
align-items: center;
|
| 666 |
-
position: fixed;
|
| 667 |
-
top: 0;
|
| 668 |
-
left: 0;
|
| 669 |
-
width: 100%;
|
| 670 |
-
height: 100%;
|
| 671 |
-
background-color: rgba(0, 0, 0, 0.5);
|
| 672 |
-
z-index: 1000;
|
| 673 |
-
opacity: 0;
|
| 674 |
-
visibility: hidden;
|
| 675 |
-
transition: opacity 0.3s ease, visibility 0.3s ease;
|
| 676 |
-
}
|
| 677 |
-
.loading-container.visible {
|
| 678 |
-
opacity: 1;
|
| 679 |
-
visibility: visible;
|
| 680 |
-
}
|
| 681 |
-
.loading-spinner {
|
| 682 |
-
border: 8px solid #f3f3f3;
|
| 683 |
-
border-top: 8px solid var(--primary-color);
|
| 684 |
-
border-radius: 50%;
|
| 685 |
-
width: 60px;
|
| 686 |
-
height: 60px;
|
| 687 |
-
animation: spin 1s linear infinite;
|
| 688 |
-
}
|
| 689 |
-
@keyframes spin {
|
| 690 |
-
0% { transform: rotate(0deg); }
|
| 691 |
-
100% { transform: rotate(360deg); }
|
| 692 |
-
}
|
| 693 |
-
.loading-text {
|
| 694 |
-
color: white;
|
| 695 |
-
font-size: 1.3em;
|
| 696 |
-
margin-top: 20px;
|
| 697 |
-
}
|
| 698 |
.footer {
|
| 699 |
background-color: var(--card-background);
|
| 700 |
padding: 40px 20px;
|
|
@@ -702,6 +667,7 @@ button.download-button:hover {
|
|
| 702 |
color: var(--text-color);
|
| 703 |
font-size: 1.1em;
|
| 704 |
box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.05);
|
|
|
|
| 705 |
}
|
| 706 |
.footer-content {
|
| 707 |
max-width: 800px;
|
|
@@ -727,19 +693,6 @@ html_header = """
|
|
| 727 |
<div class="app-title">🍲 Visual Recipe Assistant</div>
|
| 728 |
<div class="app-subtitle">Upload images of ingredients you have on hand and get personalized recipe suggestions powered by AI</div>
|
| 729 |
</div>
|
| 730 |
-
<div id="loading-overlay" class="loading-container">
|
| 731 |
-
<div class="loading-spinner"></div>
|
| 732 |
-
<div class="loading-text">Generating your recipes...</div>
|
| 733 |
-
</div>
|
| 734 |
-
<script>
|
| 735 |
-
function showLoading() {
|
| 736 |
-
document.getElementById('loading-overlay').classList.add('visible');
|
| 737 |
-
}
|
| 738 |
-
|
| 739 |
-
function hideLoading() {
|
| 740 |
-
document.getElementById('loading-overlay').classList.remove('visible');
|
| 741 |
-
}
|
| 742 |
-
</script>
|
| 743 |
"""
|
| 744 |
|
| 745 |
html_footer = """
|
|
@@ -755,37 +708,6 @@ html_footer = """
|
|
| 755 |
</div>
|
| 756 |
</div>
|
| 757 |
</div>
|
| 758 |
-
<script>
|
| 759 |
-
document.addEventListener('DOMContentLoaded', function() {
|
| 760 |
-
const submitBtn = document.querySelector('button.primary-button');
|
| 761 |
-
if (submitBtn) {
|
| 762 |
-
submitBtn.addEventListener('click', function() {
|
| 763 |
-
showLoading();
|
| 764 |
-
// Check every second for output content
|
| 765 |
-
const checkInterval = setInterval(function() {
|
| 766 |
-
const output = document.querySelector('.recipe-output');
|
| 767 |
-
if (output && output.innerHTML.trim().length > 0) {
|
| 768 |
-
hideLoading();
|
| 769 |
-
clearInterval(checkInterval);
|
| 770 |
-
clearTimeout(forceHideTimeout);
|
| 771 |
-
|
| 772 |
-
// Show download button if it exists
|
| 773 |
-
const downloadBtn = document.getElementById('download-button');
|
| 774 |
-
if (downloadBtn) {
|
| 775 |
-
downloadBtn.style.display = 'flex';
|
| 776 |
-
}
|
| 777 |
-
}
|
| 778 |
-
}, 1000);
|
| 779 |
-
|
| 780 |
-
// Force hide after 120 seconds
|
| 781 |
-
const forceHideTimeout = setTimeout(function() {
|
| 782 |
-
hideLoading();
|
| 783 |
-
clearInterval(checkInterval);
|
| 784 |
-
}, 120000);
|
| 785 |
-
});
|
| 786 |
-
}
|
| 787 |
-
});
|
| 788 |
-
</script>
|
| 789 |
"""
|
| 790 |
|
| 791 |
with gr.Blocks(css=custom_css) as app:
|
|
@@ -873,8 +795,7 @@ with gr.Blocks(css=custom_css) as app:
|
|
| 873 |
submit_button.click(
|
| 874 |
fn=process_and_update_file_path,
|
| 875 |
inputs=[api_key_input, file_upload, num_recipes, dietary_restrictions, cuisine_preference],
|
| 876 |
-
outputs=[output, html_file_path, download_button]
|
| 877 |
-
show_progress=True # Show Gradio's built-in progress indicator as well
|
| 878 |
)
|
| 879 |
|
| 880 |
# Handle download button click
|
|
@@ -885,4 +806,4 @@ with gr.Blocks(css=custom_css) as app:
|
|
| 885 |
)
|
| 886 |
|
| 887 |
if __name__ == "__main__":
|
| 888 |
-
app.launch()
|
|
|
|
| 284 |
{"role": "system", "content": system_prompt},
|
| 285 |
{"role": "user", "content": user_prompt}
|
| 286 |
],
|
| 287 |
+
max_tokens=20000,
|
| 288 |
temperature=0.7
|
| 289 |
)
|
| 290 |
|
|
|
|
| 508 |
padding: 0;
|
| 509 |
}
|
| 510 |
.container {
|
| 511 |
+
width: 100%;
|
| 512 |
margin: 0 auto;
|
| 513 |
padding: 20px;
|
| 514 |
}
|
|
|
|
| 519 |
text-align: center;
|
| 520 |
border-radius: 0 0 30px 30px;
|
| 521 |
box-shadow: var(--box-shadow);
|
| 522 |
+
width: 100%;
|
| 523 |
}
|
| 524 |
.app-title {
|
| 525 |
font-size: 2.8em;
|
|
|
|
| 538 |
padding: 30px;
|
| 539 |
box-shadow: var(--box-shadow);
|
| 540 |
margin-bottom: 30px;
|
| 541 |
+
width: 100%;
|
| 542 |
}
|
| 543 |
.section-header {
|
| 544 |
font-size: 1.6em;
|
|
|
|
| 660 |
color: var(--primary-color);
|
| 661 |
margin-bottom: 10px;
|
| 662 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 663 |
.footer {
|
| 664 |
background-color: var(--card-background);
|
| 665 |
padding: 40px 20px;
|
|
|
|
| 667 |
color: var(--text-color);
|
| 668 |
font-size: 1.1em;
|
| 669 |
box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.05);
|
| 670 |
+
width: 100%;
|
| 671 |
}
|
| 672 |
.footer-content {
|
| 673 |
max-width: 800px;
|
|
|
|
| 693 |
<div class="app-title">🍲 Visual Recipe Assistant</div>
|
| 694 |
<div class="app-subtitle">Upload images of ingredients you have on hand and get personalized recipe suggestions powered by AI</div>
|
| 695 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 696 |
"""
|
| 697 |
|
| 698 |
html_footer = """
|
|
|
|
| 708 |
</div>
|
| 709 |
</div>
|
| 710 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 711 |
"""
|
| 712 |
|
| 713 |
with gr.Blocks(css=custom_css) as app:
|
|
|
|
| 795 |
submit_button.click(
|
| 796 |
fn=process_and_update_file_path,
|
| 797 |
inputs=[api_key_input, file_upload, num_recipes, dietary_restrictions, cuisine_preference],
|
| 798 |
+
outputs=[output, html_file_path, download_button]
|
|
|
|
| 799 |
)
|
| 800 |
|
| 801 |
# Handle download button click
|
|
|
|
| 806 |
)
|
| 807 |
|
| 808 |
if __name__ == "__main__":
|
| 809 |
+
app.launch()
|