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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +60 -33
app.py CHANGED
@@ -1,44 +1,71 @@
1
  import gradio as gr
 
 
2
 
3
- # Function to generate a customized invoice with a wish message
4
- def generate_invoice(customer_name, items, total_amount):
5
- # Customized message
6
- wish_message = f"Thank you for visiting, {customer_name}! We appreciate your business."
7
-
8
- # Sample invoice structure
9
- invoice = f"""
10
- ----------------------------------------
11
- INVOICE
12
- Restaurant Name: Example Restaurant
13
- Address: 123 Main Street, City, State
14
- Phone: (555) 123-4567
15
- ----------------------------------------
16
- Customer: {customer_name}
17
- ----------------------------------------
18
- Items:
19
- {items}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
 
21
- Total Amount: ${total_amount}
22
- ----------------------------------------
23
- {wish_message}
24
- ----------------------------------------
25
- """
26
 
27
- return invoice
 
 
28
 
29
- # Gradio interface
30
- iface = gr.Interface(
31
- fn=generate_invoice,
 
32
  inputs=[
33
  gr.Textbox(label="Customer Name"),
34
- gr.Textbox(label="Items (comma separated)"),
35
- gr.Number(label="Total Amount")
36
- ],
37
- outputs="text",
38
- live=True
 
39
  )
40
 
41
  # Launch the app
42
- iface.launch()
43
-
44
 
 
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