added image.save() using slugify and mkdir
Browse files
app.py
CHANGED
|
@@ -1,7 +1,8 @@
|
|
| 1 |
import torch
|
| 2 |
from diffusers import DiffusionPipeline, AutoencoderKL
|
| 3 |
import gradio as gr
|
| 4 |
-
|
|
|
|
| 5 |
|
| 6 |
# Function to load the model.
|
| 7 |
def load_model():
|
|
@@ -31,14 +32,25 @@ def generate_image(prompt, num_inference_steps):
|
|
| 31 |
num_inference_steps_int = int(num_inference_steps)
|
| 32 |
|
| 33 |
image = pipe(prompt, num_inference_steps=num_inference_steps_int).images[0]
|
| 34 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
return image
|
| 36 |
|
| 37 |
iface = gr.Interface(
|
| 38 |
fn=generate_image,
|
| 39 |
inputs=[
|
| 40 |
gr.Textbox(label="Enter a prompt for the image"),
|
| 41 |
-
gr.Textbox(label="Number of Inference Steps")
|
| 42 |
],
|
| 43 |
outputs="image",
|
| 44 |
title="Stable Diffusion XL Text2Image Finetune Dreambooth",
|
|
|
|
| 1 |
import torch
|
| 2 |
from diffusers import DiffusionPipeline, AutoencoderKL
|
| 3 |
import gradio as gr
|
| 4 |
+
from pathlib import Path
|
| 5 |
+
from slugify import slugify
|
| 6 |
|
| 7 |
# Function to load the model.
|
| 8 |
def load_model():
|
|
|
|
| 32 |
num_inference_steps_int = int(num_inference_steps)
|
| 33 |
|
| 34 |
image = pipe(prompt, num_inference_steps=num_inference_steps_int).images[0]
|
| 35 |
+
|
| 36 |
+
# save the generated image
|
| 37 |
+
DIR_NAME="./images/"
|
| 38 |
+
dirpath = Path(DIR_NAME)
|
| 39 |
+
# create parent dir if doesn't exist
|
| 40 |
+
dirpath.mkdir(parents=True, exist_ok=True)
|
| 41 |
+
# create filename for image based on prompt
|
| 42 |
+
image_name = f'{slugify(prompt)}.jpg'
|
| 43 |
+
image_path = dirpath / image_name
|
| 44 |
+
image.save(image_path)
|
| 45 |
+
print(image_name)
|
| 46 |
+
|
| 47 |
return image
|
| 48 |
|
| 49 |
iface = gr.Interface(
|
| 50 |
fn=generate_image,
|
| 51 |
inputs=[
|
| 52 |
gr.Textbox(label="Enter a prompt for the image"),
|
| 53 |
+
gr.Textbox(label="Number of Inference Steps min=10 or max=50")
|
| 54 |
],
|
| 55 |
outputs="image",
|
| 56 |
title="Stable Diffusion XL Text2Image Finetune Dreambooth",
|