grandchild / app.py
Renecto's picture
Update app.py
70790e9 verified
import gradio as gr
import time
from datetime import datetime
import pytz
import psutil
def get_cpu_usage_visual():
# 各コアのCPU使用率を取得
cpu_usages = psutil.cpu_percent(interval=1, percpu=True)
visual_line = ""
for usage in cpu_usages:
if usage < 10:
visual_line += "⬛️" # 非常に低い使用率(0-9%)
elif usage < 20:
visual_line += "🟦" # 低い使用率(10-19%)
elif usage < 30:
visual_line += "🟩" # やや低い使用率(20-29%)
elif usage < 50:
visual_line += "🟨" # 中程度の使用率(30-49%)
elif usage < 70:
visual_line += "🟧" # 高めの使用率(50-69%)
else:
visual_line += "🟥" # 非常に高い使用率(70-100%)
return visual_line
def greet(name):
start = datetime.now(pytz.timezone('Asia/Tokyo')).strftime("%H:%M:%S")
time.sleep(1)
print(get_cpu_usage_visual())
end = datetime.now(pytz.timezone('Asia/Tokyo')).strftime("%H:%M:%S")
return f"[{name}] {start} ~ {end}"
demo = gr.Interface(fn=greet, inputs="text", outputs="text", concurrency_limit=10)
demo.launch()