Seunggg commited on
Commit
3550141
·
verified ·
1 Parent(s): 2f8f8ca

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -8
app.py CHANGED
@@ -72,17 +72,14 @@ def respond(user_input):
72
  # Gradio 界面
73
  with gr.Blocks() as demo:
74
  with gr.Row():
75
- sensor_box = gr.Textbox(label="🧪 当前传感器数据", lines=6, interactive=False)
76
  question_box = gr.Textbox(label="🌿 植物问题", lines=4)
77
  answer_box = gr.Textbox(label="🤖 回答建议", lines=8, interactive=False)
78
 
79
- # 用户提交提问后,更新传感器+回答
80
  question_box.submit(fn=respond, inputs=question_box, outputs=[sensor_box, answer_box])
81
 
82
- # 定时每 5 秒自动刷新传感器数据
83
- def update_sensor():
84
- return get_sensor_data()
85
 
86
- gr.Timer(period=5, fn=update_sensor, outputs=sensor_box)
87
-
88
- demo.launch()
 
72
  # Gradio 界面
73
  with gr.Blocks() as demo:
74
  with gr.Row():
75
+ sensor_box = gr.Textbox(label="🧪 当前传感器数据", lines=6, interactive=False, value=get_sensor_data(), live=True)
76
  question_box = gr.Textbox(label="🌿 植物问题", lines=4)
77
  answer_box = gr.Textbox(label="🤖 回答建议", lines=8, interactive=False)
78
 
79
+ # 用户提交后生成回答
80
  question_box.submit(fn=respond, inputs=question_box, outputs=[sensor_box, answer_box])
81
 
82
+ # 5 秒自动更新传感器数据
83
+ sensor_box.change(fn=show_sensor_data, inputs=None, outputs=sensor_box).every(5)
 
84
 
85
+ demo.launch()