Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -11,6 +11,7 @@ import io
|
|
11 |
from PIL import Image
|
12 |
import plotly.graph_objects as go
|
13 |
from plotly.subplots import make_subplots
|
|
|
14 |
|
15 |
# OpenSky API URL
|
16 |
BASE_URL = "https://opensky-network.org/api"
|
@@ -216,7 +217,6 @@ custom_css = """
|
|
216 |
}
|
217 |
"""
|
218 |
|
219 |
-
# Gradio interface
|
220 |
with gr.Blocks(css=custom_css) as demo:
|
221 |
gr.HTML(
|
222 |
"""
|
@@ -233,7 +233,7 @@ with gr.Blocks(css=custom_css) as demo:
|
|
233 |
)
|
234 |
with gr.Column(scale=1):
|
235 |
refresh_btn = gr.Button("🔄 Refresh")
|
236 |
-
auto_refresh = gr.Checkbox(label="Auto Refresh
|
237 |
|
238 |
with gr.Row():
|
239 |
with gr.Column(scale=2):
|
@@ -247,6 +247,14 @@ with gr.Blocks(css=custom_css) as demo:
|
|
247 |
def update_map(region):
|
248 |
return create_map(region)
|
249 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
250 |
refresh_btn.click(
|
251 |
fn=update_map,
|
252 |
inputs=[region_select],
|
@@ -259,14 +267,14 @@ with gr.Blocks(css=custom_css) as demo:
|
|
259 |
outputs=[map_html, dashboard_plot, stats_text]
|
260 |
)
|
261 |
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
|
271 |
# Initial map load
|
272 |
map_html, dashboard_plot, stats_text = create_map("world")
|
|
|
11 |
from PIL import Image
|
12 |
import plotly.graph_objects as go
|
13 |
from plotly.subplots import make_subplots
|
14 |
+
import threading
|
15 |
|
16 |
# OpenSky API URL
|
17 |
BASE_URL = "https://opensky-network.org/api"
|
|
|
217 |
}
|
218 |
"""
|
219 |
|
|
|
220 |
with gr.Blocks(css=custom_css) as demo:
|
221 |
gr.HTML(
|
222 |
"""
|
|
|
233 |
)
|
234 |
with gr.Column(scale=1):
|
235 |
refresh_btn = gr.Button("🔄 Refresh")
|
236 |
+
auto_refresh = gr.Checkbox(label="Auto Refresh", value=False)
|
237 |
|
238 |
with gr.Row():
|
239 |
with gr.Column(scale=2):
|
|
|
247 |
def update_map(region):
|
248 |
return create_map(region)
|
249 |
|
250 |
+
def auto_refresh_function(auto_refresh_state):
|
251 |
+
while auto_refresh_state:
|
252 |
+
time.sleep(30) # 30초 대기
|
253 |
+
map_data, dashboard_data, stats_data = create_map(region_select.value)
|
254 |
+
map_html.update(value=map_data)
|
255 |
+
dashboard_plot.update(value=dashboard_data)
|
256 |
+
stats_text.update(value=stats_data)
|
257 |
+
|
258 |
refresh_btn.click(
|
259 |
fn=update_map,
|
260 |
inputs=[region_select],
|
|
|
267 |
outputs=[map_html, dashboard_plot, stats_text]
|
268 |
)
|
269 |
|
270 |
+
def handle_auto_refresh(auto_refresh_state):
|
271 |
+
if auto_refresh_state:
|
272 |
+
threading.Thread(target=auto_refresh_function, args=(True,), daemon=True).start()
|
273 |
+
|
274 |
+
auto_refresh.change(
|
275 |
+
fn=handle_auto_refresh,
|
276 |
+
inputs=[auto_refresh]
|
277 |
+
)
|
278 |
|
279 |
# Initial map load
|
280 |
map_html, dashboard_plot, stats_text = create_map("world")
|