deepstack 0.0.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6bd245c6bb369aed6c65f88277a186cd283d396b5eeafa28bc10e854dfbd027c
4
- data.tar.gz: b428c594d92837534124004c0ff0ef4f0b0c2aad0a2cf40ef4faa69f38d904d3
3
+ metadata.gz: dc0409e409422c065962aa065244f20658c764c904462935936b05c1950e771a
4
+ data.tar.gz: 074e0f2e9f309f72aaa402ef5e1b3bd469da172bbb60679a2a59b218f4a2a7ac
5
5
  SHA512:
6
- metadata.gz: 1f4d4c306447142dd071a6a4a28ce8f36f2170cf23160401e7cbf1786d9b8124e9c72e1a144c13096b62ad03a361fe4684f0aa8d9fab4aee0b921017ed0fff8c
7
- data.tar.gz: 2a7c706fbfe815f7faf5ce06294f1eff65c2c9aeec3cdddb865e97348475cf1ee3478b9152444e4a92ae3697eeae3ad4e97a1fd47edff3247578eae52b340953
6
+ metadata.gz: '0923fd828175f78a7bc90a40623c6ed7ec8ce8681876ab340697309c9557bdbf2551f10567b4df4dd861c2121e2cd37c62b47f06803e08f8cc0b1a5739e68d89'
7
+ data.tar.gz: b9be9f1439d69f939f2dbf66842264a750e47d8cba455ff528b7879f115f3510e45690f8ff7a804e1b23428a5313c44c147049b3bcc269db31b4887f7c03b34e
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Deepstack
3
+ module DeepStackModule
4
4
  # Custom Model
5
5
  module Custom
6
6
  #
@@ -28,9 +28,9 @@ module Deepstack
28
28
  #
29
29
  # @param [String] model custom model name
30
30
  # @param [Object] image binary data or a File object
31
- # @param [Hash] options additional fields for Deepstack, e.g. min_confidence: 0.5
31
+ # @param [Hash] options additional fields for DeepStack, e.g. min_confidence: 0.5
32
32
  #
33
- # @return [Array] if successful, an array of Deepstack predictions
33
+ # @return [Array] if successful, an array of DeepStack predictions
34
34
  #
35
35
  # @return [nil] if error
36
36
  #
@@ -1,13 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Deepstack
3
+ module DeepStackModule
4
4
  # APIs related to object detection
5
5
  module Detection
6
6
  #
7
7
  # Perform object detection
8
8
  #
9
9
  # @param [Object] image raw image data or a File object of an image file
10
- # @param [Hash] options additional fields for Deepstack, e.g. min_confidence: 0.5
10
+ # @param [Hash] options additional fields for DeepStack, e.g. min_confidence: 0.5
11
11
  #
12
12
  # @return [Array] a list of predictions, or nil on error
13
13
  #
@@ -1,15 +1,15 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Deepstack
3
+ module DeepStackModule
4
4
  # APIs related to face recognition
5
5
  module Face
6
6
  #
7
7
  # Perform face recognition
8
8
  #
9
9
  # @param [Object] image binary data or a File object
10
- # @param [Hash] options additional fields for Deepstack, e.g. min_confidence: 0.5
10
+ # @param [Hash] options additional fields for DeepStack, e.g. min_confidence: 0.5
11
11
  #
12
- # @return [Array] if successful, an array of Deepstack predictions
12
+ # @return [Array] if successful, an array of DeepStack predictions
13
13
  #
14
14
  # @return [nil] if error
15
15
  #
@@ -23,9 +23,9 @@ module Deepstack
23
23
  # Detect faces in an image
24
24
  #
25
25
  # @param [Object] image binary data or a File object
26
- # @param [Hash] options additional fields for Deepstack, e.g. min_confidence: 0.5
26
+ # @param [Hash] options additional fields for DeepStack, e.g. min_confidence: 0.5
27
27
  #
28
- # @return [Array] if successful, an array of Deepstack predictions
28
+ # @return [Array] if successful, an array of DeepStack predictions
29
29
  #
30
30
  def detect_faces(image, **options)
31
31
  target = 'vision/face/' # the URL ends with a slash
@@ -1,15 +1,15 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Deepstack
3
+ module DeepStackModule
4
4
  # Scene Recognition
5
5
  module Scene
6
6
  #
7
7
  # Return
8
8
  #
9
9
  # @param [Object] image binary data or a File object
10
- # @param [Hash] options additional fields for Deepstack, e.g. min_confidence: 0.5
10
+ # @param [Hash] options additional fields for DeepStack, e.g. min_confidence: 0.5
11
11
  #
12
- # @return [Hash] if successful, Deepstack result hash {'label' => 'scene', 'confidence' => 2.2}
12
+ # @return [Hash] if successful, DeepStack result hash {'label' => 'scene', 'confidence' => 2.2}
13
13
  #
14
14
  # @return [nil] if error
15
15
  def identify_scene(image, **options)
@@ -3,7 +3,7 @@
3
3
  #
4
4
  # Holds project version constant
5
5
  #
6
- module Deepstack
7
- # @return [String] Version of Deepstack helper libraries
8
- VERSION = '0.0.1'
6
+ class DeepStack
7
+ # @return [String] Version of DeepStack helper libraries
8
+ VERSION = '1.0.0'
9
9
  end
data/lib/deepstack.rb CHANGED
@@ -9,103 +9,101 @@ require_relative 'deepstack/scene'
9
9
  require_relative 'deepstack/custom'
10
10
  require_relative 'deepstack/version'
11
11
 
12
- module Deepstack
13
- # Deepstack API
14
- class API
15
- include Deepstack::Face
16
- include Deepstack::Detection
17
- include Deepstack::Scene
18
- include Deepstack::Custom
19
-
20
- attr_reader :duration, :predictions, :success
21
-
22
- # Create a deepstack object connected to the given URL
23
- def initialize(base_url)
24
- @base_url = base_url
25
- end
12
+ # DeepStack API
13
+ class DeepStack
14
+ include DeepStackModule::Face
15
+ include DeepStackModule::Detection
16
+ include DeepStackModule::Scene
17
+ include DeepStackModule::Custom
18
+
19
+ attr_reader :duration, :predictions, :success
20
+
21
+ # Create a deepstack object connected to the given URL
22
+ def initialize(base_url)
23
+ @base_url = base_url
24
+ end
26
25
 
27
- #
28
- # The result of the last call
29
- #
30
- # @return [Boolean] true if the last call was successful
31
- #
32
- def success?
33
- @success == true
34
- end
26
+ #
27
+ # The result of the last call
28
+ #
29
+ # @return [Boolean] true if the last call was successful
30
+ #
31
+ def success?
32
+ @success == true
33
+ end
35
34
 
36
- #
37
- # Make a POST request to Deepstack path target
38
- #
39
- # @param [String] path to the Deepstack API URL
40
- # @param [Array] images zero or more images to post
41
- # @param [Hash] args additional named fields to post
42
- #
43
- # @return [Hash] if successful, the json data returned by Deepstack, nil otherwise
44
- #
45
- def api_post(path, *images, **args)
46
- uri = build_uri(path)
47
-
48
- result = nil
49
- 10.times do
50
- result = images ? post_files(uri, images.flatten, **args) : post(uri, args)
51
- break unless result.is_a?(Net::HTTPRedirection)
52
-
53
- uri.path = result['location']
54
- end
55
- raise Net::HTTPClientException, 'Too many redirections' if result.is_a?(Net::HTTPRedirection)
56
-
57
- process_result(result)
35
+ #
36
+ # Make a POST request to DeepStack path target
37
+ #
38
+ # @param [String] path to the DeepStack API URL
39
+ # @param [Array] images zero or more images to post
40
+ # @param [Hash] args additional named fields to post
41
+ #
42
+ # @return [Hash] if successful, the json data returned by DeepStack, nil otherwise
43
+ #
44
+ def api_post(path, *images, **args)
45
+ uri = build_uri(path)
46
+
47
+ result = nil
48
+ 10.times do
49
+ result = images ? post_files(uri, images.flatten, **args) : post(uri, args)
50
+ break unless result.is_a?(Net::HTTPRedirection)
51
+
52
+ uri.path = result['location']
58
53
  end
54
+ raise Net::HTTPClientException, 'Too many redirections' if result.is_a?(Net::HTTPRedirection)
59
55
 
60
- private
56
+ process_result(result)
57
+ end
61
58
 
62
- def build_uri(path)
63
- URI.join(@base_url, '/v1/', path)
64
- end
59
+ private
65
60
 
66
- def post(uri, **args)
67
- Net::HTTP.post_form(uri, args)
68
- end
61
+ def build_uri(path)
62
+ URI.join(@base_url, '/v1/', path)
63
+ end
69
64
 
70
- def post_files(uri, *images, **args)
71
- form_data = combine_images_and_args(images.flatten, **args)
72
- req = Net::HTTP::Post.new(uri)
73
- req.set_form(form_data, 'multipart/form-data')
74
- Net::HTTP.start(uri.hostname, uri.port) { |http| http.request(req) }
75
- end
65
+ def post(uri, **args)
66
+ Net::HTTP.post_form(uri, args)
67
+ end
76
68
 
77
- def combine_images_and_args(*images, **args)
78
- stringify_keys(args).concat(image_form_data(images.flatten))
79
- end
69
+ def post_files(uri, *images, **args)
70
+ form_data = combine_images_and_args(images.flatten, **args)
71
+ req = Net::HTTP::Post.new(uri)
72
+ req.set_form(form_data, 'multipart/form-data')
73
+ Net::HTTP.start(uri.hostname, uri.port) { |http| http.request(req) }
74
+ end
80
75
 
81
- def stringify_keys(hash)
82
- hash.map { |k, v| [k.to_s, v] }
83
- end
76
+ def combine_images_and_args(*images, **args)
77
+ stringify_keys(args).concat(image_form_data(images.flatten))
78
+ end
84
79
 
85
- #
86
- # Return an array of image entries for form data.
87
- # The field name is 'image' for a single image
88
- # For multiple images, the field names will be 'image1', 'image2', ...
89
- #
90
- # @param [Array<Object>] images an array of raw image data or a File object
91
- #
92
- # @return [Array] the image entries for set_form
93
- #
94
- def image_form_data(*images)
95
- images = images.flatten
96
- return [image_entry('image', images.first)] if images.length == 1
97
-
98
- images.map.with_index(1) { |image, i| image_entry("image#{i}", image) }
99
- end
80
+ def stringify_keys(hash)
81
+ hash.map { |k, v| [k.to_s, v] }
82
+ end
100
83
 
101
- def image_entry(name, image)
102
- [name, image].tap { |result| result << { filename: "#{name}.jpg" } unless image.instance_of? File }
103
- end
84
+ #
85
+ # Return an array of image entries for form data.
86
+ # The field name is 'image' for a single image
87
+ # For multiple images, the field names will be 'image1', 'image2', ...
88
+ #
89
+ # @param [Array<Object>] images an array of raw image data or a File object
90
+ #
91
+ # @return [Array] the image entries for set_form
92
+ #
93
+ def image_form_data(*images)
94
+ images = images.flatten
95
+ return [image_entry('image', images.first)] if images.length == 1
96
+
97
+ images.map.with_index(1) { |image, i| image_entry("image#{i}", image) }
98
+ end
104
99
 
105
- def process_result(result)
106
- @result = result.is_a?(Net::HTTPSuccess) ? JSON.parse(result.body) : nil
107
- %w[success duration predictions].each { |attrib| instance_variable_set("@#{attrib}", @result&.dig(attrib)) }
108
- @result
109
- end
100
+ def image_entry(name, image)
101
+ [name, image].tap { |result| result << { filename: "#{name}.jpg" } unless image.instance_of? File }
102
+ end
103
+
104
+ def process_result(result)
105
+ @result = result.is_a?(Net::HTTPSuccess) ? JSON.parse(result.body) : nil
106
+ %w[success duration predictions].each { |attrib| instance_variable_set("@#{attrib}", @result&.dig(attrib)) }
107
+ @result
110
108
  end
111
109
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: deepstack
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jimmy Tanagra
@@ -48,5 +48,5 @@ requirements: []
48
48
  rubygems_version: 3.3.7
49
49
  signing_key:
50
50
  specification_version: 4
51
- summary: A Ruby wrapper for Deepstack API
51
+ summary: A Ruby wrapper for DeepStack API
52
52
  test_files: []