Renecto commited on
Commit
a25df2a
·
verified ·
1 Parent(s): 938eaf7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -0
app.py CHANGED
@@ -1,7 +1,28 @@
1
  from gradio_client import Client
2
  import gradio as gr
3
  import concurrent.futures
 
4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  def greet_para(params_text):
6
  params = params_text.split("\n")
7
  with concurrent.futures.ThreadPoolExecutor() as executor:
@@ -11,6 +32,7 @@ def greet_para(params_text):
11
  def greet(name):
12
  client = Client("Renecto/grandchild")
13
  r = client.submit(name=name, api_name="/predict")
 
14
  return r.result()
15
 
16
  demo = gr.Interface(fn=greet_para, inputs=gr.TextArea("""aaa
 
1
  from gradio_client import Client
2
  import gradio as gr
3
  import concurrent.futures
4
+ import psutil
5
 
6
+ def get_cpu_usage_visual():
7
+ # 各コアのCPU使用率を取得
8
+ cpu_usages = psutil.cpu_percent(interval=1, percpu=True)
9
+ visual_line = ""
10
+
11
+ for usage in cpu_usages:
12
+ if usage < 10:
13
+ visual_line += "⬛️" # 非常に低い使用率(0-9%)
14
+ elif usage < 20:
15
+ visual_line += "🟦" # 低い使用率(10-19%)
16
+ elif usage < 30:
17
+ visual_line += "🟩" # やや低い使用率(20-29%)
18
+ elif usage < 50:
19
+ visual_line += "🟨" # 中程度の使用率(30-49%)
20
+ elif usage < 70:
21
+ visual_line += "🟧" # 高めの使用率(50-69%)
22
+ else:
23
+ visual_line += "🟥" # 非常に高い使用率(70-100%)
24
+ return visual_line
25
+
26
  def greet_para(params_text):
27
  params = params_text.split("\n")
28
  with concurrent.futures.ThreadPoolExecutor() as executor:
 
32
  def greet(name):
33
  client = Client("Renecto/grandchild")
34
  r = client.submit(name=name, api_name="/predict")
35
+ print(get_cpu_usage_visual())
36
  return r.result()
37
 
38
  demo = gr.Interface(fn=greet_para, inputs=gr.TextArea("""aaa