Subbu1304 commited on
Commit
90d1ce5
·
verified ·
1 Parent(s): 6bf530c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +58 -64
app.py CHANGED
@@ -1,71 +1,65 @@
1
  import gradio as gr
2
- from fpdf import FPDF
3
- from PIL import Image, ImageDraw, ImageFont
4
 
5
- # Function to generate a themed invoice
6
- def generate_invoice(customer_name, items, logo_path):
7
- # Create a PDF document
8
- pdf = FPDF()
9
- pdf.set_auto_page_break(auto=True, margin=15)
10
- pdf.add_page()
11
-
12
- # Title and Basic Styling
13
- pdf.set_font("Arial", 'B', 16)
14
- pdf.cell(200, 10, txt="Restaurant Invoice", ln=True, align='C')
15
-
16
- # Add logo
17
- if logo_path:
18
- pdf.image(logo_path, x=10, y=20, w=30) # Adjust the size and position of the logo
19
-
20
- # Customer Details
21
- pdf.ln(30) # Add space after title
22
- pdf.set_font("Arial", size=12)
23
- pdf.cell(100, 10, f"Customer: {customer_name}", ln=True)
24
-
25
- # Itemized list
26
- pdf.cell(100, 10, "Item", ln=True, border=1, align="C")
27
- pdf.cell(30, 10, "Price", ln=True, border=1, align="C")
28
- total_price = 0
29
-
30
- for item, price in items.items():
31
- pdf.cell(100, 10, item, ln=True, border=1)
32
- pdf.cell(30, 10, f"${price:.2f}", ln=True, border=1, align="R")
33
- total_price += price
34
-
35
- # Add Total
36
- pdf.ln(10)
37
- pdf.cell(100, 10, "Total", ln=True, align="C", border=1)
38
- pdf.cell(30, 10, f"${total_price:.2f}", ln=True, border=1, align="R")
39
-
40
- # Wish Message
41
- pdf.ln(20)
42
- pdf.set_font("Arial", 'I', 12)
43
- pdf.multi_cell(0, 10, "Thank you for choosing us! We hope to serve you again soon.")
44
-
45
- # Save PDF to a file
46
- pdf_output = "/tmp/invoice.pdf"
47
- pdf.output(pdf_output)
48
- return pdf_output
49
 
 
 
 
 
 
 
 
 
 
50
 
51
  # Gradio Interface
52
- def invoice_interface(customer_name, items, logo_path):
53
- return generate_invoice(customer_name, items, logo_path)
54
-
55
 
56
- # Example Gradio Interface
57
- interface = gr.Interface(
58
- fn=invoice_interface,
59
- inputs=[
60
- gr.Textbox(label="Customer Name"),
61
- gr.JSON(label="Items (JSON format like {'item1': 10.5, 'item2': 7.25})"),
62
- gr.Image(label="Upload Logo", type="filepath")
63
- ],
64
- outputs=gr.File(label="Download Invoice"),
65
- title="Customized Restaurant Invoice Generator",
66
- description="Generate an invoice with your restaurant's custom theme, logo, and message!"
67
- )
68
-
69
- # Launch the app
70
- interface.launch()
71
 
 
 
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()