bnews3 / app.py
seawolf2357's picture
Update app.py
cb65975 verified
raw
history blame
5.34 kB
import gradio as gr
import requests
import logging
import threading
import time
# λ‘œκΉ… μ„€μ •
logging.basicConfig(level=logging.INFO)
css = """
footer { visibility: hidden; }
.status-button {
display: inline-block;
padding: 5px 10px;
margin: 5px;
border-radius: 5px;
font-size: 12px;
}
.status-normal { background-color: green; color: white; }
.status-abnormal { background-color: red; color: white; }
"""
# λͺ¨λ‹ˆν„°λ§ λŒ€μƒ λͺ©λ‘
TARGETS = [
{"name": "[GINI/DS]ν…ŒμŠ€νŠΈ", "url": "http://hugpu.ai:8888"},
{"name": "[OFAI/DS]ν…ŒμŠ€νŠΈ", "url": "http://hugpu.ai:8888"},
{"name": "[HF]ν…ŒμŠ€νŠΈ", "url": "http://hugpu.ai:8888"},
{"name": "[H100]AI κ°œμΈλΉ„μ„œ JinJAVIS", "url": "http://hugpu.ai:8000"},
{"name": "[HUGPU]FLUX ν™•μž₯ 이미지 생성", "url": "https://fantaxy-ofai-flx-expl-store.hf.space"},
{"name": "[HUGPU]FLUX GIF 생성", "url": "https://.hf.space"},
{"name": "[HUGPU] ", "url": "https://.hf.space"},
{"name": "[HUGPU] ", "url": "https://.hf.space"},
{"name": "[HUGPU] ", "url": "https://.hf.space"},
{"name": "[HUGPU] ", "url": "https://.hf.space"},
{"name": "[HUGPU] ", "url": "https://.hf.space"},
{"name": "[HUGPU] ", "url": "https://.hf.space"},
{"name": "[HUGPU] ", "url": "https://.hf.space"},
{"name": "[HUGPU] ", "url": "https://.hf.space"},
{"name": "[HUGPU] ", "url": "https://.hf.space"},
{"name": "[HUGPU] ", "url": "https://.hf.space"},
{"name": "[HUGPU] ", "url": "https://.hf.space"},
{"name": "[HUGPU] ", "url": "https://.hf.space"},
{"name": "[HUGPU] ", "url": "https://.hf.space"},
{"name": "[HUGPU] ", "url": "https://.hf.space"},
{"name": "[HUGPU] ", "url": "https://.hf.space"},
{"name": "[HUGPU] ", "url": "https://.hf.space"},
{"name": "[HUGPU] ", "url": "https://.hf.space"},
{"name": "[HUGPU] ", "url": "https://.hf.space"},
{"name": "[HUGPU] ", "url": "https://.hf.space"},
{"name": "[HUGPU] ", "url": "https://.hf.space"},
{"name": "[HUGPU] ", "url": "https://.hf.space"},
{"name": "[HUGPU] ", "url": "https://.hf.space"},
{"name": "[HUGPU] ", "url": "https://.hf.space"},
{"name": "[HUGPU] ", "url": "https://.hf.space"},
{"name": "[HUGPU] ", "url": "https://.hf.space"},
{"name": "[HUGPU] ", "url": "https://.hf.space"},
{"name": "[HUGPU] ", "url": "https://.hf.space"},
{"name": "[HUGPU] ", "url": "https://.hf.space"},
{"name": "[HUGPU] ", "url": "https://.hf.space"},
{"name": "[HUGPU] ", "url": "https://.hf.space"},
{"name": "[HUGPU] ", "url": "https://.hf.space"},
{"name": "[HUGPU] ", "url": "https://.hf.space"},
{"name": "[HUGPU] ", "url": "https://.hf.space"},
{"name": "[HUGPU] ", "url": "https://.hf.space"},
{"name": "[HUGPU] ", "url": "https://.hf.space"},
{"name": "[HUGPU] ", "url": "https://.hf.space"},
{"name": "[HUGPU] ", "url": "https://.hf.space"},
{"name": "[HUGPU] ", "url": "https://.hf.space"},
{"name": "[HUGPU] ", "url": "https://.hf.space"},
{"name": "[HUGPU] ", "url": "https://.hf.space"},
{"name": "[HUGPU] ", "url": "https://.hf.space"},
{"name": "[HUGPU] ", "url": "https://.hf.space"},
{"name": "[HUGPU] ", "url": "https://.hf.space"},
{"name": "[HUGPU] ", "url": "https://.hf.space"},
]
# URL μƒνƒœ 확인 ν•¨μˆ˜
def check_url_status(url):
try:
response = requests.get(url, timeout=5)
if response.status_code == 200:
logging.info(f"URL 접속 성곡: {url}")
return "정상", "normal"
else:
logging.error(f"URL 접속 였λ₯˜: {url}, μƒνƒœ μ½”λ“œ {response.status_code}")
return "비정상", "abnormal"
except requests.exceptions.RequestException as e:
logging.exception(f"μ„œλ²„μ— μ—°κ²°ν•  수 μ—†μŠ΅λ‹ˆλ‹€: {url}")
return "비정상", "abnormal"
# μƒνƒœ μ—…λ°μ΄νŠΈ ν•¨μˆ˜
def update_status():
status_html = ""
for target in TARGETS:
status, status_class = check_url_status(target["url"])
status_html += f'<span class="status-button status-{status_class}">{target["name"]}: {status}</span>'
return status_html
# 주기적 μ—…λ°μ΄νŠΈλ₯Ό μœ„ν•œ ν•¨μˆ˜
def periodic_update(status_html):
while True:
time.sleep(10) # 10초 λŒ€κΈ°
new_status = update_status()
status_html.update(value=new_status)
# Gradio μΈν„°νŽ˜μ΄μŠ€ μ„€μ •
def create_dashboard():
with gr.Blocks(css=css) as app:
gr.Image("banner.png", show_label=False)
gr.Markdown("# 24μ‹œκ°„ λͺ¨λ‹ˆν„°λ§ μ‹œμŠ€ν…œ")
gr.Markdown("## \n")
status_html = gr.HTML()
refresh_button = gr.Button("μƒνƒœ μƒˆλ‘œκ³ μΉ¨")
refresh_button.click(fn=update_status, outputs=status_html)
# 초기 μƒνƒœ μ—…λ°μ΄νŠΈ
app.load(fn=update_status, outputs=status_html)
# λ°±κ·ΈλΌμš΄λ“œμ—μ„œ 주기적 μ—…λ°μ΄νŠΈ μ‹œμž‘
threading.Thread(target=periodic_update, args=(status_html,), daemon=True).start()
return app
if __name__ == "__main__":
dashboard = create_dashboard()
dashboard.launch()