Subbu1304 commited on
Commit
1674c86
·
verified ·
1 Parent(s): 90d1ce5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -60
app.py CHANGED
@@ -1,65 +1,21 @@
1
  import gradio as gr
2
- import json
3
 
4
- # Sample JSON data of dishes
5
- dishes = [
6
- {
7
- "dish_id": 1,
8
- "name": "Spaghetti Bolognese",
9
- "description": "Classic Italian pasta with a rich, meaty tomato sauce.",
10
- "price": 12.99
11
- },
12
- {
13
- "dish_id": 2,
14
- "name": "Margherita Pizza",
15
- "description": "Simple and delicious pizza with fresh mozzarella, basil, and tomato sauce.",
16
- "price": 9.99
17
- },
18
- {
19
- "dish_id": 3,
20
- "name": "Caesar Salad",
21
- "description": "Crisp romaine lettuce, parmesan, croutons, and Caesar dressing.",
22
- "price": 8.99
23
- },
24
- {
25
- "dish_id": 4,
26
- "name": "Chicken Alfredo",
27
- "description": "Grilled chicken breast served with creamy Alfredo sauce over fettuccine.",
28
- "price": 14.99
29
- },
30
- {
31
- "dish_id": 5,
32
- "name": "Tiramisu",
33
- "description": "Classic Italian dessert with layers of coffee-soaked ladyfingers and mascarpone cream.",
34
- "price": 5.99
35
- }
36
- ]
37
-
38
- # Function to generate an invoice based on selected dishes
39
- def generate_invoice(selected_dishes):
40
- total_price = sum(dish["price"] for dish in selected_dishes)
41
- invoice_text = "----- Invoice -----\n"
42
- for dish in selected_dishes:
43
- invoice_text += f"{dish['name']}: ${dish['price']}\n"
44
- invoice_text += f"Total: ${total_price:.2f}\n"
45
- invoice_text += "\nThank you for dining with us! Have a great day!"
46
- return invoice_text
47
-
48
- # Gradio Interface
49
- def invoice_interface(selected_dishes_ids):
50
- selected_dishes = [dishes[i] for i in selected_dishes_ids]
51
- return generate_invoice(selected_dishes)
52
 
53
  # Create Gradio interface
54
- with gr.Blocks() as demo:
55
- gr.Markdown("### Select Dishes for Your Invoice")
56
-
57
- dish_choices = [gr.Checkbox(label=dish['name'], value=False) for dish in dishes]
58
-
59
- btn = gr.Button("Generate Invoice")
60
-
61
- output = gr.Textbox(label="Invoice")
62
-
63
- btn.click(invoice_interface, inputs=dish_choices, outputs=output)
64
 
65
- demo.launch()
 
1
  import gradio as gr
 
2
 
3
+ # Sample function to generate invoice
4
+ def generate_invoice(dishes):
5
+ dishes_list = dishes.split(",")
6
+ total = len(dishes_list) * 10 # Assume each dish costs $10
7
+ invoice = f"Invoice for dishes: {', '.join(dishes_list)}\nTotal: ${total}"
8
+ return invoice
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
 
10
  # Create Gradio interface
11
+ interface = gr.Interface(
12
+ fn=generate_invoice,
13
+ inputs=gr.Textbox(label="Enter Dishes (comma-separated)"),
14
+ outputs="text",
15
+ title="Restaurant Invoice Generator",
16
+ description="Enter the names of dishes to generate a themed invoice with a custom message."
17
+ )
18
+
19
+ # Launch the interface
20
+ interface.launch()
21