Skip to content
This repository has been archived by the owner on Sep 1, 2022. It is now read-only.

n Input Image on web site ? #3

Open
kilik128 opened this issue Jul 25, 2022 · 1 comment
Open

n Input Image on web site ? #3

kilik128 opened this issue Jul 25, 2022 · 1 comment

Comments

@kilik128
Copy link

Any idea why we got not the same result when Input Image on web site ?
when use api is look give like unfinished result

chrome_2022-07-25_20-45-02

chrome_2022-07-25_20-44-58



var Prompt = "wool";
var Style = 0;
var Weigth =  "HIGH"	;//  "LOW" "MEDIUM" "HIGH"
var Path_Import = String.raw`V:\Generation\Movie\01`;
var Path_Export = String.raw`V:\Generation\Movie\02`;
var Frequency = 10;
var Img = true;

const { buildDefaultInstance } = require('wombo-dream-api');
const fs = require('fs');
const https = require("https");
var files = fs.readdirSync(Path_Import ); // './Craft/'
//console.log(files);
files = shuffle(files );


function shuffle(array ) {
  let currentIndex = array.length,  randomIndex;

  // While there remain elements to shuffle.
  while (currentIndex != 0) {

    // Pick a remaining element.
    randomIndex = Math.floor(Math.random() * currentIndex);
    currentIndex--;

    // And swap it with the current element.
    [array[currentIndex], array[randomIndex]] = [
      array[randomIndex], array[currentIndex]];
  }

  return array;
}


//goonous
(async () => {
	try {
		const credentials = {
			email: '@.com',
			password: '',
		};

		// signin is automatically done when you interract with the api if you pass credentials
		const wombo = buildDefaultInstance(credentials);

		// if you want to sign up as new user:
		// await wombo.authentifier.signUp(credentials);

		// fetch all styles
		const styles = await wombo.fetchStyles();
		console.log(styles.map((style) => `[${style.id}] ${style.name}`));



		for (const filename of files) { 
		//for (let i = 0; i < 1000; i++) {
 		//await delay(2500);

		console.log(filename );

		// upload image [ONLY JPEG SUPPORTED]
		const uploadedImage = await wombo.uploadImage(
			fs.readFileSync(Path_Import +"/"+ filename)
			//fs.readFileSync('./image.jpeg')
		);

		
 	

		// generate picture from image
		const generatedTask = await wombo.generatePicture(
			Prompt ,
			styles[Style ].id,
			(taskInProgress) => {
				console.log(
					`[${taskInProgress.id}]: ${taskInProgress.state} | step: ${taskInProgress.photo_url_list.length}`
				);
			},
			{mediastore_id: uploadedImage.id,  weight: Weigth ,frequency: Frequency  } //

			);


		console.log(
			`[${generatedTask.id}]: ${generatedTask.state} | final url: ${generatedTask.result?.final}`
		);

	    // to interract with the gallery, YOU NEED TO HAVE A USERNAME!
	    // if you just created the account and it doesn't have a username, set it with:
	    // await wombo.setUsername('myusername');

	    // save an image in the gallery
		const savedTask = await wombo.saveTaskToGallery(
			generatedTask.id,
			'my wonderful creation',
			true,
			true
		);

		console.log('image saved!');

		// URL of the image
                const url = generatedTask.result?.final;

https.get(url, (res) => {
  const path = Path_Export + "/" + filename  + generatedTask.id+".jpeg";
  const writeStream = fs.createWriteStream(path);

  res.pipe(writeStream);

  writeStream.on("finish", () => {
    writeStream.close();
    console.log("Download Completed");
  });
});

}




		// obtain gallery tasks
		const galleryTasks = await wombo.fetchGalleryTasks();

		//console.log(galleryTasks);
	} catch (error) {
		console.error(error);
	}
})();




















@leopoldhub
Copy link
Owner

leopoldhub commented Jul 25, 2022

Hi, I just checked and you are right, there is a slight difference between the "final" image and the last image in "photo_url_list".
however, the "final" image have a much better resolution (see the images bellow)

The final image (960x1568)

final
2022-07-25_21-26

The last photo_url_list image (432x704)

19
2022-07-25_21-26_1

If you wish to obtain the exact same image as the website, you can use generatedTask.photo_url_list[generatedTask.photo_url_list.lenght - 2]

If you wish to obtain the "final" image in full resolution, use
generatedTask.result?.final

I hope that this awnser your question, please let me know if you have other troubles ^^

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants