File size: 1,359 Bytes
744a4e1
 
 
a25df2a
744a4e1
a25df2a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
744a4e1
 
 
25c1d65
744a4e1
 
 
938eaf7
25c1d65
a25df2a
acb3120
744a4e1
f632c1f
 
 
 
 
2958197
744a4e1
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
from gradio_client import Client
import gradio as gr
import concurrent.futures
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_para(params_text):
    params = params_text.split("\n")
    with concurrent.futures.ThreadPoolExecutor() as executor:
        results = list(executor.map(greet, params))
    return results 
        
def greet(name):
    client = Client("Renecto/grandchild")
    r = client.submit(name=name,	api_name="/predict")
    print(get_cpu_usage_visual())
    return r.result()

demo = gr.Interface(fn=greet_para, inputs=gr.TextArea("""aaa
bbb
ccc
ddd
eee
fff"""), outputs="json")
demo.launch()