Skip to content

Commit d84d07d

Browse files
committed
added ruby demo
1 parent 06b62cc commit d84d07d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+10816
-1
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,13 @@ This suite of 5 demos uses Javascript and PHP to showcase Kairos Emotion Analysi
88
This suite of 5 demos uses Golang to showcase Kairos Emotion Analysis and Facial Recognition/Detection
99
[Documentation](/go-demo/README.md)
1010

11+
### Python-Demo
12+
This suite of 4 demos uses Python to showcase Kairos Emotion Analysis and Facial Recognition/Detection
13+
[Documentation](/python-demo/README.md)
14+
15+
### Ruby-Demo
16+
This suite of 5 demos uses Golang to showcase Kairos Emotion Analysis and Facial Recognition/Detection
17+
[Documentation](/ruby-demo/README.md)
18+
1119
### Miscellaneous Examples
1220
We have included API examples in various programming languages to assist you in a variety of situations

python-demo/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
These demo apps showcase the Kairos APIs by giving the user a means to quickly get up and running with our Emotion Analysis and Facial Recognition / Detection APIs.
55

66
## Running the App
7-
The demo app can easily be run using Docker with the included Dockerfile and docker-compose.yml or locally using a solution stack program such as MAMP or WAMP.
7+
The demo app can easily be run using Docker with the included Dockerfile and docker-compose.yml or locally from your command prompt.
88

99
The app is basically a single page application, which is viewed at index.html.
1010

ruby-demo/README.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Kairos Ruby/Javascript Demo Modules
2+
3+
## What it does
4+
These demo apps showcase the Kairos APIs by giving the user a means to quickly get up and running with our Emotion Analysis and Facial Recognition / Detection APIs.
5+
6+
## Running the App
7+
The demo app can easily be run using Docker with the included Dockerfile and docker-compose.yml or locally from your command prompt.
8+
9+
The app is basically a single page application, which is viewed at index.html.
10+
11+
The easiest way to get started is to clone or fork the repo, and add your APP_ID and API_KEY to the app.rb file after signing up at [developer.kairos.com](https://developer.kairos.com)
12+
13+
#### Install Ruby
14+
From your command prompt, run `rvm install ruby-2.3.0` or the latest version.
15+
#### Install dependencies
16+
From your command prompt, run:
17+
18+
* `gem install sinatra`
19+
* `gem install rest-client`
20+
* `gem install httparty`
21+
22+
#### Run application
23+
24+
Run `ruby app.rb`
25+
26+
Point your browser to `http://127.0.0.1:4567/`
27+
28+
### Detect
29+
The Detect Demo uses Kairos Face Recognition API to detect a human face in an existing photo, or a snapshot from the user's webcam.
30+
[Documentation](/ruby-demo/public/docs/detect/Detect.md)
31+
32+
### Emotion
33+
The Emotion Demo showcases the Kairos Emotion API by giving the user three methods for analyzing human emotions in a video stream.
34+
[Documentation](/ruby-demo/public/docs/emotion/Emotion.md)
35+
36+
### Recognize
37+
The Recognize Demo uses Kairos Face Recognition API to recognize human faces from previously enrolled faces by the user.
38+
[Documentation](/ruby-demo/public/docs/recognize/Recognize.md)
39+
40+
### Verify
41+
Using the Kairos Face Recognition API, the Verify Demo compares two photos, and verifies that the two photos are of the same individual.
42+
[Documentation](/ruby-demo/public/docs/verify/Verify.md)
43+
44+

ruby-demo/app.rb

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
# app.rb
2+
require "sinatra"
3+
require "rest-client"
4+
require "base64"
5+
require "httparty"
6+
7+
api_url = "https://api.kairos.com"
8+
app_id = "YOUR_APP_ID"
9+
app_key = "YOUR_APP_KEY"
10+
11+
headers = {
12+
"app_id" => app_id,
13+
"app_key" => app_key
14+
}
15+
16+
get "/" do
17+
File.read("views/index.html")
18+
end
19+
20+
get "/detect" do
21+
@API_URL = api_url
22+
@APP_ID = app_id
23+
@APP_KEY = app_key
24+
erb :detect
25+
end
26+
27+
post "/detect/send-to-api" do
28+
url = api_url + "/detect"
29+
payload = request["imgObj"]
30+
return RestClient.post(url,payload,headers=headers)
31+
end
32+
33+
get "/emotion" do
34+
@API_URL = api_url
35+
@APP_ID = app_id
36+
@APP_KEY = app_key
37+
erb :emotion
38+
end
39+
40+
post "/emotion/send-to-api" do
41+
if request["fname"] == "polling"
42+
mediaId = request["mediaId"]
43+
url = api_url + "/v2/media/" + mediaId
44+
return RestClient.get(url,headers=headers)
45+
elsif request["fname"] == "analytics"
46+
mediaId = request["mediaId"]
47+
url = api_url + "/v2/analytics/" + mediaId
48+
return RestClient.get(url,headers=headers)
49+
elsif request["fname"] == "urlGetContent"
50+
urlPath = request["urlPath"]
51+
response = HTTParty.get(urlPath)
52+
contentLength = response.headers["content-length"]
53+
contentType = response.headers["content-type"]
54+
base64Str = Base64.encode64(response.body)
55+
returnArray = {
56+
"contentLength" => contentLength,
57+
"contentType" => contentType,
58+
"base64Str" => base64Str
59+
}
60+
return returnArray.to_json
61+
elsif request["fname"] == "urlProcess"
62+
mediaUrl = request["urlPath"]
63+
url = api_url + "/v2/media?source=" + mediaUrl + "&landmarks=1&timeout=1"
64+
return RestClient.post(url,"",headers=headers)
65+
elsif request["fname"] == "fileupload"
66+
@filename = params[:file][:filename]
67+
file = params[:file][:tempfile]
68+
filepath = "./public/tmp/#{@filename}"
69+
File.open(filepath, "wb") do |f|
70+
f.write(file.read)
71+
end
72+
url = api_url + "/v2/media?landmarks=1"
73+
video = File.new(filepath, "rb")
74+
payload = {"source" => video}
75+
File.delete(filepath)
76+
return RestClient.post(url,payload,headers=headers)
77+
78+
end
79+
end
80+
81+
get "/recognize" do
82+
@API_URL = api_url
83+
@APP_ID = app_id
84+
@APP_KEY = app_key
85+
erb :recognize
86+
end
87+
88+
post "/recognize/send-to-api" do
89+
if request['process'] == "enroll"
90+
url = api_url + '/enroll'
91+
payload = request['imgObj']
92+
return RestClient.post(url,payload,headers=headers)
93+
end
94+
if request['process'] == "recognize"
95+
url = api_url + '/recognize'
96+
payload = request['imgObj']
97+
return RestClient.post(url,payload,headers=headers)
98+
end
99+
end
100+
101+
get "/verify" do
102+
@API_URL = api_url
103+
@APP_ID = app_id
104+
@APP_KEY = app_key
105+
erb :verify
106+
end
107+
108+
post "/verify/send-to-api" do
109+
if request['process'] == "enroll"
110+
url = api_url + '/enroll'
111+
payload = request['imgObj']
112+
return RestClient.post(url,payload,headers=headers)
113+
end
114+
if request['process'] == "verify"
115+
url = api_url + '/verify'
116+
payload = request['imgObj']
117+
return RestClient.post(url,payload,headers=headers)
118+
end
119+
end
120+
121+
# utility functions
122+
# ExifData needs to be written
123+
124+
post "/exif-data" do
125+
return ""
126+
end
127+
128+
129+
130+
Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
@media (max-width: 600px) {
2+
.image2 {
3+
display: none;
4+
}
5+
.copy-json-button {
6+
display: none;
7+
}
8+
.ethnicity-graph-inner .bar-container {
9+
height: 20px;
10+
}
11+
.face-overlay {
12+
background-position: 50% 50%;
13+
}
14+
}
15+
16+
@media (max-width: 767px) {
17+
.image2, .image4 {
18+
display: none;
19+
}
20+
.photo-thumbnail img {
21+
width: 31%;
22+
margin-right: 3.5%;
23+
}
24+
.image3 img {
25+
float: left;
26+
}
27+
.image5 img {
28+
margin-top: 0;
29+
}
30+
.json-response, .json-response-template, .copy-json-button {
31+
display: none;
32+
}
33+
}
34+
35+
@media (min-width: 768px) {
36+
.main-image-container {
37+
padding-right: 0;
38+
}
39+
.image2 {
40+
display: none;
41+
}
42+
.image3 img {
43+
margin-top: 0;
44+
float: left;
45+
}
46+
.image4 {
47+
display: block;
48+
}
49+
.image4 img {
50+
margin-top: 0;
51+
float: left;
52+
}
53+
.image5 img {
54+
margin-top: 0;
55+
float: right;
56+
}
57+
.json-response {
58+
display: block;
59+
height: 360px;
60+
}
61+
.photo-thumbnail img {
62+
width: 23%;
63+
margin-right: 2.6%;
64+
}
65+
.ui-buttons-mask {
66+
width: 96%;
67+
}
68+
.show-hide-ethnicity {
69+
display: block;
70+
}
71+
.ethnicity-graph-inner .bar-container {
72+
height: 12px;
73+
}
74+
.ethnicity-graph-inner .bar-header .percent {
75+
font-size: 20px;
76+
font-weight: bold;
77+
}
78+
.ethnicity-graph-inner .bar-header .title {
79+
font-size: 11px;
80+
font-weight: normal;
81+
}
82+
#webcamVideo {
83+
position: absolute;
84+
top: 0;
85+
left: -80px;
86+
z-index: 9;
87+
}
88+
#displayCanvas {
89+
left: -80px;
90+
}
91+
}
92+
93+
@media (min-width: 992px) {
94+
.main-container {
95+
width: 980px;
96+
margin: 0 auto;
97+
padding: 50px 0;
98+
}
99+
.main-image-container {
100+
padding-right: 0;
101+
height: 475px;
102+
}
103+
#previewImage {
104+
width: 475px;
105+
height: 475px;
106+
}
107+
.image2, .image4 {
108+
display: block;
109+
}
110+
.photo-thumbnail img {
111+
width: 184px;
112+
margin-top: 0;
113+
margin-right: 15px;
114+
opacity: 0.7;
115+
float: left;
116+
}
117+
.canvas-container {
118+
width: 475px;
119+
height: 475px;
120+
overflow: hidden;
121+
position: absolute;
122+
top: 0;
123+
left: 15px;
124+
z-index: 9;
125+
}
126+
.display-image-container {
127+
width: 475px;
128+
height: 475px;
129+
}
130+
.image-container-template {
131+
width: 475px;
132+
height: 475px;
133+
}
134+
.webcam-video-container {
135+
width: 475px;
136+
height: 475px;
137+
}
138+
.json-response {
139+
width: 505px;
140+
height: 475px;
141+
padding-left: 0;
142+
}
143+
.ui-buttons .upload {
144+
padding-left: 0;
145+
margin-top: 0;
146+
}
147+
.show-hide-json {
148+
display: none;
149+
}
150+
.ui-buttons-mask {
151+
width: 97%;
152+
}
153+
.ethnicity-graph-inner .bar-container {
154+
height: 35px;
155+
}
156+
.ethnicity-graph-inner .bar-header .percent {
157+
font-size: 22px;
158+
font-weight: bold;
159+
}
160+
.ethnicity-graph-inner .bar-header .title {
161+
font-size: 13px;
162+
font-weight: normal;
163+
}
164+
}
165+
166+
@media (min-width: 1200px) {
167+
168+
}
169+

0 commit comments

Comments
 (0)