bnews3 / app.py
seawolf2357's picture
Update app.py
db7d3b2 verified
raw
history blame
1.76 kB
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()