Spaces:
Running
Running
Update app.py
Browse files
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 |
-
#
|
8 |
logging.basicConfig(level=logging.INFO)
|
9 |
|
10 |
css = """
|
11 |
footer { visibility: hidden; }
|
|
|
|
|
12 |
"""
|
13 |
|
14 |
-
#
|
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
|
20 |
-
return "
|
21 |
else:
|
22 |
-
logging.error(f"URL
|
23 |
-
return "
|
24 |
except requests.exceptions.RequestException as e:
|
25 |
-
logging.exception("
|
26 |
-
return "
|
27 |
|
28 |
-
#
|
29 |
def update_status():
|
30 |
while True:
|
31 |
-
status,
|
32 |
-
yield status
|
33 |
-
time.sleep(6) #
|
34 |
|
35 |
-
# Gradio
|
36 |
def create_dashboard():
|
37 |
with gr.Blocks(css=css) as app:
|
38 |
gr.Image("banner.png", show_label=False)
|
39 |
-
gr.Markdown("#
|
40 |
gr.Markdown("## \n")
|
41 |
-
gr.Markdown("###
|
42 |
gr.Markdown("## \n")
|
43 |
|
44 |
-
|
45 |
-
status_box = gr.Box(visible=False)
|
46 |
|
47 |
-
|
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()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|