Skip to content

Commit 2aeebad

Browse files
committed
first commit
0 parents  commit 2aeebad

File tree

9 files changed

+265
-0
lines changed

9 files changed

+265
-0
lines changed

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/**/__pycache__
2+
/**/.pytest_cache
3+
/**/*.pem
4+
.DS_Store
5+
.pytest_cache
6+
dist
7+
build
8+
fastlabel.egg-info

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2020 FastLabel Inc
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or 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.

MANIFEST.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
include requirements.txt
2+
include README.md

README.md

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# FastLabel Python SDK
2+
3+
## Installation
4+
5+
```bash
6+
$ pip install fastlabel
7+
```
8+
9+
## Usage
10+
11+
Configure API Key in environment variable.
12+
13+
```bash
14+
export FASTLABEL_API_KEY="YOUR_API_KEY"
15+
```
16+
17+
Initialize fastlabel client.
18+
19+
```python
20+
import fastlabel
21+
client = fastlabel.Client()
22+
```
23+
24+
## Model Analysis
25+
26+
### Upload Predictions
27+
28+
```python
29+
import fastlabel
30+
from fastlabel.const import AnalysisType
31+
32+
# Initialize client
33+
client = fastlabel.Client()
34+
35+
# Create predictions
36+
const predictions = [
37+
{
38+
fileKey="sample1.jpg", # file name exists in project
39+
labels=[
40+
{
41+
"value": "line_a", # class value exists in project
42+
"points": [
43+
{ "x": 10, "y": 10 },
44+
{ "x": 20, "y": 20 },
45+
]
46+
},
47+
{
48+
"value": "line_b",
49+
"points": [
50+
{ "x": 30, "y": 30 },
51+
{ "x": 40, "y": 40 },
52+
]
53+
}
54+
]
55+
}
56+
]
57+
58+
# Upload predictions
59+
client.upload_predictions(
60+
project_id="project_id", # your fastlabel project id
61+
analysis_type=AnalysisType.line, # annotation type to be analyze
62+
threshold=20, # IoU percentage/pixel to analyze labels. (Ex: 0 - 100)
63+
predictions=predictions
64+
)
65+
```
66+
67+
## API Docs
68+
69+
Check [this](https://api-fastlabel-production.web.app/api/doc/) for further information.

fastlabel/__init__.py

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
import logging
2+
import os
3+
import requests
4+
from fastlabel.const import AnalysisType
5+
6+
FASTLABEL_ENDPOINT = "https://api-fastlabel-production.web.app/api/v1/"
7+
8+
class Client:
9+
10+
api_key = None
11+
12+
def __init__(self) -> None:
13+
if not os.environ.get('FASTLABEL_API_KEY'):
14+
raise ValueError("FASTLABEL_API_KEY is not configured.")
15+
self.api_key = "Bearer " + os.environ.get('FASTLABEL_API_KEY')
16+
17+
def _getrequest(self, endpoint: str, params=None) -> dict:
18+
"""Makes a get request to an endpoint.
19+
If an error occurs, assumes that endpoint returns JSON as:
20+
{ 'status_code': XXX,
21+
'error': 'I failed' }
22+
"""
23+
params = params or {}
24+
headers = {
25+
"Content-Type": "application/json",
26+
"Authorization": self.api_key,
27+
}
28+
r = requests.get(FASTLABEL_ENDPOINT + endpoint,
29+
headers=headers, params=params)
30+
31+
if r.status_code == 200:
32+
return r.json()
33+
else:
34+
try:
35+
error = r.json()['error']
36+
except ValueError:
37+
error = r.text
38+
if r.status_code == 400:
39+
raise FastLabelInvalidException(error, r.status_code)
40+
else:
41+
raise FastLabelException(error, r.status_code)
42+
43+
def _postrequest(self, endpoint, payload=None):
44+
"""Makes a post request to an endpoint.
45+
If an error occurs, assumes that endpoint returns JSON as:
46+
{ 'status_code': XXX,
47+
'error': 'I failed' }
48+
"""
49+
payload = payload or {}
50+
headers = {
51+
"Content-Type": "application/json",
52+
"Authorization": self.api_key,
53+
}
54+
r = requests.post(FASTLABEL_ENDPOINT + endpoint, json=payload, headers=headers)
55+
56+
if r.status_code == 200:
57+
return r.json()
58+
else:
59+
try:
60+
error = r.json()['error']
61+
except ValueError:
62+
error = r.text
63+
if r.status_code == 400:
64+
raise FastLabelInvalidException(error, r.status_code)
65+
else:
66+
raise FastLabelException(error, r.status_code)
67+
68+
def upload_predictions(self, project_id: str, analysis_type: AnalysisType, threshold: int, predictions: list) -> None:
69+
endpoint = "predictions/upload"
70+
payload = {
71+
"projectId": project_id,
72+
"analysisType": analysis_type,
73+
"threshold": threshold,
74+
"predictions": predictions
75+
}
76+
self._postrequest(endpoint, payload=payload)
77+
logging.info("")
78+
79+
80+
class FastLabelException(Exception):
81+
def __init__(self, message, errcode):
82+
super(FastLabelException, self).__init__(
83+
'<Response [{}]> {}'.format(errcode, message))
84+
self.code = errcode
85+
86+
87+
class FastLabelInvalidException(FastLabelException, ValueError):
88+
pass

fastlabel/const.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class AnalysisType(object):
2+
bbox = "bbox"
3+
line = "line"

pypi_update_guide.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# PyPI Update Guide
2+
3+
_Creating and deploying a new package version is easy_
4+
5+
## Prerequisites
6+
7+
1. Ensure you're on the latest master
8+
9+
2. Ensure you have a PyPI account created and are added as a Collaborator
10+
11+
## Deployment Steps:
12+
13+
**Step 0: Critical - Bump Project Version**
14+
15+
In `setup.py`, you need to specify a new project version.
16+
17+
We use [semantic versioning](https://packaging.python.org/guides/distributing-packages-using-setuptools/#semantic-versioning-preferred). If you are adding a meaningful feature, bump the minor version. If you are fixing a bug, bump the incremental version.
18+
19+
**Step 1: Remove Previous Versions**
20+
21+
Clear out any previously packaged files in the `dist` folder
22+
23+
**Step 2: Create a Source Distribution**
24+
25+
```
26+
python3 setup.py sdist
27+
```
28+
29+
**Step 3: Create `wheel`**
30+
31+
You should also create a wheel for your project. A wheel is a built package that can be installed without needing to go through the “build” process. Installing wheels is substantially faster for the end user than installing from a source distribution
32+
33+
```
34+
python3 setup.py bdist_wheel
35+
```
36+
37+
**Step 4: Install Twine**
38+
39+
Twine is what is used to manage PyPI pacakges
40+
41+
```
42+
pip install twine
43+
```
44+
45+
**Step 5: Upload distribution to PyPI**
46+
47+
```
48+
python3 -m twine upload dist/*
49+
```
50+
51+
**Step 6: Check out the PyPI page to ensure all looks good**
52+
53+
[https://pypi.org/project/fastlabel/](https://pypi.org/project/fastlabel/)

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
requests==2.25.1

setup.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import setuptools
2+
3+
with open("README.md", "r", encoding="utf-8") as file:
4+
long_description = file.read()
5+
6+
with open('requirements.txt', encoding="utf-8") as file:
7+
install_requires = file.read()
8+
9+
setuptools.setup(
10+
name="fastlabel",
11+
version="0.1.0",
12+
author="eisuke-ueta",
13+
author_email="eisuke.ueta@fastlabel.ai",
14+
description="The official Python SDK for FastLabel API, the Data Platform for AI",
15+
long_description=long_description,
16+
long_description_content_type="text/markdown",
17+
packages=setuptools.find_packages(),
18+
install_requires=install_requires,
19+
python_requires='>=3.8',
20+
include_package_data=True)

0 commit comments

Comments
 (0)