Subbu1304 commited on
Commit
ba4cf3f
·
verified ·
1 Parent(s): d3bed3c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -36
app.py CHANGED
@@ -1,51 +1,44 @@
1
  import gradio as gr
2
- from PIL import Image, ImageDraw, ImageFont
3
 
 
4
  def generate_invoice(customer_name, items, total_amount):
5
- # Create a blank image with white background
6
- width, height = 400, 600
7
- img = Image.new('RGB', (width, height), color=(255, 255, 255))
8
-
9
- # Initialize drawing context
10
- draw = ImageDraw.Draw(img)
11
- font = ImageFont.load_default()
12
-
13
- # Add restaurant name and header
14
- draw.text((10, 10), "Restaurant XYZ", font=font, fill=(0, 0, 0))
15
- draw.text((10, 40), f"Customer: {customer_name}", font=font, fill=(0, 0, 0))
16
-
17
- # Add items and prices
18
- y_offset = 70
19
- for item in items:
20
- draw.text((10, y_offset), item, font=font, fill=(0, 0, 0))
21
- y_offset += 20
22
-
23
- # Add total amount
24
- draw.text((10, y_offset), f"Total: ${total_amount}", font=font, fill=(0, 0, 0))
25
-
26
- # Add a wish message
27
- y_offset += 30
28
- draw.text((10, y_offset), "Thank you for dining with us!", font=font, fill=(0, 0, 0))
29
-
30
- # Save the image to a temporary file
31
- img_path = "/tmp/invoice.png"
32
- img.save(img_path)
33
 
34
- return img_path
 
 
 
 
 
 
35
 
36
  # Gradio interface
37
  iface = gr.Interface(
38
  fn=generate_invoice,
39
  inputs=[
40
- gr.Textbox(label="Customer Name"),
41
- gr.Textbox(label="Items (comma-separated)"),
42
- gr.Textbox(label="Total Amount")
43
  ],
44
- outputs=gr.Image(label="Generated Invoice"),
45
- title="Custom Invoice Generator",
46
- description="Enter the customer name, items, and total amount to generate a customized restaurant invoice with a wish message."
47
  )
48
 
49
  # Launch the app
50
  iface.launch()
51
 
 
 
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
+