Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Imagen #276

Closed
wants to merge 15 commits into from
Closed

Imagen #276

wants to merge 15 commits into from

Conversation

junyanxu
Copy link
Collaborator

@junyanxu junyanxu commented Oct 9, 2024

Doc change not applied yet. Please focus on the main logic.

types/requests.ts Outdated Show resolved Hide resolved
types/generated-media.ts Show resolved Hide resolved
types/requests.ts Outdated Show resolved Hide resolved
types/requests.ts Outdated Show resolved Hide resolved
types/requests.ts Outdated Show resolved Hide resolved
types/generated-media.ts Show resolved Hide resolved
package.json Show resolved Hide resolved
@@ -46,6 +46,7 @@
"devDependencies": {
"@changesets/cli": "^2.27.1",
"@esm-bundle/chai": "^4.3.4-fix.0",
"@google-cloud/asset": "^5.7.0",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is this used?

@@ -0,0 +1,48 @@
export type PredictServiceBasicValueType =
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed none of the new types that are added seem to be exported from types/index.ts which means the user won't have access to them. I assume you want the developer to have access to some of them, can you make sure they're exported from types/index.ts?

src/requests/request-helpers.ts Show resolved Hide resolved
*/
negativePrompt?: string;
/**
* Number of images to generate. Range: 1..8.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I tried passing numberOfImages: 8, I got an error saying 4 is the max.

GoogleGenerativeAIFetchError: [GoogleGenerativeAI Error]: Error fetching from https://generativelanguage.googleapis.com/v1beta/models/imagen-3.0-generate-001:predict: [400 Bad Request] Image generation failed with the following error: Invalid sample count 8 in request. Max number of samples prebuilt model can return is 4. Min number is 1

types/requests.ts Outdated Show resolved Hide resolved
Comment on lines 266 to 273
/**
* Width of the image. One of the Width/Height sizes must be 256 or 1024.
*/
width?: number;
/**
* Height of the image. One of the Width/Height sizes must be 256 or 1024.
*/
height?: number;
Copy link
Collaborator

@dlarocque dlarocque Oct 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I specify width and height to 256, I get back an image that is 1024x1024. I'm not sure whether this is a backend issue or not.

import {
  GoogleGenerativeAI,
} from "@google/generative-ai";
import { writeFileSync } from 'fs';

async function imageGeneration() {
  const genAI = new GoogleGenerativeAI(process.env.API_KEY);
  const model = genAI.getImageGenerationModel({
    model: "imagen-3.0-generate-001",
  });
  const result = await model.generateImages(
    {
      prompt: "A fluffy cat",
      numberOfImages: 1, 
      width: 256,
      height: 256,
    });
  writeFileSync('image.png', new Buffer(result.images[0].imageBytes, 'base64'));
}
async function runAll() {
  await imageGeneration();
}

runAll();

image

request: ImageGenerationRequest,
): PredictRequest {
const instances = [{ prompt: request.prompt }];
const sampleImageSize = Math.max(request.width || 0, request.height || 0);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we use the max of width and height as the image size and only pass that one dimension, why not just have one imageSize option?

@junyanxu
Copy link
Collaborator Author

Sorry guys, I messes up the git after doing a merge. I open up a new branch for us to review.

@junyanxu junyanxu closed this Oct 18, 2024
@junyanxu junyanxu deleted the imagen branch October 18, 2024 19:25
@junyanxu junyanxu mentioned this pull request Oct 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants