inferencesh 0.1.4__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/__init__.py +5 -0
- inferencesh/sdk.py +75 -0
- inferencesh-0.1.4.dist-info/LICENSE +21 -0
- inferencesh-0.1.4.dist-info/METADATA +100 -0
- inferencesh-0.1.4.dist-info/RECORD +8 -0
- inferencesh-0.1.4.dist-info/WHEEL +5 -0
- inferencesh-0.1.4.dist-info/entry_points.txt +2 -0
- inferencesh-0.1.4.dist-info/top_level.txt +1 -0
inferencesh/__init__.py
ADDED
inferencesh/sdk.py
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
from typing import Optional, Union
|
|
2
|
+
from pydantic import BaseModel, ConfigDict
|
|
3
|
+
import mimetypes
|
|
4
|
+
import os
|
|
5
|
+
|
|
6
|
+
class BaseAppInput(BaseModel):
|
|
7
|
+
pass
|
|
8
|
+
|
|
9
|
+
class BaseAppOutput(BaseModel):
|
|
10
|
+
pass
|
|
11
|
+
|
|
12
|
+
class BaseApp(BaseModel):
|
|
13
|
+
model_config = ConfigDict(arbitrary_types_allowed=True)
|
|
14
|
+
extra = "allow"
|
|
15
|
+
async def setup(self):
|
|
16
|
+
pass
|
|
17
|
+
|
|
18
|
+
async def run(self, app_input: BaseAppInput) -> BaseAppOutput:
|
|
19
|
+
raise NotImplementedError("run method must be implemented")
|
|
20
|
+
|
|
21
|
+
async def unload(self):
|
|
22
|
+
pass
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class File(BaseModel):
|
|
26
|
+
"""A class representing a file in the inference.sh ecosystem."""
|
|
27
|
+
path: str # Absolute path to the file
|
|
28
|
+
mime_type: Optional[str] = None # MIME type of the file
|
|
29
|
+
size: Optional[int] = None # File size in bytes
|
|
30
|
+
filename: Optional[str] = None # Original filename if available
|
|
31
|
+
|
|
32
|
+
def __init__(self, **data):
|
|
33
|
+
super().__init__(**data)
|
|
34
|
+
if not os.path.isabs(self.path):
|
|
35
|
+
self.path = os.path.abspath(self.path)
|
|
36
|
+
self._populate_metadata()
|
|
37
|
+
|
|
38
|
+
def _populate_metadata(self) -> None:
|
|
39
|
+
"""Populate file metadata from the path if it exists."""
|
|
40
|
+
if os.path.exists(self.path):
|
|
41
|
+
if not self.mime_type:
|
|
42
|
+
self.mime_type = self._guess_mime_type()
|
|
43
|
+
if not self.size:
|
|
44
|
+
self.size = self._get_file_size()
|
|
45
|
+
if not self.filename:
|
|
46
|
+
self.filename = self._get_filename()
|
|
47
|
+
|
|
48
|
+
@classmethod
|
|
49
|
+
def from_path(cls, path: Union[str, os.PathLike]) -> 'File':
|
|
50
|
+
"""Create a File instance from a file path."""
|
|
51
|
+
return cls(path=str(path))
|
|
52
|
+
|
|
53
|
+
def _guess_mime_type(self) -> Optional[str]:
|
|
54
|
+
"""Guess the MIME type of the file."""
|
|
55
|
+
return mimetypes.guess_type(self.path)[0]
|
|
56
|
+
|
|
57
|
+
def _get_file_size(self) -> int:
|
|
58
|
+
"""Get the size of the file in bytes."""
|
|
59
|
+
return os.path.getsize(self.path)
|
|
60
|
+
|
|
61
|
+
def _get_filename(self) -> str:
|
|
62
|
+
"""Get the base filename from the path."""
|
|
63
|
+
return os.path.basename(self.path)
|
|
64
|
+
|
|
65
|
+
def exists(self) -> bool:
|
|
66
|
+
"""Check if the file exists."""
|
|
67
|
+
return os.path.exists(self.path)
|
|
68
|
+
|
|
69
|
+
def refresh_metadata(self) -> None:
|
|
70
|
+
"""Refresh all metadata from the file."""
|
|
71
|
+
self._populate_metadata()
|
|
72
|
+
|
|
73
|
+
class Config:
|
|
74
|
+
"""Pydantic config"""
|
|
75
|
+
arbitrary_types_allowed = True
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Inference Shell Inc.
|
|
4
|
+
|
|
5
|
+
This software is licensed for use only in conjunction with inference.sh services and platforms.
|
|
6
|
+
|
|
7
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
of this software to use it with inference.sh services, subject to the following conditions:
|
|
9
|
+
|
|
10
|
+
1. The software may only be used in conjunction with inference.sh services and platforms.
|
|
11
|
+
2. Redistribution and modification are permitted only for use with inference.sh services.
|
|
12
|
+
3. This copyright notice and permission notice shall be included in all copies or
|
|
13
|
+
substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
Metadata-Version: 2.2
|
|
2
|
+
Name: inferencesh
|
|
3
|
+
Version: 0.1.4
|
|
4
|
+
Summary: inference.sh Python SDK
|
|
5
|
+
Author: Inference Shell Inc.
|
|
6
|
+
Author-email: "Inference Shell Inc." <hello@inference.sh>
|
|
7
|
+
Project-URL: Homepage, https://github.com/inference-sh/sdk
|
|
8
|
+
Project-URL: Bug Tracker, https://github.com/inference-sh/sdk/issues
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
11
|
+
Classifier: Operating System :: OS Independent
|
|
12
|
+
Requires-Python: >=3.7
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
License-File: LICENSE
|
|
15
|
+
Requires-Dist: pydantic>=2.0.0
|
|
16
|
+
Dynamic: author
|
|
17
|
+
Dynamic: requires-python
|
|
18
|
+
|
|
19
|
+
# inference.sh CLI
|
|
20
|
+
|
|
21
|
+
Helper package for inference.sh Python applications.
|
|
22
|
+
|
|
23
|
+
## Installation
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
pip install infsh
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## File Handling
|
|
30
|
+
|
|
31
|
+
The `File` class provides a standardized way to handle files in the inference.sh ecosystem:
|
|
32
|
+
|
|
33
|
+
```python
|
|
34
|
+
from infsh import File
|
|
35
|
+
|
|
36
|
+
# Basic file creation
|
|
37
|
+
file = File(path="/path/to/file.png")
|
|
38
|
+
|
|
39
|
+
# File with explicit metadata
|
|
40
|
+
file = File(
|
|
41
|
+
path="/path/to/file.png",
|
|
42
|
+
mime_type="image/png",
|
|
43
|
+
filename="custom_name.png",
|
|
44
|
+
size=1024 # in bytes
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
# Create from path (automatically populates metadata)
|
|
48
|
+
file = File.from_path("/path/to/file.png")
|
|
49
|
+
|
|
50
|
+
# Check if file exists
|
|
51
|
+
exists = file.exists()
|
|
52
|
+
|
|
53
|
+
# Access file metadata
|
|
54
|
+
print(file.mime_type) # automatically detected if not specified
|
|
55
|
+
print(file.size) # file size in bytes
|
|
56
|
+
print(file.filename) # basename of the file
|
|
57
|
+
|
|
58
|
+
# Refresh metadata (useful if file has changed)
|
|
59
|
+
file.refresh_metadata()
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
The `File` class automatically handles:
|
|
63
|
+
- MIME type detection
|
|
64
|
+
- File size calculation
|
|
65
|
+
- Filename extraction from path
|
|
66
|
+
- File existence checking
|
|
67
|
+
|
|
68
|
+
## Creating an App
|
|
69
|
+
|
|
70
|
+
To create an inference app, inherit from `BaseApp` and define your input/output types:
|
|
71
|
+
|
|
72
|
+
```python
|
|
73
|
+
from infsh import BaseApp, BaseAppInput, BaseAppOutput, File
|
|
74
|
+
|
|
75
|
+
class AppInput(BaseAppInput):
|
|
76
|
+
image: str # URL or file path to image
|
|
77
|
+
mask: str # URL or file path to mask
|
|
78
|
+
|
|
79
|
+
class AppOutput(BaseAppOutput):
|
|
80
|
+
image: File
|
|
81
|
+
|
|
82
|
+
class MyApp(BaseApp):
|
|
83
|
+
async def setup(self):
|
|
84
|
+
# Initialize your model here
|
|
85
|
+
pass
|
|
86
|
+
|
|
87
|
+
async def run(self, app_input: AppInput) -> AppOutput:
|
|
88
|
+
# Process input and return output
|
|
89
|
+
result_path = "/tmp/result.png"
|
|
90
|
+
return AppOutput(image=File(path=result_path))
|
|
91
|
+
|
|
92
|
+
async def unload(self):
|
|
93
|
+
# Clean up resources
|
|
94
|
+
pass
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
The app lifecycle has three main methods:
|
|
98
|
+
- `setup()`: Called when the app starts, use it to initialize models
|
|
99
|
+
- `run()`: Called for each inference request
|
|
100
|
+
- `unload()`: Called when shutting down, use it to free resources
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
inferencesh/__init__.py,sha256=pR0MXSJe41LgJkjGK-jhZR7LjqCFdRZtNTV6qcjYSTI,123
|
|
2
|
+
inferencesh/sdk.py,sha256=0SW0LTw2bs7RYFc6t5V4_Floah_Qi3gKsk9P-mcnVbE,2371
|
|
3
|
+
inferencesh-0.1.4.dist-info/LICENSE,sha256=OsgqEWIh2el_QMj0y8O1A5Q5Dl-dxqqYbFE6fszuR4s,1086
|
|
4
|
+
inferencesh-0.1.4.dist-info/METADATA,sha256=Bx7ZcEUJIZELX6fGPNTwSbVuKvji_eASiBqL1c69Mio,2583
|
|
5
|
+
inferencesh-0.1.4.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
|
6
|
+
inferencesh-0.1.4.dist-info/entry_points.txt,sha256=6IC-fyozAqW3ljsMLGCXxJ0_ui2Jb-2fLHtoH1RTnEE,45
|
|
7
|
+
inferencesh-0.1.4.dist-info/top_level.txt,sha256=TSMHg3T1ThMl1HGAWmzBClwOYH1ump5neof9BfHIwaA,12
|
|
8
|
+
inferencesh-0.1.4.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
inferencesh
|