Spaces:
Running
Running
Commit
·
ce8a0e1
1
Parent(s):
116da9e
add port search
Browse files
app.py
CHANGED
@@ -30,6 +30,25 @@ from minigpt4.processors import *
|
|
30 |
from minigpt4.runners import *
|
31 |
from minigpt4.tasks import *
|
32 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
|
34 |
def parse_args():
|
35 |
parser = argparse.ArgumentParser(description="Demo")
|
|
|
30 |
from minigpt4.runners import *
|
31 |
from minigpt4.tasks import *
|
32 |
|
33 |
+
import socket
|
34 |
+
import os
|
35 |
+
|
36 |
+
def find_free_port(start_port, end_port):
|
37 |
+
for port in range(start_port, end_port + 1):
|
38 |
+
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
|
39 |
+
if sock.connect_ex(('localhost', port)) != 0: # Port is not open
|
40 |
+
return port
|
41 |
+
raise OSError(f"Cannot find empty port in range: {start_port}-{end_port}")
|
42 |
+
|
43 |
+
def set_gradio_server_port():
|
44 |
+
start_port = 7870
|
45 |
+
end_port = 9999
|
46 |
+
free_port = find_free_port(start_port, end_port)
|
47 |
+
os.environ["GRADIO_SERVER_PORT"] = str(free_port)
|
48 |
+
print(f"Set GRADIO_SERVER_PORT to {free_port}")
|
49 |
+
|
50 |
+
# Set GRADIO_SERVER_PORT
|
51 |
+
set_gradio_server_port()
|
52 |
|
53 |
def parse_args():
|
54 |
parser = argparse.ArgumentParser(description="Demo")
|