synapse-sdk 1.0.0a42__py3-none-any.whl → 1.0.0a44__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 +1 -1
- synapse_sdk/utils/http.py +41 -14
- {synapse_sdk-1.0.0a42.dist-info → synapse_sdk-1.0.0a44.dist-info}/METADATA +1 -1
- {synapse_sdk-1.0.0a42.dist-info → synapse_sdk-1.0.0a44.dist-info}/RECORD +8 -8
- {synapse_sdk-1.0.0a42.dist-info → synapse_sdk-1.0.0a44.dist-info}/WHEEL +0 -0
- {synapse_sdk-1.0.0a42.dist-info → synapse_sdk-1.0.0a44.dist-info}/entry_points.txt +0 -0
- {synapse_sdk-1.0.0a42.dist-info → synapse_sdk-1.0.0a44.dist-info}/licenses/LICENSE +0 -0
- {synapse_sdk-1.0.0a42.dist-info → synapse_sdk-1.0.0a44.dist-info}/top_level.txt +0 -0
synapse_sdk/utils/http.py
CHANGED
|
@@ -3,9 +3,12 @@ import os
|
|
|
3
3
|
import tempfile
|
|
4
4
|
import threading
|
|
5
5
|
import time
|
|
6
|
+
import uuid
|
|
6
7
|
from contextlib import contextmanager
|
|
7
8
|
from http.server import HTTPServer, SimpleHTTPRequestHandler
|
|
8
9
|
|
|
10
|
+
import requests
|
|
11
|
+
|
|
9
12
|
from synapse_sdk.utils.network import get_available_ports_host
|
|
10
13
|
|
|
11
14
|
|
|
@@ -15,23 +18,32 @@ class SingleFileHttpServer(SimpleHTTPRequestHandler):
|
|
|
15
18
|
regardless of the request path.
|
|
16
19
|
"""
|
|
17
20
|
|
|
18
|
-
def __init__(self, *args, file_path=None, content_type=None, **kwargs):
|
|
21
|
+
def __init__(self, *args, file_path=None, content_type=None, random_path=None, **kwargs):
|
|
19
22
|
self.file_path = file_path
|
|
20
23
|
self.content_type = content_type
|
|
24
|
+
self.random_path = random_path
|
|
21
25
|
super().__init__(*args, **kwargs)
|
|
22
26
|
|
|
23
27
|
def do_GET(self):
|
|
24
28
|
"""Handle GET requests by serving the single file."""
|
|
25
29
|
try:
|
|
26
|
-
#
|
|
27
|
-
self.
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
self.
|
|
30
|
+
# Check if the path matches our random path
|
|
31
|
+
if self.random_path and self.path == f"/{self.random_path}":
|
|
32
|
+
self.send_response(200)
|
|
33
|
+
if self.content_type:
|
|
34
|
+
self.send_header('Content-type', self.content_type)
|
|
35
|
+
self.send_header('Content-Length', str(os.path.getsize(self.file_path)))
|
|
36
|
+
self.end_headers()
|
|
37
|
+
|
|
38
|
+
with open(self.file_path, 'rb') as file:
|
|
39
|
+
self.wfile.write(file.read())
|
|
40
|
+
elif self.path == "/":
|
|
41
|
+
# Redirect root to the random path
|
|
42
|
+
self.send_response(302)
|
|
43
|
+
self.send_header('Location', f"/{self.random_path}")
|
|
44
|
+
self.end_headers()
|
|
45
|
+
else:
|
|
46
|
+
self.send_error(404, "File not found")
|
|
35
47
|
|
|
36
48
|
except Exception as e:
|
|
37
49
|
self.send_error(500, str(e))
|
|
@@ -66,8 +78,11 @@ def temp_file_server(image=None, file_path=None, format='JPEG', host='0.0.0.0',
|
|
|
66
78
|
port = get_available_ports_host(start_port=8991, end_port=8999)
|
|
67
79
|
|
|
68
80
|
temp_dir = None
|
|
81
|
+
temp_file_path = None
|
|
69
82
|
|
|
70
83
|
try:
|
|
84
|
+
random_filename = f"{uuid.uuid4().hex}"
|
|
85
|
+
|
|
71
86
|
if image is not None:
|
|
72
87
|
temp_dir = tempfile.mkdtemp()
|
|
73
88
|
ext_map = {'JPEG': '.jpg', 'PNG': '.png', 'GIF': '.gif', 'WEBP': '.webp'}
|
|
@@ -80,9 +95,14 @@ def temp_file_server(image=None, file_path=None, format='JPEG', host='0.0.0.0',
|
|
|
80
95
|
temp_file_path = os.path.join(temp_dir, f'temp_image{ext}')
|
|
81
96
|
image.save(temp_file_path, format=format)
|
|
82
97
|
file_path = temp_file_path
|
|
98
|
+
random_filename += ext
|
|
99
|
+
else:
|
|
100
|
+
_, ext = os.path.splitext(file_path)
|
|
101
|
+
random_filename += ext
|
|
83
102
|
|
|
84
103
|
def handler(*args, **kwargs):
|
|
85
|
-
return SingleFileHttpServer(*args, file_path=file_path, content_type=content_type,
|
|
104
|
+
return SingleFileHttpServer(*args, file_path=file_path, content_type=content_type,
|
|
105
|
+
random_path=random_filename, **kwargs)
|
|
86
106
|
|
|
87
107
|
server = HTTPServer((host, port), handler)
|
|
88
108
|
|
|
@@ -90,10 +110,17 @@ def temp_file_server(image=None, file_path=None, format='JPEG', host='0.0.0.0',
|
|
|
90
110
|
server_thread.daemon = True
|
|
91
111
|
server_thread.start()
|
|
92
112
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
url = f'http://localhost:{port}'
|
|
113
|
+
url = f'http://localhost:{port}/{random_filename}'
|
|
96
114
|
|
|
115
|
+
while True:
|
|
116
|
+
try:
|
|
117
|
+
response = requests.get(url)
|
|
118
|
+
if response.status_code == 200:
|
|
119
|
+
break
|
|
120
|
+
except requests.exceptions.ConnectionError:
|
|
121
|
+
pass
|
|
122
|
+
time.sleep(0.01)
|
|
123
|
+
|
|
97
124
|
try:
|
|
98
125
|
yield url
|
|
99
126
|
finally:
|
|
@@ -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=jBkonh0JHRIKFPxv-XBBFM8Da3dSJs-vyJu_KGT73DQ,4508
|
|
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
|
|
@@ -120,7 +120,7 @@ synapse_sdk/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU
|
|
|
120
120
|
synapse_sdk/utils/dataset.py,sha256=zWTzFmv589izFr62BDuApi3r5FpTsdm-5AmriC0AEdM,1865
|
|
121
121
|
synapse_sdk/utils/debug.py,sha256=F7JlUwYjTFZAMRbBqKm6hxOIz-_IXYA8lBInOS4jbS4,100
|
|
122
122
|
synapse_sdk/utils/file.py,sha256=wWBQAx0cB5a-fjfRMeJV-KjBil1ZyKRz-vXno3xBSoo,6834
|
|
123
|
-
synapse_sdk/utils/http.py,sha256=
|
|
123
|
+
synapse_sdk/utils/http.py,sha256=pQ_xiDz3bIR_XSfT3muNn3V2petu7r4uR1kv0fXUndM,4785
|
|
124
124
|
synapse_sdk/utils/module_loading.py,sha256=chHpU-BZjtYaTBD_q0T7LcKWtqKvYBS4L0lPlKkoMQ8,1020
|
|
125
125
|
synapse_sdk/utils/network.py,sha256=WI8qn6KlKpHdMi45V57ofKJB8zusJrbQsxT74LwVfsY,1000
|
|
126
126
|
synapse_sdk/utils/string.py,sha256=rEwuZ9SAaZLcQ8TYiwNKr1h2u4CfnrQx7SUL8NWmChg,216
|
|
@@ -134,9 +134,9 @@ synapse_sdk/utils/storage/providers/__init__.py,sha256=x7RGwZryT2FpVxS7fGWryRVpq
|
|
|
134
134
|
synapse_sdk/utils/storage/providers/gcp.py,sha256=i2BQCu1Kej1If9SuNr2_lEyTcr5M_ncGITZrL0u5wEA,363
|
|
135
135
|
synapse_sdk/utils/storage/providers/s3.py,sha256=W94rQvhGRXti3R4mYP7gmU5pcyCQpGFIBLvxxqLVdRM,2231
|
|
136
136
|
synapse_sdk/utils/storage/providers/sftp.py,sha256=_8s9hf0JXIO21gvm-JVS00FbLsbtvly4c-ETLRax68A,1426
|
|
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.
|
|
142
|
-
synapse_sdk-1.0.
|
|
137
|
+
synapse_sdk-1.0.0a44.dist-info/licenses/LICENSE,sha256=bKzmC5YAg4V1Fhl8OO_tqY8j62hgdncAkN7VrdjmrGk,1101
|
|
138
|
+
synapse_sdk-1.0.0a44.dist-info/METADATA,sha256=gMEVtQmAmnqDdMgHzixO5U5cN6ANhpMOI94FvRuN-fk,1203
|
|
139
|
+
synapse_sdk-1.0.0a44.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
|
|
140
|
+
synapse_sdk-1.0.0a44.dist-info/entry_points.txt,sha256=VNptJoGoNJI8yLXfBmhgUefMsmGI0m3-0YoMvrOgbxo,48
|
|
141
|
+
synapse_sdk-1.0.0a44.dist-info/top_level.txt,sha256=ytgJMRK1slVOKUpgcw3LEyHHP7S34J6n_gJzdkcSsw8,12
|
|
142
|
+
synapse_sdk-1.0.0a44.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|