tangram 0.1.0.pre.alpha.7
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/README.md +1 -0
- data/examples/heart-disease/main.rb +25 -0
- data/lib/tangram/libtangram-0.1.0-alpha.4-linux-x86_64.so +0 -0
- data/lib/tangram/libtangram-0.1.0-alpha.4-macos-x86_64.dylib +0 -0
- data/lib/tangram/libtangram.rb +24 -0
- data/lib/tangram/model.rb +53 -0
- data/lib/tangram/tangram-0.1.0-alpha.4-windows-x86_64.dll +0 -0
- data/lib/tangram.rb +1 -0
- data/scripts/build +5 -0
- data/tangram.gemspec +13 -0
- metadata +67 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 6c4cbfd5a24c6561fe11c81ae785d47bc4f4e16a0b11c10f079c63d863c6cb15
|
4
|
+
data.tar.gz: 29d6160096b0ca3d692781d07f4dffb971ab9563c9a6bd1c7911a1676e161806
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d8e03fe9d77eedf28dc4ab6b6cbf17f6c5274479b1a0324f7071d5e5f608a0fc17bb312b46d995c6873b8b7ef8fac81f8b02490ca06038e936c61a07ac19f38b
|
7
|
+
data.tar.gz: 8c47ffbf42a08c613e3e6bcfdcefc396d5db0d2288a85b52f3bf766f30f9a0bff685d04c282a837b693e2c959e4037713f655a3e07a01e4fe1bc04077ee997df
|
data/README.md
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# tangram-ruby
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'tangram'
|
2
|
+
|
3
|
+
model = Tangram::Model.from_file('./heart-disease.tangram')
|
4
|
+
|
5
|
+
puts model.task
|
6
|
+
|
7
|
+
input = {
|
8
|
+
age: 63,
|
9
|
+
gender: 'male',
|
10
|
+
chest_pain: 'typical angina',
|
11
|
+
resting_blood_pressure: 145,
|
12
|
+
cholesterol: 233,
|
13
|
+
fasting_blood_sugar_greater_than_120: 'true',
|
14
|
+
resting_ecg_result: 'probable or definite left ventricular hypertrophy',
|
15
|
+
exercise_max_heart_rate: 150,
|
16
|
+
exercise_induced_angina: 'no',
|
17
|
+
exercise_st_depression: 2.3,
|
18
|
+
exercise_st_slope: 'downsloping',
|
19
|
+
fluoroscopy_vessels_colored: 0,
|
20
|
+
thallium_stress_test: 'fixed defect',
|
21
|
+
}
|
22
|
+
|
23
|
+
output = model.predict(input)
|
24
|
+
|
25
|
+
puts('Prediction:', output['className'])
|
Binary file
|
Binary file
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'ffi'
|
2
|
+
require 'rbconfig'
|
3
|
+
|
4
|
+
module LibTangram
|
5
|
+
cpu = RbConfig::CONFIG['host_cpu']
|
6
|
+
os = RbConfig::CONFIG['host_os']
|
7
|
+
if cpu == 'x86_64' and os =~ /linux/
|
8
|
+
library_name = 'libtangram-0.1.0-alpha.4-linux-x86_64.so'
|
9
|
+
elsif cpu == 'x86_64' and os =~ /darwin/
|
10
|
+
library_name = 'libtangram-0.1.0-alpha.4-macos-x86_64.dylib'
|
11
|
+
elsif cpu == 'x86_64' and os =~ /mingw/
|
12
|
+
library_name = 'tangram-0.1.0-alpha.4-windows-x86_64.dll'
|
13
|
+
else
|
14
|
+
raise 'tangram-ruby does not yet support your combination of operating system and CPU architecture.'
|
15
|
+
end
|
16
|
+
extend FFI::Library
|
17
|
+
ffi_lib File.expand_path("#{library_name}", __dir__)
|
18
|
+
attach_function :tangram_model_load, [:pointer, :uint, :pointer], :int
|
19
|
+
attach_function :tangram_model_id, [:pointer, :pointer], :int
|
20
|
+
attach_function :tangram_model_task, [:pointer, :pointer], :int
|
21
|
+
attach_function :tangram_model_predict, [:pointer, :pointer, :pointer, :pointer], :int
|
22
|
+
attach_function :tangram_string_free, [:pointer], :int
|
23
|
+
attach_function :tangram_model_free, [:pointer], :int
|
24
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'tangram/libtangram'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module Tangram
|
5
|
+
class Model
|
6
|
+
def self.from_file(model_path)
|
7
|
+
model_data = IO.binread(model_path)
|
8
|
+
self.from_data(model_data)
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.from_data(model_data)
|
12
|
+
self.new(model_data)
|
13
|
+
end
|
14
|
+
|
15
|
+
def initialize(model_data)
|
16
|
+
model_ptr = FFI::MemoryPointer.new(:pointer)
|
17
|
+
result = LibTangram.tangram_model_load(model_data, model_data.size, model_ptr)
|
18
|
+
if result != 0
|
19
|
+
raise 'tangram error'
|
20
|
+
end
|
21
|
+
@model = FFI::AutoPointer.new(model_ptr.read_pointer, LibTangram.method(:tangram_model_free))
|
22
|
+
end
|
23
|
+
|
24
|
+
def task
|
25
|
+
task_ptr = FFI::MemoryPointer.new(:pointer)
|
26
|
+
result = LibTangram.tangram_model_task(@model, task_ptr)
|
27
|
+
if result != 0
|
28
|
+
raise 'tangram error'
|
29
|
+
end
|
30
|
+
task = task_ptr.read_pointer.read_string.force_encoding('utf-8')
|
31
|
+
LibTangram.tangram_string_free(task_ptr.read_pointer)
|
32
|
+
task
|
33
|
+
end
|
34
|
+
|
35
|
+
def predict(input, options)
|
36
|
+
input = JSON.unparse(input)
|
37
|
+
unless options.nil?
|
38
|
+
options = JSON.unparse(options)
|
39
|
+
else
|
40
|
+
options = nil
|
41
|
+
end
|
42
|
+
output_ptr = FFI::MemoryPointer.new(:pointer)
|
43
|
+
result = LibTangram.tangram_model_predict(@model, input, options, output_ptr)
|
44
|
+
if result != 0
|
45
|
+
raise 'tangram error'
|
46
|
+
end
|
47
|
+
output = output_ptr.read_pointer.read_string.force_encoding('utf-8')
|
48
|
+
output = JSON.parse(output)
|
49
|
+
LibTangram.tangram_string_free(output_ptr.read_pointer)
|
50
|
+
output
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
Binary file
|
data/lib/tangram.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'tangram/model'
|
data/scripts/build
ADDED
data/tangram.gemspec
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = "tangram"
|
3
|
+
s.version = "0.1.0-alpha.7"
|
4
|
+
s.date = "2019-11-22"
|
5
|
+
s.summary = "Tangram for Ruby"
|
6
|
+
s.description = "Make predictions with a Tangram model from your Ruby app. Learn more at https://www.tangramhq.com/."
|
7
|
+
s.authors = ["Tangram"]
|
8
|
+
s.email = "help@tangramhq.com"
|
9
|
+
s.files = Dir['**/**'].grep_v(/.gem$/)
|
10
|
+
s.homepage = "http://rubygems.org/gems/tangram"
|
11
|
+
s.license = "MIT"
|
12
|
+
s.add_dependency 'ffi', '~> 1'
|
13
|
+
end
|
metadata
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tangram
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0.pre.alpha.7
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tangram
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-11-22 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: ffi
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1'
|
27
|
+
description: Make predictions with a Tangram model from your Ruby app. Learn more
|
28
|
+
at https://www.tangramhq.com/.
|
29
|
+
email: help@tangramhq.com
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- README.md
|
35
|
+
- examples/heart-disease/main.rb
|
36
|
+
- lib/tangram.rb
|
37
|
+
- lib/tangram/libtangram-0.1.0-alpha.4-linux-x86_64.so
|
38
|
+
- lib/tangram/libtangram-0.1.0-alpha.4-macos-x86_64.dylib
|
39
|
+
- lib/tangram/libtangram.rb
|
40
|
+
- lib/tangram/model.rb
|
41
|
+
- lib/tangram/tangram-0.1.0-alpha.4-windows-x86_64.dll
|
42
|
+
- scripts/build
|
43
|
+
- tangram.gemspec
|
44
|
+
homepage: http://rubygems.org/gems/tangram
|
45
|
+
licenses:
|
46
|
+
- MIT
|
47
|
+
metadata: {}
|
48
|
+
post_install_message:
|
49
|
+
rdoc_options: []
|
50
|
+
require_paths:
|
51
|
+
- lib
|
52
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '0'
|
57
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 1.3.1
|
62
|
+
requirements: []
|
63
|
+
rubygems_version: 3.0.6
|
64
|
+
signing_key:
|
65
|
+
specification_version: 4
|
66
|
+
summary: Tangram for Ruby
|
67
|
+
test_files: []
|