Spaces:
Running
Running
import gradio as gr | |
import requests | |
import logging | |
import time | |
# λ‘κΉ μ€μ | |
logging.basicConfig(level=logging.INFO) | |
css = """ | |
footer { visibility: hidden; } | |
.status-normal { background-color: green; color: white; padding: 10px; border-radius: 5px; } | |
.status-abnormal { background-color: red; color: white; padding: 10px; border-radius: 5px; } | |
""" | |
# URL μν νμΈ ν¨μ | |
def check_url_status(): | |
try: | |
response = requests.get("http://hugpu.ai:8000") | |
if response.status_code == 200: | |
logging.info("URL μ μ μ±κ³΅: μν μ½λ 200") | |
return "μ μ", "normal" | |
else: | |
logging.error(f"URL μ μ μ€λ₯: μν μ½λ {response.status_code}") | |
return "λΉμ μ", "abnormal" | |
except requests.exceptions.RequestException as e: | |
logging.exception("μλ²μ μ°κ²°ν μ μμ΅λλ€.") | |
return "λΉμ μ", "abnormal" | |
# μν μ λ°μ΄νΈ ν¨μ | |
def update_status(): | |
while True: | |
status, status_class = check_url_status() | |
yield f"<div class='status-{status_class}'>AI κ°μΈ λΉμ μν: {status}</div>" | |
time.sleep(6) # 6μ΄ λκΈ° | |
# Gradio μΈν°νμ΄μ€ μ€μ | |
def create_dashboard(): | |
with gr.Blocks(css=css) as app: | |
gr.Image("banner.png", show_label=False) | |
gr.Markdown("# 24μκ° λͺ¨λν°λ§ μμ€ν ") | |
gr.Markdown("## \n") | |
gr.Markdown("### ν μ€λͺ : [λ§ν¬](https://seawolf2357-bnews1.hf.space)") | |
gr.Markdown("## \n") | |
status_html = gr.HTML("AI κ°μΈ λΉμ μν: λ‘λ© μ€...") | |
gr.Loop(update_status, outputs=status_html, every=6) | |
return app | |
if __name__ == "__main__": | |
dashboard = create_dashboard() | |
dashboard.launch() |