Skip to content

Commit

Permalink
Fix style, remove useless comments and formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
timursevimli committed May 16, 2024
1 parent bddc8d7 commit 18eb318
Show file tree
Hide file tree
Showing 12 changed files with 32 additions and 96 deletions.
15 changes: 3 additions & 12 deletions lib/huggingface/utils/audio.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ const { DEFAULT_MODELS } = require('../config.json');

const defaultModels = DEFAULT_MODELS.audio;

//......Audio.......

const audio = (hf) => ({

// data = readFileSync('test/sample1.flac')
async automaticSpeechRecognition(
data,
Expand All @@ -20,20 +17,14 @@ const audio = (hf) => ({
},

// data = readFileSync('test/sample1.flac')
async audioClassification(
data,
model = defaultModels.audioClassification,
) {
async audioClassification(data, model = defaultModels.audioClassification) {
const args = { data, model };
const res = await callAPI(hf, 'hf.audioClassification', args);
return res;
},

// inputs = 'Hello world!'
async textToSpeech(
inputs,
model = defaultModels.textToSpeech,
) {
async textToSpeech(inputs, model = defaultModels.textToSpeech) {
const args = { inputs, model };
const res = await callAPI(hf, 'hf.textToSpeech', args);
return res;
Expand All @@ -44,7 +35,7 @@ const audio = (hf) => ({
const args = { data, model };
const res = await callAPI(hf, 'hf.audioToAudio', args);
return res;
}
},
});

module.exports = { audio };
17 changes: 3 additions & 14 deletions lib/huggingface/utils/computerVision.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,9 @@ const { DEFAULT_MODELS } = require('../config.json');

const defaultModels = DEFAULT_MODELS.computerVision;

//......ComputerVision.......

const computerVision = (hf) => ({
// data = readFileSync('test/cheetah.png')
async imageClassification(
data,
model = defaultModels.imageClassification,
) {
async imageClassification(data, model = defaultModels.imageClassification) {
const args = { data, model };
const res = await callAPI(hf, 'hf.imageClassification', args);
return res;
Expand All @@ -28,20 +23,14 @@ const computerVision = (hf) => ({
},

// data = readFileSync('test/cats.png')
async imageSegmentation(
data,
model = defaultModels.imageSegmentation,
) {
async imageSegmentation(data, model = defaultModels.imageSegmentation) {
const args = { data, model };
const res = await callAPI(hf, 'hf.imageSegmentation', args);
return res;
},

// data = await (await fetch('https://picsum.photos/300/300')).blob()
async imageToText(
data,
model = defaultModels.imageToText,
) {
async imageToText(data, model = defaultModels.imageToText) {
const args = { data, model };
const res = await callAPI(hf, 'hf.imageToText', args);
return res;
Expand Down
19 changes: 5 additions & 14 deletions lib/huggingface/utils/custom.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,14 @@

const { callAPI } = require('../../common.js');

//......Custom.......

const custom = (hf) => ({
/*
inputs = "hello world",
parameters = {
custom_param: 'some magic',
}
*/
async customCall(
inputs,
parameters = {},
model,
) {
async customCall(inputs, parameters = {}, model) {
const args = { inputs, parameters, model };
const res = await callAPI(hf, 'hf.request', args);
return res;
Expand All @@ -27,11 +21,7 @@ const custom = (hf) => ({
custom_param: 'some magic',
}
*/
async customCallStreaming(
inputs,
parameters = {},
model,
) {
async customCallStreaming(inputs, parameters = {}, model) {
const args = { inputs, parameters, model };
return callAPI(hf, 'hf.streamingRequest', args);
},
Expand All @@ -51,9 +41,10 @@ const custom = (hf) => ({
'Error occured while triggering "textGeneration" method',
{
cause: err,
});
},
);
}
}
},
});

module.exports = { custom };
28 changes: 8 additions & 20 deletions lib/huggingface/utils/language.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ const { DEFAULT_MODELS } = require('../config.json');

const defaultModels = DEFAULT_MODELS.language;

//......Natural Language Processing (language).......

const language = (hf) => ({
// inputs = '[MASK] world!'
async fillMask(inputs, model = defaultModels.fillMask) {
Expand Down Expand Up @@ -39,10 +37,7 @@ const language = (hf) => ({
context: 'The capital of France is Paris.'
},
*/
async questionAnswering(
inputs,
model = defaultModels.questionAnswering,
) {
async questionAnswering(inputs, model = defaultModels.questionAnswering) {
const args = { inputs, model };
const res = await callAPI(hf, 'hf.questionAnswering', args);
return res;
Expand All @@ -69,10 +64,7 @@ const language = (hf) => ({
},

// inputs = 'I like you. I love you.'
async textClassification(
inputs,
model = defaultModels.textClassification,
) {
async textClassification(inputs, model = defaultModels.textClassification) {
const args = { inputs, model };
const res = await callAPI(hf, 'hf.textClassification', args);
return res;
Expand All @@ -98,10 +90,7 @@ const language = (hf) => ({
},

// inputs = 'My name is Sarah Jessica Parker but you can call me Jessica'
async tokenClassification(
inputs,
model = defaultModels.tokenClassification,
) {
async tokenClassification(inputs, model = defaultModels.tokenClassification) {
const args = { inputs, model };
const res = await callAPI(hf, 'hf.tokenClassification', args);
return res;
Expand All @@ -110,7 +99,9 @@ const language = (hf) => ({
// inputs = 'My name is Wolfgang and I live in Amsterdam',
// parameters = {"src_lang": "en_XX", "tgt_lang": "fr_XX"}
async translation(
inputs, parameters = {}, model = defaultModels.translation
inputs,
parameters = {},
model = defaultModels.translation,
) {
const args = { inputs, parameters, model };
const res = await callAPI(hf, 'hf.translation', args);
Expand Down Expand Up @@ -145,14 +136,11 @@ const language = (hf) => ({
}
*/

async sentenceSimilarity(
inputs,
model = defaultModels.sentenceSimilarity,
) {
async sentenceSimilarity(inputs, model = defaultModels.sentenceSimilarity) {
const args = { inputs, model };
const res = await callAPI(hf, 'hf.sentenceSimilarity', args);
return res;
}
},
});

module.exports = { language };
10 changes: 2 additions & 8 deletions lib/huggingface/utils/multimodal.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,9 @@ const { DEFAULT_MODELS } = require('../config.json');

const defaultModels = DEFAULT_MODELS.multimodal;

//......Multimodal.......

const multimodal = (hf) => ({

// inputs = "That is a happy person",
async featureExtraction(
inputs,
model = defaultModels.featureExtraction,
) {
async featureExtraction(inputs, model = defaultModels.featureExtraction) {
const args = { inputs, model };
const res = await callAPI(hf, 'hf.featureExtraction', args);
return res;
Expand Down Expand Up @@ -47,7 +41,7 @@ const multimodal = (hf) => ({
const args = { inputs, model };
const res = await callAPI(hf, 'hf.documentQuestionAnswering', args);
return res;
}
},
});

module.exports = { multimodal };
9 changes: 2 additions & 7 deletions lib/huggingface/utils/tabular.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ const { DEFAULT_MODELS } = require('../config.json');

const defaultModels = DEFAULT_MODELS.tabular;

//......Tabular.......

const tabular = (hf) => ({
/*
inputs = {
Expand All @@ -20,10 +18,7 @@ const tabular = (hf) => ({
},
},
*/
async tabularRegression(
inputs,
model = defaultModels.tabularRegression,
) {
async tabularRegression(inputs, model = defaultModels.tabularRegression) {
const args = { inputs, model };
const res = await callAPI(hf, 'hf.tabularRegression', args);
return res;
Expand Down Expand Up @@ -53,7 +48,7 @@ const tabular = (hf) => ({
const args = { inputs, model };
const res = await callAPI(hf, 'hf.tabularClassification', args);
return res;
}
},
});

module.exports = { tabular };
4 changes: 1 addition & 3 deletions test/huggingface/audio.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ const { Chat } = huggingface;

const API_KEY = process.env.HUGGINGFACE_API_KEY;

const {
audio: uAudio,
} = utils;
const { audio: uAudio } = utils;

const FILES = process.cwd() + '/files/huggingface/';
const AUDIOS = FILES + 'audios';
Expand Down
10 changes: 4 additions & 6 deletions test/huggingface/computerVision.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ const { Chat } = huggingface;

const API_KEY = process.env.HUGGINGFACE_API_KEY;

const {
computerVision: uComputerVision,
} = utils;
const { computerVision: uComputerVision } = utils;

const FILES = process.cwd() + '/files/huggingface/';
const IMAGES = FILES + 'images';
Expand Down Expand Up @@ -91,10 +89,10 @@ describe('computerVision', () => {

it('textToImage', async () => {
const inputs =
'award winning high resolution photo of a giant tortoise' +
'/((ladybird)) hybrid, [trending on artstation]';
'award winning high resolution photo of a giant tortoise' +
'/((ladybird)) hybrid, [trending on artstation]';
const res = await computerVision.textToImage(inputs, {
negative_prompt: 'blurry'
negative_prompt: 'blurry',
});

assert.ok(res instanceof Blob);
Expand Down
4 changes: 1 addition & 3 deletions test/huggingface/custom.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ const { Chat } = huggingface;

const API_KEY = process.env.HUGGINGFACE_API_KEY;

const {
custom: uCustom,
} = utils;
const { custom: uCustom } = utils;

describe('custom', () => {
let custom;
Expand Down
4 changes: 1 addition & 3 deletions test/huggingface/language.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ const { Chat } = huggingface;

const API_KEY = process.env.HUGGINGFACE_API_KEY;

const {
language: uLanguage,
} = utils;
const { language: uLanguage } = utils;

describe('language', () => {
let language;
Expand Down
4 changes: 1 addition & 3 deletions test/huggingface/multimodal.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ const { Chat } = huggingface;

const API_KEY = process.env.HUGGINGFACE_API_KEY;

const {
multimodal: uMultimodal,
} = utils;
const { multimodal: uMultimodal } = utils;

const FILES = process.cwd() + '/files/huggingface/';
const IMAGES = FILES + 'images';
Expand Down
4 changes: 1 addition & 3 deletions test/huggingface/tabular.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ const { Chat } = huggingface;

const API_KEY = process.env.HUGGINGFACE_API_KEY;

const {
tabular: uTabular,
} = utils;
const { tabular: uTabular } = utils;

describe('tabular', () => {
let tabular;
Expand Down

0 comments on commit 18eb318

Please sign in to comment.