Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/controllers/image-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

// Import required libraries and services
const GcpAutoMlService = require('../services/gcp-auto-ml');
const MockGcpService = require('../services/mock-gcp-service');
const fs = require('fs').promises;
const path = require('path');
const AdmZip = require('adm-zip');
Expand All @@ -24,7 +25,7 @@ const { Storage } = require('@google-cloud/storage');

/**
* Create a configured instance of the GCP AutoML service
* @returns {GcpAutoMlService} Configured service instance
* @returns {GcpAutoMlService|MockGcpService} Configured service instance
*/
function createGcpService() {
// Get configuration from environment variables
Expand All @@ -33,6 +34,18 @@ function createGcpService() {
region: process.env.GCP_REGION,
bucketName: process.env.GCS_BUCKET_NAME,
};

const useMockService = process.env.NODE_ENV === 'development' ||
!process.env.GOOGLE_APPLICATION_CREDENTIALS ||
!fs.access(process.env.GOOGLE_APPLICATION_CREDENTIALS)
.then(() => false)
.catch(() => true);

if (useMockService) {
console.log('Using mock GCP service for development or missing credentials');
return new MockGcpService(config);
}

return new GcpAutoMlService(config);
}

Expand Down
16 changes: 15 additions & 1 deletion src/controllers/text-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@

// Import the GCP service
const GcpAutoMlService = require('../services/gcp-auto-ml');
const MockGcpService = require('../services/mock-gcp-service');
const { Storage } = require('@google-cloud/storage');
const fs = require('fs').promises;

/**
* Response data for a successful operation
Expand Down Expand Up @@ -40,7 +42,7 @@ const { Storage } = require('@google-cloud/storage');

/**
* Create a configured instance of the GCP AutoML service
* @returns {GcpAutoMlService} Configured service instance
* @returns {GcpAutoMlService|MockGcpService} Configured service instance
*/
function createGcpService() {
// Get configuration from environment variables
Expand All @@ -49,6 +51,18 @@ function createGcpService() {
region: process.env.GCP_REGION,
bucketName: process.env.GCS_BUCKET_NAME,
};

const useMockService = process.env.NODE_ENV === 'development' ||
!process.env.GOOGLE_APPLICATION_CREDENTIALS ||
!fs.access(process.env.GOOGLE_APPLICATION_CREDENTIALS)
.then(() => false)
.catch(() => true);

if (useMockService) {
console.log('Using mock GCP service for development or missing credentials');
return new MockGcpService(config);
}

return new GcpAutoMlService(config);
}

Expand Down
20 changes: 20 additions & 0 deletions src/routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@ router.get('/text_home', (req, res) => {
});
});

/**
* Vision classification home page
*/
router.get('/vision_home', (req, res) => {
res.render('models/vision-home', {
title: 'Vision Classification',
description: 'Train and test image classification models'
});
});

/**
* New text classifier page
*/
Expand All @@ -38,6 +48,16 @@ router.get('/classify/text/new', (req, res) => {
});
});

/**
* New vision classifier page
*/
router.get('/classify/vision/new', (req, res) => {
res.render('models/vision/new-classifier', {
title: 'Create Vision Classifier',
description: 'Create and train a new image classifier'
});
});

/**
* API documentation route
*/
Expand Down
Loading