Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| # State yo kugenzura niba igikoresho kiri ON cyangwa OFF | |
| device_state = {"on": True} | |
| def evaluate_sensors(voltage, temperature, speed): | |
| messages = [] | |
| # Voltage check | |
| if voltage > 2.5: | |
| messages.append("⚠️ Umuriro urenze, turazimya igikoresho (OFF).") | |
| device_state["on"] = False | |
| else: | |
| messages.append("✅ Umuriro uri hasi, igikoresho kiri ON.") | |
| device_state["on"] = True | |
| # Temperature check | |
| if temperature > 70: | |
| messages.append("⚠️ Ubushyuhe buri hejuru cyane! Shyira system ku gipimo cyo kurwanya ubushyuhe.") | |
| else: | |
| messages.append("✅ Ubushyuhe buri mu rugero rwiza.") | |
| # Speed check | |
| if speed > 100: | |
| messages.append("⚠️ Umuvuduko urenze, gabanya umuvuduko.") | |
| else: | |
| messages.append("✅ Umuvuduko uri mu murongo mwiza.") | |
| # Status y’igikoresho | |
| status = "ON" if device_state["on"] else "OFF" | |
| messages.append(f"ℹ️ Status y'igikoresho: {status}") | |
| return "\n".join(messages) | |
| def turn_on(): | |
| device_state["on"] = True | |
| return "✅ Igikoresho cyongeye gukurwa kuri OFF, kiri ON ubu." | |
| def turn_off(): | |
| device_state["on"] = False | |
| return "❌ Igikoresho cyahagaze, kiri OFF ubu." | |
| def check_status(): | |
| status = "ON" if device_state["on"] else "OFF" | |
| return f"ℹ️ Status y'igikoresho: {status}" | |
| with gr.Blocks() as demo: | |
| gr.Markdown("## Simulation y'Igenzura ry'Ibipimo Byinshi hamwe na Buttons zo Kugenzura Igikoresho") | |
| voltage = gr.Slider(0, 5, step=0.1, label="Voltage (V)", value=2.0) | |
| temperature = gr.Slider(0, 100, step=1, label="Ubushyuhe (°C)", value=25) | |
| speed = gr.Slider(0, 200, step=1, label="Umuvuduko (km/h)", value=50) | |
| output_text = gr.Textbox(label="Ibisubizo bya System", lines=8) | |
| with gr.Row(): | |
| btn_on = gr.Button("Kuzimya OFF (ON)") | |
| btn_off = gr.Button("Kuzimya (OFF)") | |
| btn_check = gr.Button("Reba Status") | |
| # Guhuza events | |
| btn_on.click(turn_on, outputs=output_text) | |
| btn_off.click(turn_off, outputs=output_text) | |
| btn_check.click(check_status, outputs=output_text) | |
| def on_change_all(v, t, s): | |
| return evaluate_sensors(v, t, s) | |
| voltage.change(on_change_all, inputs=[voltage, temperature, speed], outputs=output_text) | |
| temperature.change(on_change_all, inputs=[voltage, temperature, speed], outputs=output_text) | |
| speed.change(on_change_all, inputs=[voltage, temperature, speed], outputs=output_text) | |
| # Initial display | |
| output_text.value = evaluate_sensors(voltage.value, temperature.value, speed.value) | |
| demo.launch() | |