oslovision 0.1.0
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.
- checksums.yaml +7 -0
- data/.rspec +3 -0
- data/.vscode/tasks.json +41 -0
- data/CHANGELOG.md +5 -0
- data/CODE_OF_CONDUCT.md +132 -0
- data/LICENSE.txt +21 -0
- data/README.md +151 -0
- data/Rakefile +8 -0
- data/examples/basic_usage.rb +55 -0
- data/lib/oslovision/client.rb +186 -0
- data/lib/oslovision/errors.rb +21 -0
- data/lib/oslovision/version.rb +5 -0
- data/lib/oslovision.rb +22 -0
- data/sig/oslovision.rbs +4 -0
- metadata +132 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: ac1eaffba82453bc8b456c10663e4cfe2c753dd3b586aae78cefbfb32d486a02
|
|
4
|
+
data.tar.gz: 25d86399c1413dbf5739dbb41ea9ba9c505c9f292c1e463be697ac1bda072286
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: e02ef52aeee81f69835429d51e8e75a3ec153e044da88f430351809bd14f2a121250b2fa52c1c9f4795dab1b209bab22bd39ee9fecf0f5724dcca7626bdfb446
|
|
7
|
+
data.tar.gz: 0f760156d8b501481cd20ebd5683fe9feb318b347708c0b6ebd448f7514d12fc498fe7a6792dc6780332c29cbe069b2d4be22d53d82e3c9259abf0d97bbbd52e
|
data/.rspec
ADDED
data/.vscode/tasks.json
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": "2.0.0",
|
|
3
|
+
"tasks": [
|
|
4
|
+
{
|
|
5
|
+
"label": "Run Tests",
|
|
6
|
+
"type": "shell",
|
|
7
|
+
"command": "bundle",
|
|
8
|
+
"args": ["exec", "rspec"],
|
|
9
|
+
"group": "test",
|
|
10
|
+
"problemMatcher": [],
|
|
11
|
+
"isBackground": false
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
"label": "Build Gem",
|
|
15
|
+
"type": "shell",
|
|
16
|
+
"command": "bundle",
|
|
17
|
+
"args": ["exec", "rake", "build"],
|
|
18
|
+
"group": "build",
|
|
19
|
+
"problemMatcher": [],
|
|
20
|
+
"isBackground": false
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
"label": "Install Dependencies",
|
|
24
|
+
"type": "shell",
|
|
25
|
+
"command": "bundle",
|
|
26
|
+
"args": ["install"],
|
|
27
|
+
"group": "build",
|
|
28
|
+
"problemMatcher": [],
|
|
29
|
+
"isBackground": false
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
"label": "Interactive Console",
|
|
33
|
+
"type": "shell",
|
|
34
|
+
"command": "bin/console",
|
|
35
|
+
"args": [],
|
|
36
|
+
"group": "test",
|
|
37
|
+
"problemMatcher": [],
|
|
38
|
+
"isBackground": false
|
|
39
|
+
}
|
|
40
|
+
]
|
|
41
|
+
}
|
data/CHANGELOG.md
ADDED
data/CODE_OF_CONDUCT.md
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
|
2
|
+
|
|
3
|
+
## Our Pledge
|
|
4
|
+
|
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our
|
|
6
|
+
community a harassment-free experience for everyone, regardless of age, body
|
|
7
|
+
size, visible or invisible disability, ethnicity, sex characteristics, gender
|
|
8
|
+
identity and expression, level of experience, education, socio-economic status,
|
|
9
|
+
nationality, personal appearance, race, caste, color, religion, or sexual
|
|
10
|
+
identity and orientation.
|
|
11
|
+
|
|
12
|
+
We pledge to act and interact in ways that contribute to an open, welcoming,
|
|
13
|
+
diverse, inclusive, and healthy community.
|
|
14
|
+
|
|
15
|
+
## Our Standards
|
|
16
|
+
|
|
17
|
+
Examples of behavior that contributes to a positive environment for our
|
|
18
|
+
community include:
|
|
19
|
+
|
|
20
|
+
* Demonstrating empathy and kindness toward other people
|
|
21
|
+
* Being respectful of differing opinions, viewpoints, and experiences
|
|
22
|
+
* Giving and gracefully accepting constructive feedback
|
|
23
|
+
* Accepting responsibility and apologizing to those affected by our mistakes,
|
|
24
|
+
and learning from the experience
|
|
25
|
+
* Focusing on what is best not just for us as individuals, but for the overall
|
|
26
|
+
community
|
|
27
|
+
|
|
28
|
+
Examples of unacceptable behavior include:
|
|
29
|
+
|
|
30
|
+
* The use of sexualized language or imagery, and sexual attention or advances of
|
|
31
|
+
any kind
|
|
32
|
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
|
33
|
+
* Public or private harassment
|
|
34
|
+
* Publishing others' private information, such as a physical or email address,
|
|
35
|
+
without their explicit permission
|
|
36
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
|
37
|
+
professional setting
|
|
38
|
+
|
|
39
|
+
## Enforcement Responsibilities
|
|
40
|
+
|
|
41
|
+
Community leaders are responsible for clarifying and enforcing our standards of
|
|
42
|
+
acceptable behavior and will take appropriate and fair corrective action in
|
|
43
|
+
response to any behavior that they deem inappropriate, threatening, offensive,
|
|
44
|
+
or harmful.
|
|
45
|
+
|
|
46
|
+
Community leaders have the right and responsibility to remove, edit, or reject
|
|
47
|
+
comments, commits, code, wiki edits, issues, and other contributions that are
|
|
48
|
+
not aligned to this Code of Conduct, and will communicate reasons for moderation
|
|
49
|
+
decisions when appropriate.
|
|
50
|
+
|
|
51
|
+
## Scope
|
|
52
|
+
|
|
53
|
+
This Code of Conduct applies within all community spaces, and also applies when
|
|
54
|
+
an individual is officially representing the community in public spaces.
|
|
55
|
+
Examples of representing our community include using an official email address,
|
|
56
|
+
posting via an official social media account, or acting as an appointed
|
|
57
|
+
representative at an online or offline event.
|
|
58
|
+
|
|
59
|
+
## Enforcement
|
|
60
|
+
|
|
61
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
|
62
|
+
reported to the community leaders responsible for enforcement at
|
|
63
|
+
[INSERT CONTACT METHOD].
|
|
64
|
+
All complaints will be reviewed and investigated promptly and fairly.
|
|
65
|
+
|
|
66
|
+
All community leaders are obligated to respect the privacy and security of the
|
|
67
|
+
reporter of any incident.
|
|
68
|
+
|
|
69
|
+
## Enforcement Guidelines
|
|
70
|
+
|
|
71
|
+
Community leaders will follow these Community Impact Guidelines in determining
|
|
72
|
+
the consequences for any action they deem in violation of this Code of Conduct:
|
|
73
|
+
|
|
74
|
+
### 1. Correction
|
|
75
|
+
|
|
76
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed
|
|
77
|
+
unprofessional or unwelcome in the community.
|
|
78
|
+
|
|
79
|
+
**Consequence**: A private, written warning from community leaders, providing
|
|
80
|
+
clarity around the nature of the violation and an explanation of why the
|
|
81
|
+
behavior was inappropriate. A public apology may be requested.
|
|
82
|
+
|
|
83
|
+
### 2. Warning
|
|
84
|
+
|
|
85
|
+
**Community Impact**: A violation through a single incident or series of
|
|
86
|
+
actions.
|
|
87
|
+
|
|
88
|
+
**Consequence**: A warning with consequences for continued behavior. No
|
|
89
|
+
interaction with the people involved, including unsolicited interaction with
|
|
90
|
+
those enforcing the Code of Conduct, for a specified period of time. This
|
|
91
|
+
includes avoiding interactions in community spaces as well as external channels
|
|
92
|
+
like social media. Violating these terms may lead to a temporary or permanent
|
|
93
|
+
ban.
|
|
94
|
+
|
|
95
|
+
### 3. Temporary Ban
|
|
96
|
+
|
|
97
|
+
**Community Impact**: A serious violation of community standards, including
|
|
98
|
+
sustained inappropriate behavior.
|
|
99
|
+
|
|
100
|
+
**Consequence**: A temporary ban from any sort of interaction or public
|
|
101
|
+
communication with the community for a specified period of time. No public or
|
|
102
|
+
private interaction with the people involved, including unsolicited interaction
|
|
103
|
+
with those enforcing the Code of Conduct, is allowed during this period.
|
|
104
|
+
Violating these terms may lead to a permanent ban.
|
|
105
|
+
|
|
106
|
+
### 4. Permanent Ban
|
|
107
|
+
|
|
108
|
+
**Community Impact**: Demonstrating a pattern of violation of community
|
|
109
|
+
standards, including sustained inappropriate behavior, harassment of an
|
|
110
|
+
individual, or aggression toward or disparagement of classes of individuals.
|
|
111
|
+
|
|
112
|
+
**Consequence**: A permanent ban from any sort of public interaction within the
|
|
113
|
+
community.
|
|
114
|
+
|
|
115
|
+
## Attribution
|
|
116
|
+
|
|
117
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
|
118
|
+
version 2.1, available at
|
|
119
|
+
[https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
|
|
120
|
+
|
|
121
|
+
Community Impact Guidelines were inspired by
|
|
122
|
+
[Mozilla's code of conduct enforcement ladder][Mozilla CoC].
|
|
123
|
+
|
|
124
|
+
For answers to common questions about this code of conduct, see the FAQ at
|
|
125
|
+
[https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
|
|
126
|
+
[https://www.contributor-covenant.org/translations][translations].
|
|
127
|
+
|
|
128
|
+
[homepage]: https://www.contributor-covenant.org
|
|
129
|
+
[v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
|
|
130
|
+
[Mozilla CoC]: https://github.com/mozilla/diversity
|
|
131
|
+
[FAQ]: https://www.contributor-covenant.org/faq
|
|
132
|
+
[translations]: https://www.contributor-covenant.org/translations
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Alastair Brunton
|
|
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
|
|
13
|
+
all 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
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
# OsloVision Ruby Client
|
|
2
|
+
|
|
3
|
+

|
|
4
|
+
|
|
5
|
+
<p align="center">
|
|
6
|
+
<a href="https://oslo.vision">oslo.vision</a> •
|
|
7
|
+
<a href="https://github.com/OsloVision/training-notebooks">training notebooks</a> •
|
|
8
|
+
<a href="https://github.com/OsloVision/oslovision-ruby">ruby sdk</a> •
|
|
9
|
+
<a href="https://oslo.vision/blog">blog</a>
|
|
10
|
+
</p>
|
|
11
|
+
|
|
12
|
+
This Ruby gem provides a client for interacting with the Oslo API, a platform for creating and managing datasets for machine learning projects. The client allows you to easily upload images, create annotations, and download dataset exports.
|
|
13
|
+
|
|
14
|
+
## Features
|
|
15
|
+
|
|
16
|
+
- Simple interface for interacting with the Oslo API
|
|
17
|
+
- Support for adding images to projects
|
|
18
|
+
- Creation of annotations for images
|
|
19
|
+
- Downloading of dataset exports
|
|
20
|
+
- Automatic handling of authentication
|
|
21
|
+
- Comprehensive error handling
|
|
22
|
+
|
|
23
|
+
## Installation
|
|
24
|
+
|
|
25
|
+
Add this line to your application's Gemfile:
|
|
26
|
+
|
|
27
|
+
```ruby
|
|
28
|
+
gem 'oslovision'
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
And then execute:
|
|
32
|
+
|
|
33
|
+
$ bundle install
|
|
34
|
+
|
|
35
|
+
Or install it yourself as:
|
|
36
|
+
|
|
37
|
+
$ gem install oslovision
|
|
38
|
+
|
|
39
|
+
## Usage
|
|
40
|
+
|
|
41
|
+
Here's a quick example of how to use the Oslo API client:
|
|
42
|
+
|
|
43
|
+
```ruby
|
|
44
|
+
require 'oslovision'
|
|
45
|
+
|
|
46
|
+
# Initialize the client
|
|
47
|
+
api = Oslovision.new("your_api_token_here")
|
|
48
|
+
|
|
49
|
+
# Test the API connection
|
|
50
|
+
puts api.test_api
|
|
51
|
+
|
|
52
|
+
# Add an image to a project
|
|
53
|
+
File.open("image.jpg", "rb") do |img_file|
|
|
54
|
+
image_data = api.add_image("your_project_identifier", img_file)
|
|
55
|
+
puts "Added image: #{image_data['id']}"
|
|
56
|
+
|
|
57
|
+
# Create an annotation
|
|
58
|
+
annotation = api.create_annotation(
|
|
59
|
+
"your_project_identifier",
|
|
60
|
+
image_data['id'],
|
|
61
|
+
"cat",
|
|
62
|
+
x0: 10,
|
|
63
|
+
y0: 20,
|
|
64
|
+
width_px: 100,
|
|
65
|
+
height_px: 150
|
|
66
|
+
)
|
|
67
|
+
puts "Created annotation: #{annotation['id']}"
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
# Download an export
|
|
71
|
+
download_path = api.download_export("your_project_identifier", 1)
|
|
72
|
+
puts "Export downloaded to: #{download_path}"
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## API Reference
|
|
76
|
+
|
|
77
|
+
### Oslovision.new(token, base_url: "https://app.oslo.vision/api/v1")
|
|
78
|
+
|
|
79
|
+
Initialize the Oslo API client.
|
|
80
|
+
|
|
81
|
+
- `token`: Your Oslo API authentication token
|
|
82
|
+
- `base_url`: The base URL of the Oslo API (optional)
|
|
83
|
+
|
|
84
|
+
### Methods
|
|
85
|
+
|
|
86
|
+
#### #test_api
|
|
87
|
+
|
|
88
|
+
Test if the API is up and running and the token is valid.
|
|
89
|
+
|
|
90
|
+
Returns a hash with the API test response.
|
|
91
|
+
|
|
92
|
+
#### #add_image(project_identifier, image, split: "train", status: "pending")
|
|
93
|
+
|
|
94
|
+
Add an image to a project.
|
|
95
|
+
|
|
96
|
+
- `project_identifier`: The ID of the project to add the image to
|
|
97
|
+
- `image`: Either a file object, file path string, or URL string of the image
|
|
98
|
+
- `split`: The dataset split for the image (default: "train")
|
|
99
|
+
- `status`: The status of the image (default: "pending")
|
|
100
|
+
|
|
101
|
+
Returns a hash with the added image's data.
|
|
102
|
+
|
|
103
|
+
#### #create_annotation(project_identifier, image_identifier, label, x0:, y0:, width_px:, height_px:)
|
|
104
|
+
|
|
105
|
+
Create a new annotation for an image.
|
|
106
|
+
|
|
107
|
+
- `project_identifier`: The ID of the project
|
|
108
|
+
- `image_identifier`: The ID of the image to annotate
|
|
109
|
+
- `label`: The label for the annotation
|
|
110
|
+
- `x0`, `y0`: The top-left coordinates of the bounding box
|
|
111
|
+
- `width_px`, `height_px`: The width and height of the bounding box in pixels
|
|
112
|
+
|
|
113
|
+
Returns a hash with the created annotation's data.
|
|
114
|
+
|
|
115
|
+
#### #download_export(project_identifier, version, output_dir: ".")
|
|
116
|
+
|
|
117
|
+
Download a dataset export and extract from the zip file.
|
|
118
|
+
|
|
119
|
+
- `project_identifier`: The ID of the project
|
|
120
|
+
- `version`: The version number of the export
|
|
121
|
+
- `output_dir`: The directory to save the downloaded files (default: current directory)
|
|
122
|
+
|
|
123
|
+
Returns the path to the downloaded export directory.
|
|
124
|
+
|
|
125
|
+
## Error Handling
|
|
126
|
+
|
|
127
|
+
The gem provides specific error classes for different types of failures:
|
|
128
|
+
|
|
129
|
+
- `Oslovision::AuthenticationError` - Invalid API token
|
|
130
|
+
- `Oslovision::NotFoundError` - Resource not found
|
|
131
|
+
- `Oslovision::ClientError` - Client-side errors (4xx HTTP status codes)
|
|
132
|
+
- `Oslovision::ServerError` - Server-side errors (5xx HTTP status codes)
|
|
133
|
+
- `Oslovision::APIError` - General API errors
|
|
134
|
+
|
|
135
|
+
## Development
|
|
136
|
+
|
|
137
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
|
138
|
+
|
|
139
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
|
140
|
+
|
|
141
|
+
## Contributing
|
|
142
|
+
|
|
143
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/OsloVision/oslovision-ruby. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/OsloVision/oslovision-ruby/blob/main/CODE_OF_CONDUCT.md).
|
|
144
|
+
|
|
145
|
+
## License
|
|
146
|
+
|
|
147
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
|
148
|
+
|
|
149
|
+
## Code of Conduct
|
|
150
|
+
|
|
151
|
+
Everyone interacting in the Oslovision project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/OsloVision/oslovision-ruby/blob/main/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
# Example usage of the OsloVision Ruby client
|
|
5
|
+
# Run this file with: ruby examples/basic_usage.rb
|
|
6
|
+
|
|
7
|
+
require_relative "../lib/oslovision"
|
|
8
|
+
|
|
9
|
+
# You would replace this with your actual API token
|
|
10
|
+
API_TOKEN = ENV["OSLO_API_TOKEN"] || "your_api_token_here"
|
|
11
|
+
PROJECT_ID = "your_project_identifier"
|
|
12
|
+
|
|
13
|
+
# Initialize the client
|
|
14
|
+
puts "Initializing OsloVision client..."
|
|
15
|
+
client = Oslovision.new(API_TOKEN)
|
|
16
|
+
|
|
17
|
+
begin
|
|
18
|
+
# Test the API connection
|
|
19
|
+
puts "Testing API connection..."
|
|
20
|
+
result = client.test_api
|
|
21
|
+
puts "API Test Result: #{result}"
|
|
22
|
+
|
|
23
|
+
# Example: Add an image from URL
|
|
24
|
+
puts "\nAdding image from URL..."
|
|
25
|
+
image_url = "https://example.com/sample-image.jpg"
|
|
26
|
+
# Uncomment the following lines to actually make API calls:
|
|
27
|
+
# image_data = client.add_image(PROJECT_ID, image_url)
|
|
28
|
+
# puts "Added image: #{image_data['id']}"
|
|
29
|
+
|
|
30
|
+
# Example: Create an annotation
|
|
31
|
+
# annotation = client.create_annotation(
|
|
32
|
+
# PROJECT_ID,
|
|
33
|
+
# image_data['id'],
|
|
34
|
+
# "cat",
|
|
35
|
+
# x0: 10,
|
|
36
|
+
# y0: 20,
|
|
37
|
+
# width_px: 100,
|
|
38
|
+
# height_px: 150
|
|
39
|
+
# )
|
|
40
|
+
# puts "Created annotation: #{annotation['id']}"
|
|
41
|
+
|
|
42
|
+
# Example: Download an export
|
|
43
|
+
# download_path = client.download_export(PROJECT_ID, 1)
|
|
44
|
+
# puts "Export downloaded to: #{download_path}"
|
|
45
|
+
|
|
46
|
+
rescue Oslovision::AuthenticationError => e
|
|
47
|
+
puts "Authentication failed: #{e.message}"
|
|
48
|
+
puts "Please check your API token."
|
|
49
|
+
rescue Oslovision::APIError => e
|
|
50
|
+
puts "API error occurred: #{e.message}"
|
|
51
|
+
rescue => e
|
|
52
|
+
puts "An error occurred: #{e.message}"
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
puts "\nExample completed!"
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "httparty"
|
|
4
|
+
require "mime/types"
|
|
5
|
+
require "json"
|
|
6
|
+
require "fileutils"
|
|
7
|
+
require "zip"
|
|
8
|
+
require "stringio"
|
|
9
|
+
|
|
10
|
+
module Oslovision
|
|
11
|
+
# Main client class for interacting with the Oslo API
|
|
12
|
+
class Client
|
|
13
|
+
include HTTParty
|
|
14
|
+
|
|
15
|
+
# Initialize the Oslo API client
|
|
16
|
+
#
|
|
17
|
+
# @param token [String] Your Oslo API authentication token
|
|
18
|
+
# @param base_url [String] The base URL of the Oslo API
|
|
19
|
+
def initialize(token, base_url: "https://app.oslo.vision/api/v1")
|
|
20
|
+
@token = token
|
|
21
|
+
@base_url = base_url
|
|
22
|
+
self.class.base_uri base_url
|
|
23
|
+
self.class.headers "Authorization" => "Bearer #{token}"
|
|
24
|
+
self.class.headers "User-Agent" => "oslovision-ruby/#{Oslovision::VERSION}"
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
# Test if the API is up and running and the token is valid
|
|
28
|
+
#
|
|
29
|
+
# @return [Hash] Response from the API test endpoint
|
|
30
|
+
# @raise [Oslovision::APIError] If the API request fails
|
|
31
|
+
def test_api
|
|
32
|
+
response = self.class.get("/test")
|
|
33
|
+
handle_response(response)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# Add an image to a project
|
|
37
|
+
#
|
|
38
|
+
# @param project_identifier [String] The ID of the project to add the image to
|
|
39
|
+
# @param image [String, File, IO] Either a file path, file object, or URL string of the image
|
|
40
|
+
# @param split [String] The dataset split for the image (default: "train")
|
|
41
|
+
# @param status [String] The status of the image (default: "pending")
|
|
42
|
+
# @return [Hash] Response containing the added image's data
|
|
43
|
+
# @raise [Oslovision::APIError] If the API request fails
|
|
44
|
+
def add_image(project_identifier, image, split: "train", status: "pending")
|
|
45
|
+
if image.is_a?(String) && (image.start_with?("http://") || image.start_with?("https://"))
|
|
46
|
+
# Handle URL
|
|
47
|
+
body = {
|
|
48
|
+
url: image,
|
|
49
|
+
split: split,
|
|
50
|
+
status: status
|
|
51
|
+
}
|
|
52
|
+
response = self.class.post("/projects/#{project_identifier}/images", body: body)
|
|
53
|
+
else
|
|
54
|
+
# Handle file upload
|
|
55
|
+
file_data = prepare_file_data(image)
|
|
56
|
+
body = {
|
|
57
|
+
file: file_data,
|
|
58
|
+
split: split,
|
|
59
|
+
status: status
|
|
60
|
+
}
|
|
61
|
+
response = self.class.post("/projects/#{project_identifier}/images", body: body)
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
handle_response(response)
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
# Create a new annotation for an image
|
|
68
|
+
#
|
|
69
|
+
# @param project_identifier [String] The ID of the project
|
|
70
|
+
# @param image_identifier [String] The ID of the image to annotate
|
|
71
|
+
# @param label [String] The label for the annotation
|
|
72
|
+
# @param x0 [Float] The x-coordinate of the top-left corner of the bounding box
|
|
73
|
+
# @param y0 [Float] The y-coordinate of the top-left corner of the bounding box
|
|
74
|
+
# @param width_px [Float] The width of the bounding box in pixels
|
|
75
|
+
# @param height_px [Float] The height of the bounding box in pixels
|
|
76
|
+
# @return [Hash] Response containing the created annotation's data
|
|
77
|
+
# @raise [Oslovision::APIError] If the API request fails
|
|
78
|
+
def create_annotation(project_identifier, image_identifier, label, x0:, y0:, width_px:, height_px:)
|
|
79
|
+
body = {
|
|
80
|
+
image_id: image_identifier,
|
|
81
|
+
label: label,
|
|
82
|
+
x0: x0,
|
|
83
|
+
y0: y0,
|
|
84
|
+
width_px: width_px,
|
|
85
|
+
height_px: height_px
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
response = self.class.post("/projects/#{project_identifier}/annotations",
|
|
89
|
+
body: body.to_json,
|
|
90
|
+
headers: { "Content-Type" => "application/json" })
|
|
91
|
+
handle_response(response)
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
# Download a dataset export and extract from the zip file
|
|
95
|
+
#
|
|
96
|
+
# @param project_identifier [String] The ID of the project
|
|
97
|
+
# @param version [Integer] The version number of the export
|
|
98
|
+
# @param output_dir [String] The directory to save the downloaded files (default: current directory)
|
|
99
|
+
# @return [String] The path to the downloaded export directory
|
|
100
|
+
# @raise [Oslovision::APIError] If the API request fails
|
|
101
|
+
def download_export(project_identifier, version, output_dir: ".")
|
|
102
|
+
response = self.class.get("/projects/#{project_identifier}/exports/#{version}/download")
|
|
103
|
+
|
|
104
|
+
if response.success?
|
|
105
|
+
zip_path = File.join(output_dir, "#{project_identifier}_v#{version}.zip")
|
|
106
|
+
extract_path = File.join(output_dir, "#{project_identifier}_v#{version}")
|
|
107
|
+
|
|
108
|
+
# Write the zip file
|
|
109
|
+
File.open(zip_path, "wb") do |file|
|
|
110
|
+
file.write(response.body)
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
# Extract the zip file
|
|
114
|
+
extract_zip(zip_path, extract_path)
|
|
115
|
+
|
|
116
|
+
# Clean up the zip file
|
|
117
|
+
File.delete(zip_path)
|
|
118
|
+
|
|
119
|
+
extract_path
|
|
120
|
+
else
|
|
121
|
+
handle_response(response)
|
|
122
|
+
end
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
private
|
|
126
|
+
|
|
127
|
+
# Handle API response and raise appropriate errors
|
|
128
|
+
#
|
|
129
|
+
# @param response [HTTParty::Response] The HTTP response object
|
|
130
|
+
# @return [Hash] The parsed response body
|
|
131
|
+
# @raise [Oslovision::APIError] If the response indicates an error
|
|
132
|
+
def handle_response(response)
|
|
133
|
+
case response.code
|
|
134
|
+
when 200..299
|
|
135
|
+
if response.parsed_response.is_a?(String)
|
|
136
|
+
JSON.parse(response.parsed_response)
|
|
137
|
+
else
|
|
138
|
+
response.parsed_response
|
|
139
|
+
end
|
|
140
|
+
when 401
|
|
141
|
+
raise Oslovision::AuthenticationError, "Invalid API token"
|
|
142
|
+
when 404
|
|
143
|
+
raise Oslovision::NotFoundError, "Resource not found"
|
|
144
|
+
when 400..499
|
|
145
|
+
error_message = response.parsed_response&.dig("error") || "Client error"
|
|
146
|
+
raise Oslovision::ClientError, error_message
|
|
147
|
+
when 500..599
|
|
148
|
+
raise Oslovision::ServerError, "Server error occurred"
|
|
149
|
+
else
|
|
150
|
+
raise Oslovision::APIError, "Unexpected response code: #{response.code}"
|
|
151
|
+
end
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
# Prepare file data for upload
|
|
155
|
+
#
|
|
156
|
+
# @param image [String, File, IO] The image file or path
|
|
157
|
+
# @return [File, IO] The file object ready for upload
|
|
158
|
+
def prepare_file_data(image)
|
|
159
|
+
case image
|
|
160
|
+
when String
|
|
161
|
+
# Assume it's a file path
|
|
162
|
+
File.open(image, "rb")
|
|
163
|
+
when File, IO, StringIO
|
|
164
|
+
image
|
|
165
|
+
else
|
|
166
|
+
raise ArgumentError, "Invalid image type. Expected String (file path), File, or IO object"
|
|
167
|
+
end
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
# Extract a zip file to a directory
|
|
171
|
+
#
|
|
172
|
+
# @param zip_path [String] Path to the zip file
|
|
173
|
+
# @param extract_path [String] Directory to extract to
|
|
174
|
+
def extract_zip(zip_path, extract_path)
|
|
175
|
+
FileUtils.mkdir_p(extract_path)
|
|
176
|
+
|
|
177
|
+
Zip::File.open(zip_path) do |zip_file|
|
|
178
|
+
zip_file.each do |entry|
|
|
179
|
+
entry_path = File.join(extract_path, entry.name)
|
|
180
|
+
FileUtils.mkdir_p(File.dirname(entry_path))
|
|
181
|
+
entry.extract(entry_path)
|
|
182
|
+
end
|
|
183
|
+
end
|
|
184
|
+
end
|
|
185
|
+
end
|
|
186
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Oslovision
|
|
4
|
+
# Base error class for all OsloVision-related errors
|
|
5
|
+
class Error < StandardError; end
|
|
6
|
+
|
|
7
|
+
# Error raised when API requests fail
|
|
8
|
+
class APIError < Error; end
|
|
9
|
+
|
|
10
|
+
# Error raised when authentication fails
|
|
11
|
+
class AuthenticationError < APIError; end
|
|
12
|
+
|
|
13
|
+
# Error raised when a resource is not found
|
|
14
|
+
class NotFoundError < APIError; end
|
|
15
|
+
|
|
16
|
+
# Error raised for client-side errors (4xx HTTP status codes)
|
|
17
|
+
class ClientError < APIError; end
|
|
18
|
+
|
|
19
|
+
# Error raised for server-side errors (5xx HTTP status codes)
|
|
20
|
+
class ServerError < APIError; end
|
|
21
|
+
end
|
data/lib/oslovision.rb
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "oslovision/version"
|
|
4
|
+
require_relative "oslovision/client"
|
|
5
|
+
require_relative "oslovision/errors"
|
|
6
|
+
|
|
7
|
+
# OsloVision Ruby Client
|
|
8
|
+
#
|
|
9
|
+
# This module provides a Ruby client for interacting with the Oslo API,
|
|
10
|
+
# a platform for creating and managing datasets for machine learning projects.
|
|
11
|
+
module Oslovision
|
|
12
|
+
class Error < StandardError; end
|
|
13
|
+
|
|
14
|
+
# Create a new OsloVision client instance
|
|
15
|
+
#
|
|
16
|
+
# @param token [String] Your Oslo API authentication token
|
|
17
|
+
# @param base_url [String] The base URL of the Oslo API (default: "https://app.oslo.vision/api/v1")
|
|
18
|
+
# @return [Oslovision::Client] A new client instance
|
|
19
|
+
def self.new(token, base_url: "https://app.oslo.vision/api/v1")
|
|
20
|
+
Client.new(token, base_url: base_url)
|
|
21
|
+
end
|
|
22
|
+
end
|
data/sig/oslovision.rbs
ADDED
metadata
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: oslovision
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Alastair Brunton
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2025-07-16 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: httparty
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: 0.22.0
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: 0.22.0
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: mime-types
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '3.0'
|
|
34
|
+
type: :runtime
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '3.0'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: rubyzip
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - "~>"
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '2.3'
|
|
48
|
+
type: :runtime
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - "~>"
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '2.3'
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: webmock
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - "~>"
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '3.20'
|
|
62
|
+
type: :development
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - "~>"
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: '3.20'
|
|
69
|
+
- !ruby/object:Gem::Dependency
|
|
70
|
+
name: vcr
|
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
|
72
|
+
requirements:
|
|
73
|
+
- - "~>"
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
version: '6.2'
|
|
76
|
+
type: :development
|
|
77
|
+
prerelease: false
|
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
79
|
+
requirements:
|
|
80
|
+
- - "~>"
|
|
81
|
+
- !ruby/object:Gem::Version
|
|
82
|
+
version: '6.2'
|
|
83
|
+
description: A Ruby gem providing a client for interacting with the Oslo API, a platform
|
|
84
|
+
for creating and managing datasets for machine learning projects. The client allows
|
|
85
|
+
you to easily upload images, create annotations, and download dataset exports.
|
|
86
|
+
email:
|
|
87
|
+
- support@oslo.vision
|
|
88
|
+
executables: []
|
|
89
|
+
extensions: []
|
|
90
|
+
extra_rdoc_files: []
|
|
91
|
+
files:
|
|
92
|
+
- ".rspec"
|
|
93
|
+
- ".vscode/tasks.json"
|
|
94
|
+
- CHANGELOG.md
|
|
95
|
+
- CODE_OF_CONDUCT.md
|
|
96
|
+
- LICENSE.txt
|
|
97
|
+
- README.md
|
|
98
|
+
- Rakefile
|
|
99
|
+
- examples/basic_usage.rb
|
|
100
|
+
- lib/oslovision.rb
|
|
101
|
+
- lib/oslovision/client.rb
|
|
102
|
+
- lib/oslovision/errors.rb
|
|
103
|
+
- lib/oslovision/version.rb
|
|
104
|
+
- sig/oslovision.rbs
|
|
105
|
+
homepage: https://oslo.vision
|
|
106
|
+
licenses:
|
|
107
|
+
- MIT
|
|
108
|
+
metadata:
|
|
109
|
+
allowed_push_host: https://rubygems.org
|
|
110
|
+
homepage_uri: https://oslo.vision
|
|
111
|
+
source_code_uri: https://github.com/OsloVision/oslovision-ruby
|
|
112
|
+
changelog_uri: https://github.com/OsloVision/oslovision-ruby/blob/main/CHANGELOG.md
|
|
113
|
+
post_install_message:
|
|
114
|
+
rdoc_options: []
|
|
115
|
+
require_paths:
|
|
116
|
+
- lib
|
|
117
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
118
|
+
requirements:
|
|
119
|
+
- - ">="
|
|
120
|
+
- !ruby/object:Gem::Version
|
|
121
|
+
version: 3.1.0
|
|
122
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
123
|
+
requirements:
|
|
124
|
+
- - ">="
|
|
125
|
+
- !ruby/object:Gem::Version
|
|
126
|
+
version: '0'
|
|
127
|
+
requirements: []
|
|
128
|
+
rubygems_version: 3.4.19
|
|
129
|
+
signing_key:
|
|
130
|
+
specification_version: 4
|
|
131
|
+
summary: Ruby client for the OsloVision API
|
|
132
|
+
test_files: []
|