File size: 2,650 Bytes
b63cae7
 
428e575
 
b63cae7
428e575
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b63cae7
428e575
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b63cae7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import gradio as gr

# Ibyo dushaka kugenzura: power output (kW) n'ibikoresho bikoresha power
# Turi gutegura loads 3: amatara, firigo, televiziyo

def energy_management(power_output, light_load, fridge_load, tv_load):
    total_load = light_load + fridge_load + tv_load
    messages = []
    
    messages.append(f"πŸ”Œ Power output available: {power_output} kW")
    messages.append(f"πŸ’‘ Total load demand: {total_load} kW")
    
    if power_output >= total_load:
        surplus = power_output - total_load
        messages.append(f"βœ… Power is sufficient. Surplus: {surplus:.2f} kW")
        messages.append("πŸ”‹ Amashanyarazi asigaye ashobora kubikwa cyangwa gukoreshwa mu bindi bikoresho.")
    else:
        deficit = total_load - power_output
        messages.append(f"⚠️ Power deficit! Kurwanya deficit: {deficit:.2f} kW")
        # Gukata load zidakenewe
        # Tugena priority: Firigo > TV > Lights
        load_status = {}
        remaining_power = power_output
        
        # Firigo ifite priority ya mbere
        if fridge_load <= remaining_power:
            load_status["Fridge"] = "ON"
            remaining_power -= fridge_load
        else:
            load_status["Fridge"] = "OFF"
        
        # TV ifite priority ya kabiri
        if tv_load <= remaining_power:
            load_status["TV"] = "ON"
            remaining_power -= tv_load
        else:
            load_status["TV"] = "OFF"
        
        # Lights ifite priority ya nyuma
        if light_load <= remaining_power:
            load_status["Lights"] = "ON"
            remaining_power -= light_load
        else:
            load_status["Lights"] = "OFF"
        
        messages.append("πŸ“‰ Ibyuma byakozweho:")
        for device, status in load_status.items():
            messages.append(f" - {device}: {status}")
    
    return "\n".join(messages)

with gr.Blocks() as demo:
    gr.Markdown("## Energy Management System Simulation")
    
    power_output = gr.Slider(0, 10, step=0.1, label="Power Output (kW)", value=5)
    
    light_load = gr.Slider(0, 5, step=0.1, label="Lights Load (kW)", value=1)
    fridge_load = gr.Slider(0, 5, step=0.1, label="Fridge Load (kW)", value=2)
    tv_load = gr.Slider(0, 5, step=0.1, label="TV Load (kW)", value=1)
    
    output = gr.Textbox(label="System Report", lines=12)
    
    inputs = [power_output, light_load, fridge_load, tv_load]
    for inp in inputs:
        inp.change(fn=energy_management, inputs=inputs, outputs=output)
    
    # Report ya mbere
    output.value = energy_management(power_output.value, light_load.value, fridge_load.value, tv_load.value)
    
demo.launch()