-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8c7800a
commit e333533
Showing
12 changed files
with
222 additions
and
773 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
*.db | ||
*.py[cod] | ||
.web | ||
__pycache__/ | ||
__pycache__/ | ||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,16 @@ | ||
import jax | ||
import numpy as np | ||
from flax.jax_utils import replicate | ||
from flax.training.common_utils import shard | ||
from openai import OpenAI | ||
|
||
from diffusers import FlaxStableDiffusionPipeline | ||
client = OpenAI() | ||
|
||
pipeline, params = FlaxStableDiffusionPipeline.from_pretrained( | ||
"CompVis/stable-diffusion-v1-4", revision="bf16", dtype=jax.numpy.bfloat16 | ||
) | ||
|
||
def text2img(prompt): | ||
print(prompt) | ||
response = client.images.generate( | ||
model="dall-e-3", | ||
prompt=prompt, | ||
size="1024x1024", | ||
quality="standard", | ||
n=1, | ||
) | ||
|
||
def text2img(prompt, params): | ||
prng_seed = jax.random.PRNGKey(0) | ||
num_inference_steps = 50 | ||
|
||
num_samples = jax.device_count() | ||
prompt = num_samples * [prompt] | ||
prompt_ids = pipeline.prepare_inputs(prompt) | ||
|
||
# shard inputs and rng | ||
params = replicate(params) | ||
prng_seed = jax.random.split(prng_seed, num_samples) | ||
prompt_ids = shard(prompt_ids) | ||
|
||
images = pipeline(prompt_ids, params, prng_seed, | ||
num_inference_steps, jit=True).images | ||
images = pipeline.numpy_to_pil(np.asarray( | ||
images.reshape((num_samples,) + images.shape[-3:]))) | ||
|
||
# Save each image | ||
for i, image in enumerate(images): | ||
# Define the path where you want to save the image | ||
image_path = f"/assets/meal{i}.png" | ||
image.save(image_path) # Save the image | ||
print(f"Image saved as {image_path}") | ||
|
||
|
||
# text2img(prompt, params) | ||
return response.data[0].url |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters