Files changed (1) hide show
  1. app.py +41 -0
app.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+
3
+ def calculate_bill(name, units):
4
+ units = float(units)
5
+
6
+ if units <= 100:
7
+ energy_charge = units * 5
8
+ elif units <= 200:
9
+ energy_charge = (100 * 5) + ((units - 100) * 7)
10
+ elif units <= 300:
11
+ energy_charge = (100 * 5) + (100 * 7) + ((units - 200) * 10)
12
+ else:
13
+ energy_charge = (100 * 5) + (100 * 7) + (100 * 10) + ((units - 300) * 12)
14
+
15
+ fixed_charge = 100
16
+ total_bill = energy_charge + fixed_charge
17
+
18
+ return f"""
19
+ Customer Name : {name}
20
+
21
+ Units Consumed : {units}
22
+
23
+ Energy Charge : ₹{energy_charge:.2f}
24
+
25
+ Fixed Charge : ₹{fixed_charge:.2f}
26
+
27
+ Total Bill : ₹{total_bill:.2f}
28
+ """
29
+
30
+ demo = gr.Interface(
31
+ fn=calculate_bill,
32
+ inputs=[
33
+ gr.Textbox(label="Customer Name"),
34
+ gr.Number(label="Units Consumed (kWh)")
35
+ ],
36
+ outputs=gr.Textbox(label="Electricity Bill"),
37
+ title="Electricity Bill Calculator",
38
+ description="Calculate the electricity bill based on slab rates."
39
+ )
40
+
41
+ demo.launch()