Skip to content

Instantly share code, notes, and snippets.

Avatar
🥑
guac is good

Selynna Sun selynna

🥑
guac is good
View GitHub Profile
View index.js
// Train classifier
console.log("Training...");
let trainingIteration = await trainer.trainProject(project.id);
console.log("Training started...");
while (trainingIteration.status == "Training") {
await setTimeoutPromise(1000, null);
trainingIteration = await trainer.getIteration(project.id, trainingIteration.id)
}
console.log("Training status: " + trainingIteration.status);
View index.js
console.log("Adding images...");
let fileUploadPromises = [];
const pizzaDir = `${dataRoot}/pizza`;
const pizzaFiles = fs.readdirSync(pizzaDir);
pizzaFiles.forEach(file => {
fileUploadPromises.push(trainer.createImagesFromData(project.id, fs.readFileSync(`${pizzaDir}/${file}`), { tagIds: [pizzaTag.id] }));
});
await Promise.all(fileUploadPromises);
View index.js
# index.js
// Create project
const util = require('util');
const fs = require('fs');
const TrainingApiClient = require("azure-cognitiveservices-customvision-training");
const PredictionApiClient = require("azure-cognitiveservices-customvision-prediction");
const setTimeoutPromise = util.promisify(setTimeout);
View .env
# .env
TRAINING_KEY=<your training key>
PREDICTION_KEY=<your prediction key>
TRAINING_RESOURCE_ID=<your training resource id>
PREDICTION_RESOURCE_ID=<your prediction resource id>
View file-structure.md
django_azure_demo/
|_ django_azure_demo/
  |_ __init__.py
  |_ settings.py
  |_ urls.py
  |_ wsgi.py
|_ manage.py
|_ db.sqlite3
View settings.py
# django_azure_demo/settings.py
"""
Django settings for django_azure_demo project.
Generated by 'django-admin startproject' using Django 1.11.20.
For more information on this file, see
https://docs.djangoproject.com/en/1.11/topics/settings/
For the full list of settings and their values, see
View web.config
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="httpPlatformHandler" path="*" verb="*"
modules="httpPlatformHandler" resourceType="Unspecified" />
</handlers>
<httpPlatform processPath="D:\home\Python364x86\python.exe" arguments="run_waitress_server.py" requestTimeout="00:04:00" startupTimeLimit="120" startupRetryCount="3" stdoutLogEnabled="true">
<environmentVariables>
<environmentVariable name="PYTHONPATH" value="D:\home\site\wwwroot" />
View run_waitress_server.py
import os
from waitress import serve
from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "django_azure_demo.settings")
application = get_wsgi_application()
serve(application,host="0.0.0.0",port=os.environ["PORT"])
View .deployment
[config]
command = deploy.cmd
You can’t perform that action at this time.