Skip to content

Commit 8ac897a

Browse files
committed
update Python demo to latest changes in demo repo
1 parent acc84fc commit 8ac897a

Some content is hidden

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

79 files changed

+1462
-115
lines changed

python-demo/README.md

+14-15
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,15 @@
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 from your command prompt.
87

98
The app is basically a single page application, which is viewed at index.html.
109

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.py file after signing up at [developer.kairos.com](https://developer.kairos.com)
10+
The easiest way to get started is to clone or fork the repo, and add your environment, API URL, APP_ID, and API_KEY to the app.py file after signing up at [developer.kairos.com](https://developer.kairos.com)
11+
12+
demo_env = "dev, stage, or prod"
13+
api_url = "https://api-dev.kairos.com or https://api.kairos.com"
14+
app_id = "your-app-id"
15+
app_key = "your-app-key"
1216

1317
The webcam functionality requires that your site is secure (https). In order to run your local install using https, you will need to generate a certificate and a key. To to this, run this command:
1418

@@ -21,42 +25,37 @@ Follow the prompts, and this will generate two files: `cert.pem` and `key.pem`.
2125

2226
### Run the app locally from your command prompt
2327
* make sure Python 2.7 is installed and accessible
24-
* install Python Flask `pip install flask`
28+
* if PIP is not installed: `sudo easy_install pip`
29+
* install Python Flask `sudo pip install flask`
30+
* install requests `sudo pip install requests`
2531
* cd into the python-demo repo
2632
* run `python app.py`
27-
* point your browser to `https://127.0.0.1:5000`
33+
* point your browser to `https://0.0.0.1:5000`
2834

29-
### Run the app in a Docker container
30-
* the app uses Python 2.7
31-
* cd into the python-demo repo
32-
* run `docker build -t pythondemo .`
33-
* after the app compiles, run `docker run -d -p 5000:5000 pythondemo`
34-
* run python app.py
35-
* point your browser to `https://127.0.0.1:5000`
3635

3736
---
3837

3938
### Detect
4039
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.
4140
[Documentation](/python-demo/static/docs/detect/Detect.md)
41+
[Tutorial](/python-demo/static/docs/detect/tutorial/Detect_API_Python_Tutorial.md)
4242

4343
### Emotion
4444
The Emotion Demo showcases the Kairos Emotion API by giving the user three methods for analyzing human emotions in a video stream.
4545
[Documentation](/python-demo/static/docs/emotion/Emotion.md)
46+
[Tutorial](/python-demo/static/docs/emotion/tutorial/Emotion_API_Python_Tutorial.md)
4647

4748
### Recognize
4849
The Recognize Demo uses Kairos Face Recognition API to recognize human faces from previously enrolled faces by the user.
4950
[Documentation](/python-demo/static/docs/recognize/Recognize.md)
51+
[Tutorial](/python-demo/static/docs/emotion/tutorial/Emotion_API_Python_Tutorial.md)
5052

5153
### Verify
5254
Using the Kairos Face Recognition API, the Verify Demo compares two photos, and verifies that the two photos are of the same individual.
5355
[Documentation](/python-demo/static/docs/verify/Verify.md)
56+
[Tutorial](/python-demo/static/docs/emotion/tutorial/Emotion_API_Python_Tutorial.md)
5457

55-
---
5658

57-
#### Caching
58-
To cache an asset, add: `?t_{{CACHE_BUSTER}}` to the end of the resource link, for example:
59-
`<link rel="stylesheet" href="https://media.kairos.com/python-demo/detect/css/detect.css?t_{{CACHE_BUSTER}}">`
6059

6160

6261

python-demo/static/css/detect/detect.css

+3-3
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@
103103
width: 500px;
104104
height: 500px;
105105
margin: 0 auto;
106-
background: transparent url('../images/face_overlay.png') no-repeat;
106+
background: transparent url('../../images/face_overlay.png') no-repeat;
107107
background-size: 50%;
108108
background-position: 45% 45%;
109109
z-index: 10;
@@ -179,13 +179,13 @@
179179
width: 50px;
180180
height: 50px;
181181
margin: 0 auto;
182-
background: transparent url('../images/spinner.gif') no-repeat;
182+
background: transparent url('../../images/spinner.gif') no-repeat;
183183
}
184184
.sad-face {
185185
width: 50px;
186186
height: 50px;
187187
margin: 0 auto;
188-
background: transparent url('../images/sad_face.png') no-repeat;
188+
background: transparent url('../../images/sad_face.png') no-repeat;
189189
}
190190
.message-container{
191191
font-size: 14px;

python-demo/static/css/recognize/recognize.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@
176176
width: 50px;
177177
height: 50px;
178178
margin: 0 auto;
179-
background: transparent url('../images/spinner.svg') no-repeat;
179+
background: transparent url('../../images/spinner.svg') no-repeat;
180180
position: relative;
181181
}
182182
.message-container .spinner-message{

python-demo/static/css/verify/verify.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@
195195
width: 50px;
196196
height: 50px;
197197
margin: 5px auto 3px;
198-
background: transparent url('https://media.kairos.com/python-demo/images/spinner.svg') no-repeat;
198+
background: transparent url('../../images/spinner.svg') no-repeat;
199199
position: relative;
200200
z-index: 9;
201201
}

python-demo/static/docs/detect/Detect.md

+16-5
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,17 @@
22
## What it does
33
The Detect Demo demonstrates the capability of the Kairos Face Recognition API to detect facial features by giving the user four methods for detection. In each method, image data is passed to the API, which returns a JSON object containing facial feature data.
44

5+
---
56
## Running the App
6-
The Detect demo app is run from the command line, using Python 2.7.
77

8-
The app is basically a single page application, which is viewed at index.html.
8+
See "Running the App" in the Python Demo README file: [Documentation](/python-demo/README.md)
9+
10+
You will be able to access the UI for the Detect Demo at https://0.0.0.0:5000/detect
911

10-
The Detect API demo app is comprised of three modules:
12+
The Emotion API demo app is comprised of four modules:
1113

1214
* Examples Module
13-
* Webcam Module
15+
* Webcam Module (not on Safari or mobile)
1416
* Upload Module
1517
* URL Module
1618

@@ -25,7 +27,7 @@ Five pre-processed image examples are presented to the user.
2527
Upon clicking one of the image thumbnails, a POST request is made to the Kairos API with the ID of the selected video using the following endpoint:
2628
https://api.kairos.com/detect
2729

28-
To accomplish this, an AJAX script in the `detectDemoApp.js` file POSTS to the endpoint `/detect/send-to-api` using Python Flask. Python makes a POST to the `/detect` endpoint with the proper headers containing the user's Kairos app_id and api_ky values. The API response is sent to the `apiCallback()` method, which formats the JSON response for viewing, and draws a box around the detected face, along with various other feature points.
30+
To accomplish this, an AJAX script in the `detectDemoApp.js` file POSTS to the Python route `/detect/send-to-api` using Python Flask. Python makes a POST to the `/detect` endpoint with the proper headers containing the user's Kairos app_id and api_key values. The API response is sent to the `apiCallback()` method, which formats the JSON response for viewing, and draws a box around the detected face, along with various other feature points.
2931

3032
![Box Around Face](/python-demo/static/docs/detect/box.png?raw=true)
3133

@@ -88,6 +90,15 @@ The functionality for a number of user interactions is contained within the `det
8890
If `?option-panel=yes` is added to the URL of the demo, a panel is revealed underneath the example images containing a slider/input box where the user can enter values for minHeadScale, and also radio/checkbox buttons for selector. The payload which is sent to the API is also displayed. See the docs for detailed information on these arguments: http://kairos.com/docs/api/
8991

9092

93+
---
94+
95+
## Environment Variables
96+
97+
* APP_ID - Application ID
98+
* APP_KEY - Application Key
99+
* API_URL - URL of the API server
100+
* DEMO_ENV - Environment (dev, stage, prod)
101+
91102
---
92103

93104
## Dependencies

python-demo/static/docs/detect/tutorial/Detect_API_Python_Tutorial.md

+17-19
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,23 @@ Clone or fork the repo at https://github.com/kairosinc/api-examples
1010

1111
* Go to the Kairos website at http://kairos.com/pricing and click GET YOUR FREE API KEY at the bottom of the page.
1212

13-
* Fill out the online form.
13+
![Kairos Website](/python-demo/static/docs/detect/kairos_website.png?raw=true)
14+
15+
Fill out the online form.
16+
17+
![Registration Form](/python-demo/static/docs/detect/registration_form.png?raw=true)
1418

1519
* You will receive a confirmation email. Click on the link in the email, to activate your account. This will take you to a page with your API ID and Key.
1620

17-
## 3. Run the app
21+
![ID and Key](/python-demo/static/docs/detect/id_and_key.png?raw=true)
1822

19-
#### Running the app on your local system
23+
## 3. Run the app
2024

2125
Insert your Kairos API ID and Key into the app.py file, which is at the root of the python-demo directory.
2226

23-
try:
24-
app_id = os.environ['APP_ID']
25-
except:
26-
app_id = "YOUR_APP_ID"
27-
28-
try:
29-
app_key = os.environ["APP_KEY"]
30-
except:
31-
app_key = "YOUR_APP_KEY"
27+
api_url = "https://api.kairos.com"
28+
app_id = "YOUR_APP_ID"
29+
app_key = "YOUR_APP_KEY"
3230
3331
* make sure Python 2.7 is installed and accessible
3432
* install Python Flask `pip install flask`
@@ -41,17 +39,17 @@ Insert your Kairos API ID and Key into the app.py file, which is at the root of
4139
* For the following applications, we recommend using the `app.py` file in the repo as a basis. This file contains more functionality than you'll need, so if you'd like, you can strip out all but the necessary scripts.
4240
* This script sends a payload to the Kairos API:
4341

44-
api_url = 'https://api-dev.kairos.com'
42+
api_url = 'https://api.kairos.com'
4543
headers = {
4644
"app_id": YOUR_APP_ID,
4745
"app_key": YOUR_APP_KEY
4846
}
4947
@app.route("/detect/send-to-api", methods=['POST'])
50-
def sendToApiDetect():
51-
url = api_url + "/detect"
52-
payload = request.form["imgObj"]
53-
r = requests.post(url, data=payload, headers=headers)
54-
return r.content
48+
def sendToApiDetect():
49+
url = api_url + "/detect"
50+
payload = request.form["imgObj"]
51+
r = requests.post(url, data=payload, headers=headers)
52+
return r.content
5553

5654
To use requests, you must import the library:
5755
`import requests`
@@ -149,7 +147,7 @@ For the Kairos demo, the MediaStreamRecorder.js library is used to capture the v
149147
// process the data response
150148
});
151149

152-
* The "detect/send-top-api" route will POST to the script listed in "Create your own custom applications".
150+
* The "detect/send-to-api" route will POST to the script listed in "Create your own custom applications".
153151

154152
api_url = "https://api.kairos.com"
155153
headers = {

0 commit comments

Comments
 (0)