inferencesh 0.1.5__py3-none-any.whl → 0.1.7__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 inferencesh might be problematic. Click here for more details.
- inferencesh/sdk.py +39 -4
- {inferencesh-0.1.5.dist-info → inferencesh-0.1.7.dist-info}/METADATA +1 -1
- inferencesh-0.1.7.dist-info/RECORD +8 -0
- inferencesh-0.1.5.dist-info/RECORD +0 -8
- {inferencesh-0.1.5.dist-info → inferencesh-0.1.7.dist-info}/LICENSE +0 -0
- {inferencesh-0.1.5.dist-info → inferencesh-0.1.7.dist-info}/WHEEL +0 -0
- {inferencesh-0.1.5.dist-info → inferencesh-0.1.7.dist-info}/entry_points.txt +0 -0
- {inferencesh-0.1.5.dist-info → inferencesh-0.1.7.dist-info}/top_level.txt +0 -0
inferencesh/sdk.py
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
from typing import Optional, Union
|
|
1
|
+
from typing import Optional, Union, ClassVar
|
|
2
2
|
from pydantic import BaseModel, ConfigDict
|
|
3
3
|
import mimetypes
|
|
4
4
|
import os
|
|
5
|
+
import urllib.request
|
|
6
|
+
import urllib.parse
|
|
7
|
+
import tempfile
|
|
5
8
|
|
|
6
9
|
class BaseAppInput(BaseModel):
|
|
7
10
|
pass
|
|
@@ -10,7 +13,11 @@ class BaseAppOutput(BaseModel):
|
|
|
10
13
|
pass
|
|
11
14
|
|
|
12
15
|
class BaseApp(BaseModel):
|
|
13
|
-
model_config = ConfigDict(
|
|
16
|
+
model_config = ConfigDict(
|
|
17
|
+
arbitrary_types_allowed=True,
|
|
18
|
+
extra='allow'
|
|
19
|
+
)
|
|
20
|
+
|
|
14
21
|
async def setup(self):
|
|
15
22
|
pass
|
|
16
23
|
|
|
@@ -23,17 +30,45 @@ class BaseApp(BaseModel):
|
|
|
23
30
|
|
|
24
31
|
class File(BaseModel):
|
|
25
32
|
"""A class representing a file in the inference.sh ecosystem."""
|
|
26
|
-
path: str # Absolute path to the file
|
|
33
|
+
path: str # Absolute path to the file or URL
|
|
27
34
|
mime_type: Optional[str] = None # MIME type of the file
|
|
28
35
|
size: Optional[int] = None # File size in bytes
|
|
29
36
|
filename: Optional[str] = None # Original filename if available
|
|
37
|
+
_tmp_path: Optional[str] = None # Internal storage for temporary file path
|
|
30
38
|
|
|
31
39
|
def __init__(self, **data):
|
|
32
40
|
super().__init__(**data)
|
|
33
|
-
if
|
|
41
|
+
if self._is_url(self.path):
|
|
42
|
+
self._download_url()
|
|
43
|
+
elif not os.path.isabs(self.path):
|
|
34
44
|
self.path = os.path.abspath(self.path)
|
|
35
45
|
self._populate_metadata()
|
|
36
46
|
|
|
47
|
+
def _is_url(self, path: str) -> bool:
|
|
48
|
+
"""Check if the path is a URL."""
|
|
49
|
+
parsed = urllib.parse.urlparse(path)
|
|
50
|
+
return parsed.scheme in ('http', 'https')
|
|
51
|
+
|
|
52
|
+
def _download_url(self) -> None:
|
|
53
|
+
"""Download the URL to a temporary file and update the path."""
|
|
54
|
+
original_url = self.path
|
|
55
|
+
# Create a temporary file with a suffix based on the URL path
|
|
56
|
+
suffix = os.path.splitext(urllib.parse.urlparse(original_url).path)[1]
|
|
57
|
+
tmp_file = tempfile.NamedTemporaryFile(delete=False, suffix=suffix)
|
|
58
|
+
self._tmp_path = tmp_file.name
|
|
59
|
+
|
|
60
|
+
# Download the file
|
|
61
|
+
urllib.request.urlretrieve(original_url, self._tmp_path)
|
|
62
|
+
self.path = self._tmp_path
|
|
63
|
+
|
|
64
|
+
def __del__(self):
|
|
65
|
+
"""Cleanup temporary file if it exists."""
|
|
66
|
+
if hasattr(self, '_tmp_path') and self._tmp_path:
|
|
67
|
+
try:
|
|
68
|
+
os.unlink(self._tmp_path)
|
|
69
|
+
except:
|
|
70
|
+
pass
|
|
71
|
+
|
|
37
72
|
def _populate_metadata(self) -> None:
|
|
38
73
|
"""Populate file metadata from the path if it exists."""
|
|
39
74
|
if os.path.exists(self.path):
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
inferencesh/__init__.py,sha256=pR0MXSJe41LgJkjGK-jhZR7LjqCFdRZtNTV6qcjYSTI,123
|
|
2
|
+
inferencesh/sdk.py,sha256=tvlI29zd1gMloqVVpn4s12NONhOAxKY6y7gEkMLEWlw,3576
|
|
3
|
+
inferencesh-0.1.7.dist-info/LICENSE,sha256=OsgqEWIh2el_QMj0y8O1A5Q5Dl-dxqqYbFE6fszuR4s,1086
|
|
4
|
+
inferencesh-0.1.7.dist-info/METADATA,sha256=LSwkjk4wIakU3oHnUQBSHbLaYzMwhBNNPgvgGMyT3is,2583
|
|
5
|
+
inferencesh-0.1.7.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
|
6
|
+
inferencesh-0.1.7.dist-info/entry_points.txt,sha256=6IC-fyozAqW3ljsMLGCXxJ0_ui2Jb-2fLHtoH1RTnEE,45
|
|
7
|
+
inferencesh-0.1.7.dist-info/top_level.txt,sha256=TSMHg3T1ThMl1HGAWmzBClwOYH1ump5neof9BfHIwaA,12
|
|
8
|
+
inferencesh-0.1.7.dist-info/RECORD,,
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
inferencesh/__init__.py,sha256=pR0MXSJe41LgJkjGK-jhZR7LjqCFdRZtNTV6qcjYSTI,123
|
|
2
|
-
inferencesh/sdk.py,sha256=7ma8Z_hwZHA2ZON0jKrgeyzNIZLlm3s8yMdY92xdqXg,2366
|
|
3
|
-
inferencesh-0.1.5.dist-info/LICENSE,sha256=OsgqEWIh2el_QMj0y8O1A5Q5Dl-dxqqYbFE6fszuR4s,1086
|
|
4
|
-
inferencesh-0.1.5.dist-info/METADATA,sha256=enrWcMdLYEj29CK9S75oHr_e7fKXzdvsGwn_RhRfSog,2583
|
|
5
|
-
inferencesh-0.1.5.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
|
6
|
-
inferencesh-0.1.5.dist-info/entry_points.txt,sha256=6IC-fyozAqW3ljsMLGCXxJ0_ui2Jb-2fLHtoH1RTnEE,45
|
|
7
|
-
inferencesh-0.1.5.dist-info/top_level.txt,sha256=TSMHg3T1ThMl1HGAWmzBClwOYH1ump5neof9BfHIwaA,12
|
|
8
|
-
inferencesh-0.1.5.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|