seawolf2357 commited on
Commit
db7d3b2
·
verified ·
1 Parent(s): 2877b2d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -40
app.py CHANGED
@@ -1,73 +1,53 @@
1
  import gradio as gr
2
  import requests
3
  import logging
4
- import threading
5
  import time
6
 
7
- # Logging setup
8
  logging.basicConfig(level=logging.INFO)
9
 
10
  css = """
11
  footer { visibility: hidden; }
 
 
12
  """
13
 
14
- # Function to check the status of a URL
15
  def check_url_status():
16
  try:
17
  response = requests.get("http://hugpu.ai:8000")
18
  if response.status_code == 200:
19
- logging.info("URL access successful: Status code 200")
20
- return "Normal", "green"
21
  else:
22
- logging.error(f"URL access error: Status code {response.status_code}")
23
- return "Abnormal", "red"
24
  except requests.exceptions.RequestException as e:
25
- logging.exception("Unable to connect to the server.")
26
- return "Abnormal", "red"
27
 
28
- # Function to update status
29
  def update_status():
30
  while True:
31
- status, color = check_url_status()
32
- yield status, color
33
- time.sleep(6) # Wait for 6 seconds
34
 
35
- # Gradio interface setup
36
  def create_dashboard():
37
  with gr.Blocks(css=css) as app:
38
  gr.Image("banner.png", show_label=False)
39
- gr.Markdown("# 24x7 Monitoring System")
40
  gr.Markdown("## \n")
41
- gr.Markdown("### Home description: [Link](https://seawolf2357-bnews1.hf.space)")
42
  gr.Markdown("## \n")
43
 
44
- status_label = gr.Textbox(label="AI Personal Assistant Status:", value="Loading...")
45
- status_box = gr.Box(visible=False)
46
 
47
- def update_ui(status, color):
48
- return gr.Textbox.update(value=f"AI Personal Assistant Status: {status}"), gr.Box.update(visible=True, elem_id=f"status-{color.lower()}")
49
-
50
- gr.Loop(update_status, outputs=[status_label, status_box], every=6, callback=update_ui)
51
 
52
  return app
53
 
54
  if __name__ == "__main__":
55
  dashboard = create_dashboard()
56
- dashboard.launch()
57
-
58
- # Add this CSS to your Gradio interface or in a separate CSS file
59
- custom_css = """
60
- #status-green {
61
- background-color: green;
62
- color: white;
63
- padding: 10px;
64
- border-radius: 5px;
65
- }
66
-
67
- #status-red {
68
- background-color: red;
69
- color: white;
70
- padding: 10px;
71
- border-radius: 5px;
72
- }
73
- """
 
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
  while True:
32
+ status, status_class = check_url_status()
33
+ yield f"<div class='status-{status_class}'>AI 개인 비서 상태: {status}</div>"
34
+ time.sleep(6) # 6 대기
35
 
36
+ # Gradio 인터페이스 설정
37
  def create_dashboard():
38
  with gr.Blocks(css=css) as app:
39
  gr.Image("banner.png", show_label=False)
40
+ gr.Markdown("# 24시간 모니터링 시스템")
41
  gr.Markdown("## \n")
42
+ gr.Markdown("### 설명: [링크](https://seawolf2357-bnews1.hf.space)")
43
  gr.Markdown("## \n")
44
 
45
+ status_html = gr.HTML("AI 개인 비서 상태: 로딩 중...")
 
46
 
47
+ gr.Loop(update_status, outputs=status_html, every=6)
 
 
 
48
 
49
  return app
50
 
51
  if __name__ == "__main__":
52
  dashboard = create_dashboard()
53
+ dashboard.launch()