Update app.py
Browse files
app.py
CHANGED
|
@@ -1,65 +1,21 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import json
|
| 3 |
|
| 4 |
-
# Sample
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 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 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 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 |
|
|
|