Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,13 +1,18 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
|
|
|
|
|
|
|
|
|
|
| 3 |
def multi_sensor_control(voltage, temperature, speed):
|
| 4 |
messages = []
|
| 5 |
|
| 6 |
# Igenzura voltage
|
| 7 |
if voltage > 2.5:
|
| 8 |
messages.append("Umuriro urenze, turazimya igikoresho (OFF)")
|
|
|
|
| 9 |
else:
|
| 10 |
messages.append("Umuriro uri hasi, igikoresho kiri ON")
|
|
|
|
| 11 |
|
| 12 |
# Igenzura ubushyuhe
|
| 13 |
if temperature > 70:
|
|
@@ -21,18 +26,37 @@ def multi_sensor_control(voltage, temperature, speed):
|
|
| 21 |
else:
|
| 22 |
messages.append("Umuvuduko uri mu murongo mwiza.")
|
| 23 |
|
|
|
|
|
|
|
|
|
|
| 24 |
return "\n".join(messages)
|
| 25 |
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
|
| 38 |
-
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
+
# State yo kugenzura niba igikoresho kiri ON cyangwa OFF
|
| 4 |
+
device_state = {"on": True}
|
| 5 |
+
|
| 6 |
def multi_sensor_control(voltage, temperature, speed):
|
| 7 |
messages = []
|
| 8 |
|
| 9 |
# Igenzura voltage
|
| 10 |
if voltage > 2.5:
|
| 11 |
messages.append("Umuriro urenze, turazimya igikoresho (OFF)")
|
| 12 |
+
device_state["on"] = False
|
| 13 |
else:
|
| 14 |
messages.append("Umuriro uri hasi, igikoresho kiri ON")
|
| 15 |
+
device_state["on"] = True
|
| 16 |
|
| 17 |
# Igenzura ubushyuhe
|
| 18 |
if temperature > 70:
|
|
|
|
| 26 |
else:
|
| 27 |
messages.append("Umuvuduko uri mu murongo mwiza.")
|
| 28 |
|
| 29 |
+
status = "ON" if device_state["on"] else "OFF"
|
| 30 |
+
messages.append(f"Status y'igikoresho: {status}")
|
| 31 |
+
|
| 32 |
return "\n".join(messages)
|
| 33 |
|
| 34 |
+
def turn_on():
|
| 35 |
+
device_state["on"] = True
|
| 36 |
+
return "Igikoresho cyongeye gukurwa kuri OFF, kiri ON ubu."
|
| 37 |
+
|
| 38 |
+
def turn_off():
|
| 39 |
+
device_state["on"] = False
|
| 40 |
+
return "Igikoresho cyahagaze, kiri OFF ubu."
|
| 41 |
+
|
| 42 |
+
with gr.Blocks() as demo:
|
| 43 |
+
voltage = gr.Slider(0, 5, step=0.1, label="Voltage (V)")
|
| 44 |
+
temperature = gr.Slider(0, 100, step=1, label="Ubushyuhe (°C)")
|
| 45 |
+
speed = gr.Slider(0, 200, step=1, label="Umuvuduko (km/h)")
|
| 46 |
+
|
| 47 |
+
output_text = gr.Textbox(label="Ibisubizo", lines=6)
|
| 48 |
+
|
| 49 |
+
btn_on = gr.Button("Kuzimya OFF (ON)")
|
| 50 |
+
btn_off = gr.Button("Kuzimya (OFF)")
|
| 51 |
+
btn_check = gr.Button("Reba Status")
|
| 52 |
+
|
| 53 |
+
btn_on.click(turn_on, outputs=output_text)
|
| 54 |
+
btn_off.click(turn_off, outputs=output_text)
|
| 55 |
+
btn_check.click(lambda: f"Status y'igikoresho: {'ON' if device_state['on'] else 'OFF'}", outputs=output_text)
|
| 56 |
+
|
| 57 |
+
# Reba ibisubizo uko bipimwa
|
| 58 |
+
voltage.change(lambda v, t, s: multi_sensor_control(v, t, s), inputs=[voltage, temperature, speed], outputs=output_text)
|
| 59 |
+
temperature.change(lambda v, t, s: multi_sensor_control(v, t, s), inputs=[voltage, temperature, speed], outputs=output_text)
|
| 60 |
+
speed.change(lambda v, t, s: multi_sensor_control(v, t, s), inputs=[voltage, temperature, speed], outputs=output_text)
|
| 61 |
|
| 62 |
+
demo.launch()
|