Update app.py
Browse files
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 |
-
#
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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
|
| 42 |
-
gr.
|
| 43 |
],
|
| 44 |
-
outputs=
|
| 45 |
-
|
| 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 |
+
|