Subbu1304 commited on
Commit
45e90b2
Β·
verified Β·
1 Parent(s): 4fa3ff7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -33
app.py CHANGED
@@ -1,26 +1,36 @@
 
1
  import gradio as gr
2
- import random
3
  from datetime import datetime
4
 
5
- # Sample list of dishes (this can be dynamic or fetched from a database)
6
- dishes = [
7
- {"id": 1, "name": "Spaghetti Bolognese", "price": 12.99},
8
- {"id": 2, "name": "Margherita Pizza", "price": 9.99},
9
- {"id": 3, "name": "Chicken Alfredo", "price": 14.99},
10
- {"id": 4, "name": "Caesar Salad", "price": 7.99},
11
- {"id": 5, "name": "Garlic Bread", "price": 4.99}
12
- ]
13
-
14
- # Function to generate a dynamic wish message
15
- def generate_wish(occasion):
16
- wishes = {
17
- "birthday": ["Happy Birthday! πŸŽ‰", "Wishing you a day full of love and joy! πŸŽ‚", "May your day be as special as you are! 🎈"],
18
- "anniversary": ["Happy Anniversary! ❀️", "Here's to many more years of love and happiness! πŸ₯‚", "May your love continue to grow stronger every year! πŸ’"],
19
- "congratulations": ["Congratulations on your special achievement! πŸŽ‰", "Wishing you continued success and happiness! 🌟", "Well done and keep shining! πŸ’ͺ"],
20
- }
21
- return random.choice(wishes.get(occasion.lower(), ["Wishing you all the best! πŸ’–"]))
 
 
 
 
 
 
 
 
 
 
 
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']})\\n"
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()}\\n"
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()