VIATEUR-AI commited on
Commit
c2c7b55
·
verified ·
1 Parent(s): f11f1b2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -25
app.py CHANGED
@@ -3,60 +3,74 @@ import gradio as gr
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:
19
- messages.append("Ubushyuhe buri hejuru cyane! Shyira system ku gipimo cyo kurwanya ubushyuhe.")
20
  else:
21
- messages.append("Ubushyuhe buri mu rugero rwiza.")
22
 
23
- # Igenzura umuvuduko (speed)
24
  if speed > 100:
25
- messages.append("Umuvuduko urenze, gabanya umuvuduko.")
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()
 
 
3
  # State yo kugenzura niba igikoresho kiri ON cyangwa OFF
4
  device_state = {"on": True}
5
 
6
+ def evaluate_sensors(voltage, temperature, speed):
7
  messages = []
8
 
9
+ # Voltage check
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
+ # Temperature check
18
  if temperature > 70:
19
+ messages.append("⚠️ Ubushyuhe buri hejuru cyane! Shyira system ku gipimo cyo kurwanya ubushyuhe.")
20
  else:
21
+ messages.append("Ubushyuhe buri mu rugero rwiza.")
22
 
23
+ # Speed check
24
  if speed > 100:
25
+ messages.append("⚠️ Umuvuduko urenze, gabanya umuvuduko.")
26
  else:
27
+ messages.append("Umuvuduko uri mu murongo mwiza.")
28
 
29
+ # Status y’igikoresho
30
  status = "ON" if device_state["on"] else "OFF"
31
+ messages.append(f"ℹ️ Status y'igikoresho: {status}")
32
 
33
  return "\n".join(messages)
34
 
35
  def turn_on():
36
  device_state["on"] = True
37
+ return "Igikoresho cyongeye gukurwa kuri OFF, kiri ON ubu."
38
 
39
  def turn_off():
40
  device_state["on"] = False
41
+ return "Igikoresho cyahagaze, kiri OFF ubu."
42
+
43
+ def check_status():
44
+ status = "ON" if device_state["on"] else "OFF"
45
+ return f"ℹ️ Status y'igikoresho: {status}"
46
 
47
  with gr.Blocks() as demo:
48
+ gr.Markdown("## Simulation y'Igenzura ry'Ibipimo Byinshi hamwe na Buttons zo Kugenzura Igikoresho")
49
+ voltage = gr.Slider(0, 5, step=0.1, label="Voltage (V)", value=2.0)
50
+ temperature = gr.Slider(0, 100, step=1, label="Ubushyuhe (°C)", value=25)
51
+ speed = gr.Slider(0, 200, step=1, label="Umuvuduko (km/h)", value=50)
52
 
53
+ output_text = gr.Textbox(label="Ibisubizo bya System", lines=8)
54
 
55
+ with gr.Row():
56
+ btn_on = gr.Button("Kuzimya OFF (ON)")
57
+ btn_off = gr.Button("Kuzimya (OFF)")
58
+ btn_check = gr.Button("Reba Status")
59
 
60
+ # Guhuza events
61
  btn_on.click(turn_on, outputs=output_text)
62
  btn_off.click(turn_off, outputs=output_text)
63
+ btn_check.click(check_status, outputs=output_text)
64
+
65
+ def on_change_all(v, t, s):
66
+ return evaluate_sensors(v, t, s)
67
 
68
+ voltage.change(on_change_all, inputs=[voltage, temperature, speed], outputs=output_text)
69
+ temperature.change(on_change_all, inputs=[voltage, temperature, speed], outputs=output_text)
70
+ speed.change(on_change_all, inputs=[voltage, temperature, speed], outputs=output_text)
71
+
72
+ # Initial display
73
+ output_text.value = evaluate_sensors(voltage.value, temperature.value, speed.value)
74
 
75
  demo.launch()
76
+