|
from gradio_client import Client |
|
import gradio as gr |
|
import concurrent.futures |
|
import psutil |
|
|
|
def get_cpu_usage_visual(): |
|
|
|
cpu_usages = psutil.cpu_percent(interval=1, percpu=True) |
|
visual_line = "" |
|
|
|
for usage in cpu_usages: |
|
if usage < 10: |
|
visual_line += "⬛️" |
|
elif usage < 20: |
|
visual_line += "🟦" |
|
elif usage < 30: |
|
visual_line += "🟩" |
|
elif usage < 50: |
|
visual_line += "🟨" |
|
elif usage < 70: |
|
visual_line += "🟧" |
|
else: |
|
visual_line += "🟥" |
|
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() |
|
|
|
|