Business / app.py
VIATEUR-AI's picture
Create app.py
96577b8 verified
import gradio as gr
# STORAGE
employees = []
products = []
sales = []
# FUNCTIONS
def add_employee(name, role):
employees.append({"name": name, "role": role})
return show_all()
def add_product(name, price, qty):
products.append({"name": name, "price": float(price), "qty": int(qty)})
return show_all()
def add_sale(product_name, qty):
qty = int(qty)
for p in products:
if p["name"] == product_name:
if p["qty"] >= qty:
p["qty"] -= qty
total = qty * p["price"]
sales.append({"name": product_name, "qty": qty, "total": total})
return show_all()
else:
return "Stock ntihagije", show_all()
return "Product ntibashije kuboneka", show_all()
def show_all():
emp_table = "\n".join([f'{e["name"]} - {e["role"]}' for e in employees]) or "No employees"
prod_table = "\n".join([f'{p["name"]} | {p["price"]} | {p["qty"]}' for p in products]) or "No products"
sale_table = "\n".join([f'{s["name"]} | {s["qty"]} | {s["total"]}' for s in sales]) or "No sales"
total_sales = sum(s["total"] for s in sales)
dashboard = f"""
EMPLOYEES: {len(employees)}
PRODUCTS: {len(products)}
TOTAL SALES: {total_sales}
"""
return dashboard, emp_table, prod_table, sale_table
# UI
with gr.Blocks() as app:
gr.Markdown("# 🏢 COMPANY ERP SYSTEM (Gradio + HF)")
dashboard = gr.Textbox(label="Dashboard")
with gr.Tab("Employees"):
name = gr.Textbox(label="Name")
role = gr.Textbox(label="Role")
btn = gr.Button("Add Employee")
with gr.Tab("Products"):
pname = gr.Textbox(label="Product Name")
price = gr.Textbox(label="Price")
qty = gr.Textbox(label="Quantity")
btn2 = gr.Button("Add Product")
with gr.Tab("Sales"):
sname = gr.Textbox(label="Product Name")
sqty = gr.Textbox(label="Quantity")
btn3 = gr.Button("Sell Product")
emp_table = gr.Textbox(label="Employees")
prod_table = gr.Textbox(label="Products")
sale_table = gr.Textbox(label="Sales")
btn.click(add_employee, inputs=[name, role],
outputs=[dashboard, emp_table, prod_table, sale_table])
btn2.click(add_product, inputs=[pname, price, qty],
outputs=[dashboard, emp_table, prod_table, sale_table])
btn3.click(add_sale, inputs=[sname, sqty],
outputs=[dashboard, emp_table, prod_table, sale_table])
app.load(show_all, outputs=[dashboard, emp_table, prod_table, sale_table])
app.launch()