Spaces:
Running
Running
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() |