Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,26 +1,36 @@
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import random
|
| 3 |
from datetime import datetime
|
| 4 |
|
| 5 |
-
#
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
"
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
-
# Function to generate the invoice
|
| 24 |
def generate_invoice(customer_name, table_number, selected_items, wishes):
|
| 25 |
try:
|
| 26 |
selected_items = [item.strip() for item in selected_items.split(',')]
|
|
@@ -40,7 +50,7 @@ def generate_invoice(customer_name, table_number, selected_items, wishes):
|
|
| 40 |
Items Ordered:
|
| 41 |
"""
|
| 42 |
for item in items:
|
| 43 |
-
invoice += f"- {item['name']} (${item['price']})
|
| 44 |
|
| 45 |
invoice += f"""
|
| 46 |
-----------------------------------------
|
|
@@ -49,7 +59,7 @@ def generate_invoice(customer_name, table_number, selected_items, wishes):
|
|
| 49 |
Customer Wishes:
|
| 50 |
"""
|
| 51 |
for wish in wishes.split(','):
|
| 52 |
-
invoice += f"- {wish.strip()}
|
| 53 |
|
| 54 |
invoice += """
|
| 55 |
-----------------------------------------
|
|
@@ -60,13 +70,6 @@ def generate_invoice(customer_name, table_number, selected_items, wishes):
|
|
| 60 |
except Exception as e:
|
| 61 |
return f"Error generating invoice: {str(e)}"
|
| 62 |
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
# Function to display the dynamic app interface
|
| 66 |
-
def display_interface():
|
| 67 |
-
dish_names = [dish["name"] for dish in dishes]
|
| 68 |
-
|
| 69 |
-
# Gradio Interface for Dish Selection and Occasion Input
|
| 70 |
with gr.Blocks() as demo:
|
| 71 |
gr.Markdown("""# Restaurant Invoice Generator
|
| 72 |
### Welcome to our restaurant!
|
|
@@ -77,6 +80,7 @@ with gr.Blocks() as demo:
|
|
| 77 |
customer_name = gr.Textbox(label="Customer Name")
|
| 78 |
table_number = gr.Textbox(label="Table Number")
|
| 79 |
|
|
|
|
| 80 |
menu_display = gr.Textbox(show_label=False, interactive=False, value=render_menu())
|
| 81 |
|
| 82 |
selected_items = gr.Textbox(label="Selected Items (comma-separated)", placeholder="e.g., Roti, Paneer Butter Masala")
|
|
@@ -86,14 +90,10 @@ with gr.Blocks() as demo:
|
|
| 86 |
|
| 87 |
invoice_output = gr.Textbox(label="Generated Invoice", lines=15, interactive=False)
|
| 88 |
|
| 89 |
-
# Ensure all 4 inputs are passed to the function
|
| 90 |
generate_invoice_btn.click(
|
| 91 |
generate_invoice,
|
| 92 |
inputs=[customer_name, table_number, selected_items, wishes],
|
| 93 |
outputs=invoice_output
|
| 94 |
)
|
| 95 |
|
| 96 |
-
|
| 97 |
-
# Run the Gradio interface
|
| 98 |
-
if __name__ == "__main__":
|
| 99 |
-
display_interface()
|
|
|
|
| 1 |
+
# app.py
|
| 2 |
import gradio as gr
|
|
|
|
| 3 |
from datetime import datetime
|
| 4 |
|
| 5 |
+
# Dynamic menu data
|
| 6 |
+
menu = {
|
| 7 |
+
"Bread": [
|
| 8 |
+
{"name": "Roti", "price": 2},
|
| 9 |
+
{"name": "Naan", "price": 3}
|
| 10 |
+
],
|
| 11 |
+
"Veg Curries": [
|
| 12 |
+
{"name": "Paneer Butter Masala", "price": 10},
|
| 13 |
+
{"name": "Mixed Vegetable Curry", "price": 8}
|
| 14 |
+
],
|
| 15 |
+
"Non-Veg Curries": [
|
| 16 |
+
{"name": "Chicken Curry", "price": 12},
|
| 17 |
+
{"name": "Mutton Curry", "price": 15}
|
| 18 |
+
],
|
| 19 |
+
"Biryanis": [
|
| 20 |
+
{"name": "Vegetable Biryani", "price": 10},
|
| 21 |
+
{"name": "Chicken Biryani", "price": 12}
|
| 22 |
+
]
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
# Ensure render_menu is defined before usage
|
| 26 |
+
def render_menu():
|
| 27 |
+
rendered_menu = ""
|
| 28 |
+
for category, items in menu.items():
|
| 29 |
+
rendered_menu += f"\n{category}:\n"
|
| 30 |
+
for item in items:
|
| 31 |
+
rendered_menu += f"- {item['name']} (${item['price']})\n"
|
| 32 |
+
return rendered_menu
|
| 33 |
|
|
|
|
| 34 |
def generate_invoice(customer_name, table_number, selected_items, wishes):
|
| 35 |
try:
|
| 36 |
selected_items = [item.strip() for item in selected_items.split(',')]
|
|
|
|
| 50 |
Items Ordered:
|
| 51 |
"""
|
| 52 |
for item in items:
|
| 53 |
+
invoice += f"- {item['name']} (${item['price']})\n"
|
| 54 |
|
| 55 |
invoice += f"""
|
| 56 |
-----------------------------------------
|
|
|
|
| 59 |
Customer Wishes:
|
| 60 |
"""
|
| 61 |
for wish in wishes.split(','):
|
| 62 |
+
invoice += f"- {wish.strip()}\n"
|
| 63 |
|
| 64 |
invoice += """
|
| 65 |
-----------------------------------------
|
|
|
|
| 70 |
except Exception as e:
|
| 71 |
return f"Error generating invoice: {str(e)}"
|
| 72 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
with gr.Blocks() as demo:
|
| 74 |
gr.Markdown("""# Restaurant Invoice Generator
|
| 75 |
### Welcome to our restaurant!
|
|
|
|
| 80 |
customer_name = gr.Textbox(label="Customer Name")
|
| 81 |
table_number = gr.Textbox(label="Table Number")
|
| 82 |
|
| 83 |
+
# Ensure render_menu is called after its definition
|
| 84 |
menu_display = gr.Textbox(show_label=False, interactive=False, value=render_menu())
|
| 85 |
|
| 86 |
selected_items = gr.Textbox(label="Selected Items (comma-separated)", placeholder="e.g., Roti, Paneer Butter Masala")
|
|
|
|
| 90 |
|
| 91 |
invoice_output = gr.Textbox(label="Generated Invoice", lines=15, interactive=False)
|
| 92 |
|
|
|
|
| 93 |
generate_invoice_btn.click(
|
| 94 |
generate_invoice,
|
| 95 |
inputs=[customer_name, table_number, selected_items, wishes],
|
| 96 |
outputs=invoice_output
|
| 97 |
)
|
| 98 |
|
| 99 |
+
demo.launch()
|
|
|
|
|
|
|
|
|