Spaces:
Sleeping
Sleeping
File size: 2,654 Bytes
6ffed44 f11f1b2 c2c7b55 f2c9d5c c2c7b55 f2c9d5c c2c7b55 f11f1b2 f2c9d5c c2c7b55 f11f1b2 f2c9d5c c2c7b55 f2c9d5c c2c7b55 f2c9d5c c2c7b55 f2c9d5c c2c7b55 f2c9d5c c2c7b55 f2c9d5c c2c7b55 f2c9d5c c2c7b55 f11f1b2 c2c7b55 f11f1b2 f2c9d5c f11f1b2 c2c7b55 f11f1b2 c2c7b55 f11f1b2 c2c7b55 f11f1b2 c2c7b55 f11f1b2 c2c7b55 f11f1b2 c2c7b55 f11f1b2 c2c7b55 f11f1b2 c2c7b55 6ffed44 f11f1b2 c2c7b55 |
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 73 74 75 76 77 |
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()
|