Skip to content

Commit

Permalink
asd
Browse files Browse the repository at this point in the history
  • Loading branch information
elitan committed Nov 6, 2023
1 parent 20c95cb commit e3473b3
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 73 deletions.
2 changes: 1 addition & 1 deletion worker/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ while true; do
pnpm transcribe
pnpm openai
pnpm images
pnpm piper
pnpm tts
# pnpm elevenlabs (out of tokens)
for (( i=1200; i>=0; i-- )); do
echo "$i"
Expand Down
3 changes: 2 additions & 1 deletion worker/src/4-openai-images.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ async function main() {
.orderBy('id', 'desc')
.execute();

console.log(`Found ${articlesToRefine.length} articles to refine`);
for (const article of articlesToRefine) {
if (!article.imagePrompt) {
console.log('No image prompt found for article', article.id);
Expand All @@ -37,7 +38,7 @@ async function main() {
n: 1,
quality: 'standard',
size: '1792x1024',
style: 'vivid',
style: 'natural',
});

if (!image.data[0].b64_json) {
Expand Down
1 change: 1 addition & 0 deletions worker/src/5-openai-tts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ async function main() {
.orderBy('id', 'desc')
.execute();

console.log(`Found ${articlesToRefine.length} articles to refine`);
for (const article of articlesToRefine) {
console.log(`Generate audio for article ${article.id}`);

Expand Down
12 changes: 4 additions & 8 deletions worker/src/playground.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,10 @@ async function main() {
const prompt =
'A Swedish flag fluttering against a backdrop of a city skyline, symbolizing the Swedish labor market. In the foreground, a contract is laid out on a table, an ink pen resting on top of it. The contract represents the collective agreement signed by Klarna.';

const image = await openai.images.generate({
model: 'dall-e-3',
prompt,
response_format: 'b64_json',
n: 1,
quality: 'standard',
size: '1792x1024',
style: 'vivid',
const image = await openai.audio.transcriptions.create({
model: 'whisper-1',
response_format: 'text',
prompt: 'asd',
});

console.log(image.data[0]);
Expand Down
135 changes: 72 additions & 63 deletions worker/src/tmp-backfill-translations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,86 +6,95 @@ async function main() {
// get all articles that are not yet translated
const articlesToTranslate = await db
.selectFrom('articles')
.select(['id', 'title', 'slug', 'category', 'body', 'audioUrl'])
.where('title', 'is not', null)
.where('isRelatedToSweden', '=', true)
.select(['id', 'audioUrl'])
.where('audioUrl', 'is not', null)
.execute();

for (const articleToTranslate of articlesToTranslate) {
console.log({ articleToTranslate });

const { id, title, slug, body, category } = articleToTranslate;
const { id, audioUrl } = articleToTranslate;

if (!title || !body || !category) {
console.log('title, body or category is null');
if (!audioUrl) {
console.log('audioUrl is null');
continue;
}

// insert the en version

await db
.insertInto('articleTranslations')
.values({
articleId: id,
language: 'en',
title,
slug,
body,
category,
isPublished: true,
.updateTable('articleTranslations')
.set({
audioUrl,
})
.where('articleId', '=', id)
.where('language', '=', 'en')
.execute();
}

const languages = [
'fi',
'ar',
'ckb',
'so',
'ru',
'uk',
'fa',
'es',
'de',
'fr',
];
for (const language of languages) {
console.log(`generate article in ${language}`);
// insert the en version

const headlineTranslated = await translate({
from: 'en',
to: language,
text: title,
});
// await db
// .insertInto('articleTranslations')
// .values({
// articleId: id,
// language: 'en',
// title,
// slug,
// body,
// category,
// isPublished: true,
// })
// .execute();

const bodyTranslated = await translate({
from: 'en',
to: language,
text: body,
});
// const languages = [
// 'fi',
// 'ar',
// 'ckb',
// 'so',
// 'ru',
// 'uk',
// 'fa',
// 'es',
// 'de',
// 'fr',
// ];
// for (const language of languages) {
// console.log(`generate article in ${language}`);

const categoryTranslated = await translate({
from: 'en',
to: language,
text: category,
});
// const headlineTranslated = await translate({
// from: 'en',
// to: language,
// text: title,
// });

await db
.insertInto('articleTranslations')
.values({
articleId: id,
language: language,
title: headlineTranslated,
slug: slugify(headlineTranslated, {
lower: true,
strict: true,
}),
body: bodyTranslated,
category: categoryTranslated,
isPublished: true,
})
.execute();
}
}
// const bodyTranslated = await translate({
// from: 'en',
// to: language,
// text: body,
// });

// const categoryTranslated = await translate({
// from: 'en',
// to: language,
// text: category,
// });

// await db
// .insertInto('articleTranslations')
// .values({
// articleId: id,
// language: language,
// title: headlineTranslated,
// slug: slugify(headlineTranslated, {
// lower: true,
// strict: true,
// }),
// body: bodyTranslated,
// category: categoryTranslated,
// isPublished: true,
// })
// .execute();
// }
// }

console.log(articlesToTranslate.length);
}
Expand Down

0 comments on commit e3473b3

Please sign in to comment.