Compare commits
2 Commits
6eec0890a7
...
243f107ef5
| Author | SHA1 | Date | |
|---|---|---|---|
| 243f107ef5 | |||
| 9ad4e7972b |
@ -35,7 +35,7 @@ function extractJsonFromText(text: string): any | null {
|
||||
logger.info(`Starting photo download process with prompt: "${HARDCODED_USER_PROMPT}"`);
|
||||
|
||||
// 1. Extract keywords from the hardcoded prompt
|
||||
const keywords = ["food", "perfume", "accesory", "jewelry", "shoes", "bags", "watches", "sunglasses", "hats", "scarves", "belts", "wallets", "gloves", "ties", "cufflinks", "brooches", "necklaces", "bracelets", "earrings"];
|
||||
const keywords = ["fullbody portrait girl", "fullbody portrait 18y girl", "fullbody portrait cute girl", "fullbody portrait blond girl", "fullbody portrait 20y girl"];
|
||||
|
||||
if (!keywords || keywords.length === 0) {
|
||||
logger.error("Could not extract keywords from prompt. Exiting.");
|
||||
@ -48,7 +48,7 @@ function extractJsonFromText(text: string): any | null {
|
||||
for (const keyword of keywords) {
|
||||
try {
|
||||
logger.info(`Downloading photos for keyword: "${keyword}"`);
|
||||
const downloadedPaths = await downloadImagesFromPinterestSearch(`${keyword} product photo`, PHOTOS_PER_KEYWORD);
|
||||
const downloadedPaths = await downloadImagesFromPinterestSearch(`${keyword}`, PHOTOS_PER_KEYWORD);
|
||||
if (downloadedPaths.length > 0) {
|
||||
logger.info(`Successfully downloaded ${downloadedPaths.length} images for "${keyword}"`);
|
||||
totalDownloads += downloadedPaths.length;
|
||||
|
||||
54
src/tools/embed_prompt_to_png.ts
Normal file
54
src/tools/embed_prompt_to_png.ts
Normal file
@ -0,0 +1,54 @@
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import { callLMStudioAPIWithFile } from '../lib/lmstudio';
|
||||
import { embedJsonToPng } from '../lib/util';
|
||||
|
||||
const imageDir = 'C:\\Users\\fm201\\Desktop\\vton\\bags';
|
||||
|
||||
async function processImages() {
|
||||
try {
|
||||
const files = fs.readdirSync(imageDir);
|
||||
const imageFiles = files.filter(file => /\.(png)$/i.test(file));
|
||||
|
||||
for (const imageFile of imageFiles) {
|
||||
const imagePath = path.join(imageDir, imageFile);
|
||||
console.log(`Processing ${imagePath}...`);
|
||||
|
||||
const prompt = `
|
||||
Based on the handbag in the image, generate 10 outfit prompts that would complement it.
|
||||
Each prompt should be a short, descriptive sentence of around 20 words.
|
||||
Return the result in the following JSON format:
|
||||
{"result": ["outfit prompt 1", "outfit prompt 2", ...]}
|
||||
`;
|
||||
|
||||
try {
|
||||
const response = await callLMStudioAPIWithFile(imagePath, prompt);
|
||||
let outfitPrompts;
|
||||
|
||||
if (typeof response === 'string') {
|
||||
try {
|
||||
outfitPrompts = JSON.parse(response);
|
||||
} catch (e) {
|
||||
console.error(`Failed to parse JSON string for ${imageFile}:`, response);
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
outfitPrompts = response;
|
||||
}
|
||||
|
||||
if (outfitPrompts && outfitPrompts.result) {
|
||||
await embedJsonToPng(imagePath, outfitPrompts);
|
||||
console.log(`Successfully embedded prompts into ${imageFile}`);
|
||||
} else {
|
||||
console.error(`Invalid JSON response for ${imageFile}:`, response);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(`Failed to process ${imageFile}:`, error);
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error reading image directory:', error);
|
||||
}
|
||||
}
|
||||
|
||||
processImages();
|
||||
Reference in New Issue
Block a user