oscarwang2 commited on
Commit
bc57054
1 Parent(s): b9c6f79

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -32
app.py CHANGED
@@ -7,7 +7,6 @@ from zipfile import ZipFile
7
  import logging
8
  import json
9
  import psutil
10
- from flask import Flask, request, jsonify
11
  import threading
12
 
13
  # Configure logging
@@ -15,6 +14,8 @@ logging.basicConfig(level=logging.INFO)
15
  logger = logging.getLogger(__name__)
16
 
17
  # Initialize Flask app
 
 
18
  app = Flask(__name__)
19
 
20
  connected_cpus = {}
@@ -89,44 +90,34 @@ def get_cpu_info():
89
  info.append(f"{host}: {data['cpu_count']} CPUs, {data['usage']}% usage")
90
  return "\n".join(info)
91
 
92
- # Gradio interface
93
- def gradio_interface():
94
- interface_inputs = [
95
- gr.File(label="Upload Folder", file_count="multiple", file_types=['file']),
96
- gr.Textbox(label="Python Script Name")
97
- ]
98
- interface_outputs = [
99
- gr.Textbox(label="Log Output", interactive=False),
100
- gr.File(label="Download Output Folder"),
101
- gr.Textbox(label="Connected CPUs Info", interactive=False)
102
- ]
103
-
104
  iface = gr.Interface(
105
  fn=handle_upload,
106
- inputs=interface_inputs,
107
- outputs=interface_outputs,
 
 
 
 
 
 
 
108
  live=True,
109
  theme="light" # Specify a theme that works, "light" is an example
110
  )
111
-
112
- return iface
113
 
114
- # Function to run Flask app
115
- def run_flask_app():
116
- app.run(host='0.0.0.0', port=7860)
117
-
118
- # Function to run Gradio interface
119
- def run_gradio_interface():
120
- iface = gradio_interface()
121
- iface.launch(port=7860)
122
-
123
- # Start Flask and Gradio interfaces in separate threads
124
  if __name__ == "__main__":
125
  flask_thread = threading.Thread(target=run_flask_app)
126
- gradio_thread = threading.Thread(target=run_gradio_interface)
127
-
128
  flask_thread.start()
129
- gradio_thread.start()
130
-
 
 
131
  flask_thread.join()
132
- gradio_thread.join()
 
7
  import logging
8
  import json
9
  import psutil
 
10
  import threading
11
 
12
  # Configure logging
 
14
  logger = logging.getLogger(__name__)
15
 
16
  # Initialize Flask app
17
+ from flask import Flask, request, jsonify
18
+
19
  app = Flask(__name__)
20
 
21
  connected_cpus = {}
 
90
  info.append(f"{host}: {data['cpu_count']} CPUs, {data['usage']}% usage")
91
  return "\n".join(info)
92
 
93
+ # Function to run Flask app in background
94
+ def run_flask_app():
95
+ app.run(host='0.0.0.0', port=7860, threaded=True, debug=False)
96
+
97
+ # Function to launch Gradio interface
98
+ def launch_gradio_interface():
 
 
 
 
 
 
99
  iface = gr.Interface(
100
  fn=handle_upload,
101
+ inputs=[
102
+ gr.File(label="Upload Folder", file_count="multiple", file_types=['file']),
103
+ gr.Textbox(label="Python Script Name")
104
+ ],
105
+ outputs=[
106
+ gr.Textbox(label="Log Output", interactive=False),
107
+ gr.File(label="Download Output Folder"),
108
+ gr.Textbox(label="Connected CPUs Info", interactive=False)
109
+ ],
110
  live=True,
111
  theme="light" # Specify a theme that works, "light" is an example
112
  )
113
+ iface.launch()
 
114
 
115
+ # Start Flask app in a separate thread
 
 
 
 
 
 
 
 
 
116
  if __name__ == "__main__":
117
  flask_thread = threading.Thread(target=run_flask_app)
 
 
118
  flask_thread.start()
119
+
120
+ # Launch Gradio interface in the main thread
121
+ launch_gradio_interface()
122
+
123
  flask_thread.join()