seawolf2357 commited on
Commit
67c9619
·
verified ·
1 Parent(s): 03fea9e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -11
app.py CHANGED
@@ -1,35 +1,50 @@
1
  import gradio as gr
2
  import requests
3
  import logging
4
- import time
5
 
6
  # 로깅 설정
7
  logging.basicConfig(level=logging.INFO)
8
 
9
  css = """
10
  footer { visibility: hidden; }
11
- .status-normal { background-color: green; color: white; padding: 10px; border-radius: 5px; }
12
- .status-abnormal { background-color: red; color: white; padding: 10px; border-radius: 5px; }
 
 
 
 
 
 
 
13
  """
14
 
 
 
 
 
 
 
15
  # URL 상태 확인 함수
16
- def check_url_status():
17
  try:
18
- response = requests.get("http://hugpu.ai:8000")
19
  if response.status_code == 200:
20
- logging.info("URL 접속 성공: 상태 코드 200")
21
  return "정상", "normal"
22
  else:
23
- logging.error(f"URL 접속 오류: 상태 코드 {response.status_code}")
24
  return "비정상", "abnormal"
25
  except requests.exceptions.RequestException as e:
26
- logging.exception("서버에 연결할 수 없습니다.")
27
  return "비정상", "abnormal"
28
 
29
  # 상태 업데이트 함수
30
  def update_status():
31
- status, status_class = check_url_status()
32
- return f"<div class='status-{status_class}'>AI 개인 비서 상태: {status}</div>"
 
 
 
33
 
34
  # Gradio 인터페이스 설정
35
  def create_dashboard():
@@ -40,7 +55,7 @@ def create_dashboard():
40
  gr.Markdown("### 홈 설명: [링크](https://seawolf2357-bnews1.hf.space)")
41
  gr.Markdown("## \n")
42
 
43
- status_html = gr.HTML("AI 개인 비서 상태: 로딩 중...")
44
 
45
  refresh_button = gr.Button("상태 새로고침")
46
  refresh_button.click(fn=update_status, outputs=status_html)
 
1
  import gradio as gr
2
  import requests
3
  import logging
 
4
 
5
  # 로깅 설정
6
  logging.basicConfig(level=logging.INFO)
7
 
8
  css = """
9
  footer { visibility: hidden; }
10
+ .status-button {
11
+ display: inline-block;
12
+ padding: 5px 10px;
13
+ margin: 5px;
14
+ border-radius: 5px;
15
+ font-size: 12px;
16
+ }
17
+ .status-normal { background-color: green; color: white; }
18
+ .status-abnormal { background-color: red; color: white; }
19
  """
20
 
21
+ # 모니터링 대상 목록
22
+ TARGETS = [
23
+ {"name": "AI 개인 비서", "url": "http://hugpu.ai:8000"},
24
+ {"name": "A4D1: 미디움 블로그", "url": "http://hugpu.ai:7917"},
25
+ ]
26
+
27
  # URL 상태 확인 함수
28
+ def check_url_status(url):
29
  try:
30
+ response = requests.get(url, timeout=5)
31
  if response.status_code == 200:
32
+ logging.info(f"URL 접속 성공: {url}")
33
  return "정상", "normal"
34
  else:
35
+ logging.error(f"URL 접속 오류: {url}, 상태 코드 {response.status_code}")
36
  return "비정상", "abnormal"
37
  except requests.exceptions.RequestException as e:
38
+ logging.exception(f"서버에 연결할 수 없습니다: {url}")
39
  return "비정상", "abnormal"
40
 
41
  # 상태 업데이트 함수
42
  def update_status():
43
+ status_html = ""
44
+ for target in TARGETS:
45
+ status, status_class = check_url_status(target["url"])
46
+ status_html += f'<span class="status-button status-{status_class}">{target["name"]}: {status}</span>'
47
+ return status_html
48
 
49
  # Gradio 인터페이스 설정
50
  def create_dashboard():
 
55
  gr.Markdown("### 홈 설명: [링크](https://seawolf2357-bnews1.hf.space)")
56
  gr.Markdown("## \n")
57
 
58
+ status_html = gr.HTML()
59
 
60
  refresh_button = gr.Button("상태 새로고침")
61
  refresh_button.click(fn=update_status, outputs=status_html)