seawolf2357 commited on
Commit
09a7d59
Β·
verified Β·
1 Parent(s): 92f15ad

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -15
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 # '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 # 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 "비정상", "abnormal"
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
- status_html.update(value=new_status)
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