Comments (1)
do the same for tags:
const openai = require('openai')('your-api-key-here');
const csv = require('csv-parser');
const fs = require('fs');
const inputFilePath = 'input.csv';
const outputFilePath = 'output.csv';
const categories = ['nature', 'technology', 'popculture', 'gaming', 'music', 'fantasy', 'sci-fi', 'history', 'horror', 'joy', 'feminine', 'masculine'];
const results = [];
const processRow = (row) => {
const name = row.name.trim();
openai.complete({
engine: 'text-davinci-002',
prompt: `Generate tags for the color name "${name}". Categories: ${categories.join(', ')}`,
maxTokens: 50,
n: 1,
stop: '\n',
temperature: 0.7,
presencePenalty: 0.3,
frequencyPenalty: 0.3,
}).then((res) => {
const tags = res.data.choices[0].text.trim().split(',').map((t) => t.trim());
results.push({ name, tags });
if (results.length === count) {
saveResults();
}
}).catch((err) => {
console.error(err);
});
};
const saveResults = () => {
const stream = fs.createWriteStream(outputFilePath, { flags: 'a' });
stream.write(`name,tags\n`);
results.forEach((r) => {
const tagsString = r.tags.join(';');
stream.write(`${r.name},${tagsString}\n`);
});
stream.end();
};
fs.createReadStream(inputFilePath)
.pipe(csv())
.on('data', processRow)
.on('end', () => {
console.log('Finished processing all rows.');
});
from color-names.
Related Issues (20)
- Fix: Shell command built from environment values
- Examples In README Do Not Work HOT 1
- Adding ton of colors! HOT 1
- Fix typo "sematnic". HOT 2
- Add Chinese traditional colors HOT 6
- REST API: round response values to 5 decimals
- get some color names from https://colornames.org/ HOT 5
- just an idea HOT 1
- Suggestion For Name Recognition HOT 1
- Color issue HOT 1
- When passing in a hex code to get color name, the hex code needs to be in lower case. So it would be better to accept uppercase too HOT 1
- Colour Lovers? HOT 1
- Name collision + typo HOT 2
- Yet another name collision HOT 2
- Bad color name for light red and light blue HOT 2
- Professenial color names HOT 1
- Spelling error in README.md HOT 9
- Create Viz of names over time
- [issue] `namedColors.find` isn't a function? HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from color-names.