synapse-sdk 1.0.0a39__py3-none-any.whl → 1.0.0a40__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of synapse-sdk might be problematic. Click here for more details.
- synapse_sdk/plugins/categories/neural_net/actions/gradio.py +4 -22
- synapse_sdk/utils/file.py +0 -1
- synapse_sdk/utils/http.py +110 -0
- synapse_sdk/utils/network.py +21 -0
- {synapse_sdk-1.0.0a39.dist-info → synapse_sdk-1.0.0a40.dist-info}/METADATA +1 -1
- {synapse_sdk-1.0.0a39.dist-info → synapse_sdk-1.0.0a40.dist-info}/RECORD +10 -9
- {synapse_sdk-1.0.0a39.dist-info → synapse_sdk-1.0.0a40.dist-info}/WHEEL +0 -0
- {synapse_sdk-1.0.0a39.dist-info → synapse_sdk-1.0.0a40.dist-info}/entry_points.txt +0 -0
- {synapse_sdk-1.0.0a39.dist-info → synapse_sdk-1.0.0a40.dist-info}/licenses/LICENSE +0 -0
- {synapse_sdk-1.0.0a39.dist-info → synapse_sdk-1.0.0a40.dist-info}/top_level.txt +0 -0
|
@@ -6,6 +6,7 @@ from pathlib import Path
|
|
|
6
6
|
from synapse_sdk.plugins.categories.base import Action
|
|
7
7
|
from synapse_sdk.plugins.categories.decorators import register_action
|
|
8
8
|
from synapse_sdk.plugins.enums import PluginCategory, RunMethod
|
|
9
|
+
from synapse_sdk.utils.network import get_available_ports_host
|
|
9
10
|
|
|
10
11
|
|
|
11
12
|
@register_action
|
|
@@ -31,7 +32,7 @@ class GradioAction(Action):
|
|
|
31
32
|
|
|
32
33
|
@cached_property
|
|
33
34
|
def deploy_port(self):
|
|
34
|
-
return
|
|
35
|
+
return get_available_ports_host()
|
|
35
36
|
|
|
36
37
|
def deploy(self):
|
|
37
38
|
self.run.log('deploy', 'Start deploying')
|
|
@@ -102,27 +103,6 @@ CMD ["python", "app.py"]
|
|
|
102
103
|
)
|
|
103
104
|
print(result)
|
|
104
105
|
|
|
105
|
-
@staticmethod
|
|
106
|
-
def _get_avail_ports_host(start_port=8900, end_port=8999):
|
|
107
|
-
import nmap
|
|
108
|
-
|
|
109
|
-
nm = nmap.PortScanner()
|
|
110
|
-
|
|
111
|
-
scan_range = f'{start_port}-{end_port}'
|
|
112
|
-
nm.scan(hosts='host.docker.internal', arguments=f'-p {scan_range}')
|
|
113
|
-
|
|
114
|
-
try:
|
|
115
|
-
open_ports = nm['host.docker.internal']['tcp'].keys()
|
|
116
|
-
open_ports = [int(port) for port in open_ports]
|
|
117
|
-
except KeyError:
|
|
118
|
-
open_ports = []
|
|
119
|
-
|
|
120
|
-
for port in range(start_port, end_port + 1):
|
|
121
|
-
if port not in open_ports:
|
|
122
|
-
return port
|
|
123
|
-
|
|
124
|
-
raise IOError(f'No free ports available in range {start_port}-{end_port}')
|
|
125
|
-
|
|
126
106
|
def run_docker_image(self):
|
|
127
107
|
self.run.log('deploy', 'Start running docker image')
|
|
128
108
|
|
|
@@ -143,6 +123,8 @@ CMD ["python", "app.py"]
|
|
|
143
123
|
self.tag,
|
|
144
124
|
'-p',
|
|
145
125
|
f'{self.deploy_port}:7860',
|
|
126
|
+
'-p',
|
|
127
|
+
'8991-8999:8991-8999',
|
|
146
128
|
self.tag,
|
|
147
129
|
],
|
|
148
130
|
check=True,
|
synapse_sdk/utils/file.py
CHANGED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
import os
|
|
3
|
+
import tempfile
|
|
4
|
+
import threading
|
|
5
|
+
import time
|
|
6
|
+
from contextlib import contextmanager
|
|
7
|
+
from http.server import HTTPServer, SimpleHTTPRequestHandler
|
|
8
|
+
|
|
9
|
+
from synapse_sdk.utils.network import get_available_ports_host
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class SingleFileHttpServer(SimpleHTTPRequestHandler):
|
|
13
|
+
"""
|
|
14
|
+
Custom HTTP request handler that serves a single specified file
|
|
15
|
+
regardless of the request path.
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
def __init__(self, *args, file_path=None, content_type=None, **kwargs):
|
|
19
|
+
self.file_path = file_path
|
|
20
|
+
self.content_type = content_type
|
|
21
|
+
super().__init__(*args, **kwargs)
|
|
22
|
+
|
|
23
|
+
def do_GET(self):
|
|
24
|
+
"""Handle GET requests by serving the single file."""
|
|
25
|
+
try:
|
|
26
|
+
# Always serve the specified file regardless of the path requested
|
|
27
|
+
self.send_response(200)
|
|
28
|
+
if self.content_type:
|
|
29
|
+
self.send_header('Content-type', self.content_type)
|
|
30
|
+
self.send_header('Content-Length', str(os.path.getsize(self.file_path)))
|
|
31
|
+
self.end_headers()
|
|
32
|
+
|
|
33
|
+
with open(self.file_path, 'rb') as file:
|
|
34
|
+
self.wfile.write(file.read())
|
|
35
|
+
|
|
36
|
+
except Exception as e:
|
|
37
|
+
self.send_error(500, str(e))
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
@contextmanager
|
|
41
|
+
def temp_file_server(image=None, file_path=None, format='JPEG', host='localhost', port=None, content_type=None):
|
|
42
|
+
"""
|
|
43
|
+
Context manager that serves a file temporarily via HTTP.
|
|
44
|
+
|
|
45
|
+
Args:
|
|
46
|
+
image: A PIL Image object to serve (optional)
|
|
47
|
+
file_path: Path to an existing file to serve (optional - used if image not provided)
|
|
48
|
+
format: Image format when saving a PIL Image (default: "JPEG")
|
|
49
|
+
host: Host to serve on (default: "localhost")
|
|
50
|
+
port: Port to serve on (default: auto-selected free port)
|
|
51
|
+
content_type: Content type header (default: auto-detected based on format)
|
|
52
|
+
|
|
53
|
+
Returns:
|
|
54
|
+
URL where the file is being served
|
|
55
|
+
|
|
56
|
+
Usage:
|
|
57
|
+
with temp_file_serve(image=my_pillow_img) as url:
|
|
58
|
+
# use url to access the image
|
|
59
|
+
print(f"Image available at: {url}")
|
|
60
|
+
"""
|
|
61
|
+
if image is None and file_path is None:
|
|
62
|
+
raise ValueError('Either image or file_path must be provided')
|
|
63
|
+
|
|
64
|
+
# Use a free port if none specified
|
|
65
|
+
if port is None:
|
|
66
|
+
port = get_available_ports_host(start_port=8991, end_port=8999)
|
|
67
|
+
|
|
68
|
+
temp_dir = None
|
|
69
|
+
|
|
70
|
+
try:
|
|
71
|
+
if image is not None:
|
|
72
|
+
temp_dir = tempfile.mkdtemp()
|
|
73
|
+
ext_map = {'JPEG': '.jpg', 'PNG': '.png', 'GIF': '.gif', 'WEBP': '.webp'}
|
|
74
|
+
content_type_map = {'JPEG': 'image/jpeg', 'PNG': 'image/png', 'GIF': 'image/gif', 'WEBP': 'image/webp'}
|
|
75
|
+
|
|
76
|
+
ext = ext_map.get(format, '.jpg')
|
|
77
|
+
if content_type is None:
|
|
78
|
+
content_type = content_type_map.get(format, 'image/jpeg')
|
|
79
|
+
|
|
80
|
+
temp_file_path = os.path.join(temp_dir, f'temp_image{ext}')
|
|
81
|
+
image.save(temp_file_path, format=format)
|
|
82
|
+
file_path = temp_file_path
|
|
83
|
+
|
|
84
|
+
def handler(*args, **kwargs):
|
|
85
|
+
return SingleFileHttpServer(*args, file_path=file_path, content_type=content_type, **kwargs)
|
|
86
|
+
|
|
87
|
+
server = HTTPServer((host, port), handler)
|
|
88
|
+
|
|
89
|
+
server_thread = threading.Thread(target=server.serve_forever)
|
|
90
|
+
server_thread.daemon = True
|
|
91
|
+
server_thread.start()
|
|
92
|
+
|
|
93
|
+
time.sleep(0.1)
|
|
94
|
+
|
|
95
|
+
url = f'http://{host}:{port}'
|
|
96
|
+
|
|
97
|
+
try:
|
|
98
|
+
yield url
|
|
99
|
+
finally:
|
|
100
|
+
server.shutdown()
|
|
101
|
+
server.server_close()
|
|
102
|
+
|
|
103
|
+
finally:
|
|
104
|
+
if temp_dir:
|
|
105
|
+
try:
|
|
106
|
+
if temp_file_path and os.path.exists(temp_file_path):
|
|
107
|
+
os.unlink(temp_file_path)
|
|
108
|
+
os.rmdir(temp_dir)
|
|
109
|
+
except Exception as e:
|
|
110
|
+
logging.warning(f'Error cleaning up temporary files: {e}')
|
synapse_sdk/utils/network.py
CHANGED
|
@@ -14,3 +14,24 @@ def clean_url(url, remove_query_params=True, remove_fragment=True):
|
|
|
14
14
|
query,
|
|
15
15
|
fragment,
|
|
16
16
|
))
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def get_available_ports_host(start_port=8900, end_port=8990):
|
|
20
|
+
import nmap
|
|
21
|
+
|
|
22
|
+
nm = nmap.PortScanner()
|
|
23
|
+
|
|
24
|
+
scan_range = f'{start_port}-{end_port}'
|
|
25
|
+
nm.scan(hosts='host.docker.internal', arguments=f'-p {scan_range}')
|
|
26
|
+
|
|
27
|
+
try:
|
|
28
|
+
open_ports = nm['host.docker.internal']['tcp'].keys()
|
|
29
|
+
open_ports = [int(port) for port in open_ports]
|
|
30
|
+
except KeyError:
|
|
31
|
+
open_ports = []
|
|
32
|
+
|
|
33
|
+
for port in range(start_port, end_port + 1):
|
|
34
|
+
if port not in open_ports:
|
|
35
|
+
return port
|
|
36
|
+
|
|
37
|
+
raise IOError(f'No free ports available in range {start_port}-{end_port}')
|
|
@@ -68,7 +68,7 @@ synapse_sdk/plugins/categories/export/templates/plugin/export.py,sha256=39XLGo8u
|
|
|
68
68
|
synapse_sdk/plugins/categories/neural_net/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
69
69
|
synapse_sdk/plugins/categories/neural_net/actions/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
70
70
|
synapse_sdk/plugins/categories/neural_net/actions/deployment.py,sha256=y2LrS-pwazqRI5O0q1NUy45NQYsBj6ykbrXnDMs_fqE,1987
|
|
71
|
-
synapse_sdk/plugins/categories/neural_net/actions/gradio.py,sha256=
|
|
71
|
+
synapse_sdk/plugins/categories/neural_net/actions/gradio.py,sha256=pcrMr3pmNJmVjS2wRvyGmCvIoxYKSQJAheXqJBNRfm4,3790
|
|
72
72
|
synapse_sdk/plugins/categories/neural_net/actions/inference.py,sha256=0a655ELqNVjPFZTJDiw4EUdcMCPGveUEKyoYqpwMFBU,1019
|
|
73
73
|
synapse_sdk/plugins/categories/neural_net/actions/test.py,sha256=JY25eg-Fo6WbgtMkGoo_qNqoaZkp3AQNEypJmeGzEog,320
|
|
74
74
|
synapse_sdk/plugins/categories/neural_net/actions/train.py,sha256=kve6iTCg2kUeavMQTR2JFuoYDu-QWZFFlB58ZICQtdM,5406
|
|
@@ -119,9 +119,10 @@ synapse_sdk/shared/enums.py,sha256=WMZPag9deVF7VCXaQkLk7ly_uX1KwbNzRx9TdvgaeFE,1
|
|
|
119
119
|
synapse_sdk/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
120
120
|
synapse_sdk/utils/dataset.py,sha256=zWTzFmv589izFr62BDuApi3r5FpTsdm-5AmriC0AEdM,1865
|
|
121
121
|
synapse_sdk/utils/debug.py,sha256=F7JlUwYjTFZAMRbBqKm6hxOIz-_IXYA8lBInOS4jbS4,100
|
|
122
|
-
synapse_sdk/utils/file.py,sha256=
|
|
122
|
+
synapse_sdk/utils/file.py,sha256=wWBQAx0cB5a-fjfRMeJV-KjBil1ZyKRz-vXno3xBSoo,6834
|
|
123
|
+
synapse_sdk/utils/http.py,sha256=GqYONHfovwBmP4p3ZczVCNvn4oApx2QzfzGIEiICqJo,3770
|
|
123
124
|
synapse_sdk/utils/module_loading.py,sha256=chHpU-BZjtYaTBD_q0T7LcKWtqKvYBS4L0lPlKkoMQ8,1020
|
|
124
|
-
synapse_sdk/utils/network.py,sha256=
|
|
125
|
+
synapse_sdk/utils/network.py,sha256=WI8qn6KlKpHdMi45V57ofKJB8zusJrbQsxT74LwVfsY,1000
|
|
125
126
|
synapse_sdk/utils/string.py,sha256=rEwuZ9SAaZLcQ8TYiwNKr1h2u4CfnrQx7SUL8NWmChg,216
|
|
126
127
|
synapse_sdk/utils/pydantic/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
127
128
|
synapse_sdk/utils/pydantic/config.py,sha256=1vYOcUI35GslfD1rrqhFkNXXJOXt4IDqOPSx9VWGfNE,123
|
|
@@ -133,9 +134,9 @@ synapse_sdk/utils/storage/providers/__init__.py,sha256=x7RGwZryT2FpVxS7fGWryRVpq
|
|
|
133
134
|
synapse_sdk/utils/storage/providers/gcp.py,sha256=i2BQCu1Kej1If9SuNr2_lEyTcr5M_ncGITZrL0u5wEA,363
|
|
134
135
|
synapse_sdk/utils/storage/providers/s3.py,sha256=W94rQvhGRXti3R4mYP7gmU5pcyCQpGFIBLvxxqLVdRM,2231
|
|
135
136
|
synapse_sdk/utils/storage/providers/sftp.py,sha256=_8s9hf0JXIO21gvm-JVS00FbLsbtvly4c-ETLRax68A,1426
|
|
136
|
-
synapse_sdk-1.0.
|
|
137
|
-
synapse_sdk-1.0.
|
|
138
|
-
synapse_sdk-1.0.
|
|
139
|
-
synapse_sdk-1.0.
|
|
140
|
-
synapse_sdk-1.0.
|
|
141
|
-
synapse_sdk-1.0.
|
|
137
|
+
synapse_sdk-1.0.0a40.dist-info/licenses/LICENSE,sha256=bKzmC5YAg4V1Fhl8OO_tqY8j62hgdncAkN7VrdjmrGk,1101
|
|
138
|
+
synapse_sdk-1.0.0a40.dist-info/METADATA,sha256=P24axYuG6BpxcsvfyKnMuZh6NpNBQCaN3gcRnggwxDg,1203
|
|
139
|
+
synapse_sdk-1.0.0a40.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
|
|
140
|
+
synapse_sdk-1.0.0a40.dist-info/entry_points.txt,sha256=VNptJoGoNJI8yLXfBmhgUefMsmGI0m3-0YoMvrOgbxo,48
|
|
141
|
+
synapse_sdk-1.0.0a40.dist-info/top_level.txt,sha256=ytgJMRK1slVOKUpgcw3LEyHHP7S34J6n_gJzdkcSsw8,12
|
|
142
|
+
synapse_sdk-1.0.0a40.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|