Spaces:
Sleeping
Sleeping
Oscar Wang
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -15,22 +15,22 @@ logger = logging.getLogger(__name__)
|
|
15 |
|
16 |
connected_cpus = {}
|
17 |
|
18 |
-
# Function to donate CPU
|
19 |
-
def
|
20 |
host = data['host']
|
21 |
cpu_count = data['cpu_count']
|
22 |
connected_cpus[host] = {"cpu_count": cpu_count, "usage": 0.0}
|
23 |
logger.info(f"CPU donated by {host} with {cpu_count} CPUs.")
|
24 |
-
return {"status": "success", "message": f"CPU donated by {host}"}
|
25 |
|
26 |
-
# Function to update CPU usage
|
27 |
-
def
|
28 |
host = data['host']
|
29 |
usage = data['usage']
|
30 |
if host in connected_cpus:
|
31 |
connected_cpus[host]['usage'] = usage
|
32 |
logger.info(f"Updated CPU usage for {host}: {usage}%")
|
33 |
-
return {"status": "success"}
|
34 |
|
35 |
# Function to run the provided Python script using MPI
|
36 |
def run_script(script_name, folder_path):
|
@@ -83,27 +83,23 @@ def get_cpu_info():
|
|
83 |
|
84 |
# Gradio interface
|
85 |
def gradio_interface():
|
86 |
-
with gr.
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
# Define the donate CPU endpoint
|
104 |
-
demo.api(donate_cpu, inputs=gr.JSON(), outputs=gr.JSON(), name="donate_cpu")
|
105 |
-
|
106 |
-
demo.launch()
|
107 |
|
|
|
108 |
if __name__ == "__main__":
|
109 |
gradio_interface()
|
|
|
15 |
|
16 |
connected_cpus = {}
|
17 |
|
18 |
+
# Function to donate CPU (Workaround)
|
19 |
+
def donate_cpu_handler(data):
|
20 |
host = data['host']
|
21 |
cpu_count = data['cpu_count']
|
22 |
connected_cpus[host] = {"cpu_count": cpu_count, "usage": 0.0}
|
23 |
logger.info(f"CPU donated by {host} with {cpu_count} CPUs.")
|
24 |
+
return json.dumps({"status": "success", "message": f"CPU donated by {host}"})
|
25 |
|
26 |
+
# Function to update CPU usage (Workaround)
|
27 |
+
def update_cpu_usage_handler(data):
|
28 |
host = data['host']
|
29 |
usage = data['usage']
|
30 |
if host in connected_cpus:
|
31 |
connected_cpus[host]['usage'] = usage
|
32 |
logger.info(f"Updated CPU usage for {host}: {usage}%")
|
33 |
+
return json.dumps({"status": "success"})
|
34 |
|
35 |
# Function to run the provided Python script using MPI
|
36 |
def run_script(script_name, folder_path):
|
|
|
83 |
|
84 |
# Gradio interface
|
85 |
def gradio_interface():
|
86 |
+
with gr.Interface(
|
87 |
+
fn=handle_upload,
|
88 |
+
inputs=[
|
89 |
+
gr.File(label="Upload Folder", file_count="multiple", file_types=['file']),
|
90 |
+
gr.Textbox(label="Python Script Name")
|
91 |
+
],
|
92 |
+
outputs=[
|
93 |
+
gr.Textbox(label="Log Output", interactive=False),
|
94 |
+
gr.File(label="Download Output Folder"),
|
95 |
+
gr.Textbox(label="Connected CPUs Info", interactive=False)
|
96 |
+
],
|
97 |
+
live=True,
|
98 |
+
capture_session=True,
|
99 |
+
theme="compact"
|
100 |
+
) as iface:
|
101 |
+
iface.launch()
|
|
|
|
|
|
|
|
|
|
|
102 |
|
103 |
+
# Launch the Gradio interface
|
104 |
if __name__ == "__main__":
|
105 |
gradio_interface()
|