Oscar Wang commited on
Commit
4280e30
·
verified ·
1 Parent(s): d97f2ec

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -27
app.py CHANGED
@@ -15,22 +15,22 @@ logger = logging.getLogger(__name__)
15
 
16
  connected_cpus = {}
17
 
18
- # Function to donate CPU
19
- def donate_cpu(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 {"status": "success", "message": f"CPU donated by {host}"}
25
 
26
- # Function to update CPU usage
27
- def update_cpu_usage(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 {"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.Blocks() as demo:
87
- gr.Markdown("## Python Script Executor with Distributed Computing")
88
-
89
- with gr.Row():
90
- folder = gr.File(label="Upload Folder", file_count="multiple", file_types=['file'])
91
- script_name = gr.Textbox(label="Python Script Name")
92
-
93
- log_output = gr.Textbox(label="Log Output", interactive=False)
94
- output_folder = gr.File(label="Download Output Folder")
95
- cpu_info = gr.Textbox(label="Connected CPUs Info", interactive=False)
96
-
97
- run_button = gr.Button("Run Script")
98
- refresh_button = gr.Button("Refresh CPU Info")
99
-
100
- run_button.click(fn=handle_upload, inputs=[folder, script_name], outputs=[log_output, output_folder])
101
- refresh_button.click(fn=get_cpu_info, inputs=[], outputs=[cpu_info])
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()