Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -4,9 +4,8 @@ import logging
|
|
4 |
import threading
|
5 |
import time
|
6 |
from pydantic import BaseModel
|
7 |
-
from typing import Any
|
8 |
|
9 |
-
# λ‘κΉ
μ€μ
|
10 |
logging.basicConfig(level=logging.INFO)
|
11 |
|
12 |
css = """
|
@@ -18,6 +17,8 @@ footer { visibility: hidden; }
|
|
18 |
border-radius: 5px;
|
19 |
font-size: 12px;
|
20 |
}
|
|
|
|
|
21 |
"""
|
22 |
|
23 |
# λͺ¨λν°λ§ λμ λͺ©λ‘
|
@@ -104,13 +105,16 @@ TARGETS = [
|
|
104 |
|
105 |
]
|
106 |
|
|
|
|
|
|
|
|
|
107 |
class MyModel(BaseModel):
|
108 |
-
request: Any
|
109 |
|
110 |
class Config:
|
111 |
arbitrary_types_allowed = True
|
112 |
|
113 |
-
# URL μν νμΈ ν¨μ
|
114 |
def check_url_status(url):
|
115 |
try:
|
116 |
response = requests.get(url, timeout=5)
|
@@ -119,12 +123,11 @@ def check_url_status(url):
|
|
119 |
return "μ μ", "normal"
|
120 |
else:
|
121 |
logging.error(f"URL μ μ μ€λ₯: {url}, μν μ½λ {response.status_code}")
|
122 |
-
return "λΉμ μ", "abnormal"
|
123 |
except requests.exceptions.RequestException as e:
|
124 |
logging.exception(f"μλ²μ μ°κ²°ν μ μμ΅λλ€: {url}")
|
125 |
-
return "
|
126 |
|
127 |
-
# μν μ
λ°μ΄νΈ ν¨μ
|
128 |
def update_status():
|
129 |
status_html = ""
|
130 |
for target in TARGETS:
|
@@ -132,14 +135,12 @@ def update_status():
|
|
132 |
status_html += f'<span class="status-button status-{status_class}">{target["name"]}: {status}</span>'
|
133 |
return status_html
|
134 |
|
135 |
-
|
136 |
-
def periodic_update(status_html):
|
137 |
while True:
|
138 |
time.sleep(60) # 60μ΄ λκΈ°
|
139 |
new_status = update_status()
|
140 |
-
|
141 |
|
142 |
-
# Gradio μΈν°νμ΄μ€ μ€μ
|
143 |
def create_dashboard():
|
144 |
with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css) as app:
|
145 |
gr.Image("banner.png", show_label=False)
|
@@ -151,11 +152,9 @@ def create_dashboard():
|
|
151 |
refresh_button = gr.Button("μν μλ‘κ³ μΉ¨")
|
152 |
refresh_button.click(fn=update_status, outputs=status_html)
|
153 |
|
154 |
-
# μ΄κΈ° μν μ
λ°μ΄νΈ
|
155 |
app.load(fn=update_status, outputs=status_html)
|
156 |
-
|
157 |
-
|
158 |
-
threading.Thread(target=periodic_update, args=(status_html,), daemon=True).start()
|
159 |
|
160 |
return app
|
161 |
|
|
|
4 |
import threading
|
5 |
import time
|
6 |
from pydantic import BaseModel
|
7 |
+
from typing import Any
|
8 |
|
|
|
9 |
logging.basicConfig(level=logging.INFO)
|
10 |
|
11 |
css = """
|
|
|
17 |
border-radius: 5px;
|
18 |
font-size: 12px;
|
19 |
}
|
20 |
+
.status-normal { background-color: #90EE90; }
|
21 |
+
.status-abnormal { background-color: #FFA07A; }
|
22 |
"""
|
23 |
|
24 |
# λͺ¨λν°λ§ λμ λͺ©λ‘
|
|
|
105 |
|
106 |
]
|
107 |
|
108 |
+
|
109 |
+
|
110 |
+
|
111 |
+
|
112 |
class MyModel(BaseModel):
|
113 |
+
request: Any
|
114 |
|
115 |
class Config:
|
116 |
arbitrary_types_allowed = True
|
117 |
|
|
|
118 |
def check_url_status(url):
|
119 |
try:
|
120 |
response = requests.get(url, timeout=5)
|
|
|
123 |
return "μ μ", "normal"
|
124 |
else:
|
125 |
logging.error(f"URL μ μ μ€λ₯: {url}, μν μ½λ {response.status_code}")
|
126 |
+
return f"λΉμ μ (μ½λ: {response.status_code})", "abnormal"
|
127 |
except requests.exceptions.RequestException as e:
|
128 |
logging.exception(f"μλ²μ μ°κ²°ν μ μμ΅λλ€: {url}")
|
129 |
+
return "μ°κ²° λΆκ°", "abnormal"
|
130 |
|
|
|
131 |
def update_status():
|
132 |
status_html = ""
|
133 |
for target in TARGETS:
|
|
|
135 |
status_html += f'<span class="status-button status-{status_class}">{target["name"]}: {status}</span>'
|
136 |
return status_html
|
137 |
|
138 |
+
def periodic_update():
|
|
|
139 |
while True:
|
140 |
time.sleep(60) # 60μ΄ λκΈ°
|
141 |
new_status = update_status()
|
142 |
+
gr.update(value=new_status)
|
143 |
|
|
|
144 |
def create_dashboard():
|
145 |
with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css) as app:
|
146 |
gr.Image("banner.png", show_label=False)
|
|
|
152 |
refresh_button = gr.Button("μν μλ‘κ³ μΉ¨")
|
153 |
refresh_button.click(fn=update_status, outputs=status_html)
|
154 |
|
|
|
155 |
app.load(fn=update_status, outputs=status_html)
|
156 |
+
|
157 |
+
threading.Thread(target=periodic_update, daemon=True).start()
|
|
|
158 |
|
159 |
return app
|
160 |
|