Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
import os
|
|
|
|
| 2 |
import gradio as gr
|
| 3 |
import cadquery as cq
|
| 4 |
from cadquery import exporters
|
|
@@ -8,7 +9,6 @@ from io import BytesIO
|
|
| 8 |
import json
|
| 9 |
import atexit
|
| 10 |
import glob
|
| 11 |
-
import os
|
| 12 |
|
| 13 |
# Cleanup function to remove temporary files
|
| 14 |
def cleanup_temp_files():
|
|
@@ -86,6 +86,14 @@ SOLVE
|
|
| 86 |
except Exception as e:
|
| 87 |
return f"Error: {str(e)}", None
|
| 88 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
# Gradio App
|
| 90 |
def main():
|
| 91 |
with gr.Blocks() as app:
|
|
@@ -134,10 +142,9 @@ def main():
|
|
| 134 |
if __name__ == "__main__":
|
| 135 |
app = main()
|
| 136 |
try:
|
| 137 |
-
#
|
| 138 |
port = find_free_port(7860, 7870)
|
| 139 |
print(f"Launching on port: {port}")
|
| 140 |
app.launch(server_port=port, debug=True)
|
| 141 |
except Exception as e:
|
| 142 |
print(f"Failed to launch: {str(e)}")
|
| 143 |
-
|
|
|
|
| 1 |
import os
|
| 2 |
+
import socket
|
| 3 |
import gradio as gr
|
| 4 |
import cadquery as cq
|
| 5 |
from cadquery import exporters
|
|
|
|
| 9 |
import json
|
| 10 |
import atexit
|
| 11 |
import glob
|
|
|
|
| 12 |
|
| 13 |
# Cleanup function to remove temporary files
|
| 14 |
def cleanup_temp_files():
|
|
|
|
| 86 |
except Exception as e:
|
| 87 |
return f"Error: {str(e)}", None
|
| 88 |
|
| 89 |
+
# Function to find a free port in a range
|
| 90 |
+
def find_free_port(start_port, end_port):
|
| 91 |
+
for port in range(start_port, end_port + 1):
|
| 92 |
+
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
|
| 93 |
+
if sock.connect_ex(('localhost', port)) != 0: # Port is free
|
| 94 |
+
return port
|
| 95 |
+
raise OSError(f"No available ports in range {start_port}-{end_port}")
|
| 96 |
+
|
| 97 |
# Gradio App
|
| 98 |
def main():
|
| 99 |
with gr.Blocks() as app:
|
|
|
|
| 142 |
if __name__ == "__main__":
|
| 143 |
app = main()
|
| 144 |
try:
|
| 145 |
+
# Dynamically find a free port in range 7860-7870
|
| 146 |
port = find_free_port(7860, 7870)
|
| 147 |
print(f"Launching on port: {port}")
|
| 148 |
app.launch(server_port=port, debug=True)
|
| 149 |
except Exception as e:
|
| 150 |
print(f"Failed to launch: {str(e)}")
|
|
|