Spaces:
Runtime error
Runtime error
Eduardo Matallanas commited on
Commit ·
befbd95
1
Parent(s): 1a69c6e
Added the app for the demo space
Browse files- README.md +3 -3
- app.py +58 -0
- requirements.txt +3 -0
README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
| 1 |
---
|
| 2 |
-
title: Ignatius
|
| 3 |
-
emoji:
|
| 4 |
colorFrom: yellow
|
| 5 |
-
colorTo:
|
| 6 |
sdk: gradio
|
| 7 |
sdk_version: 3.21.0
|
| 8 |
app_file: app.py
|
|
|
|
| 1 |
---
|
| 2 |
+
title: Ignatius Farray - "All right!!!"
|
| 3 |
+
emoji: 🤡
|
| 4 |
colorFrom: yellow
|
| 5 |
+
colorTo: purple
|
| 6 |
sdk: gradio
|
| 7 |
sdk_version: 3.21.0
|
| 8 |
app_file: app.py
|
app.py
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from huggingface_hub import from_pretrained_keras
|
| 2 |
+
from keras_cv
|
| 3 |
+
import gradio as gr
|
| 4 |
+
from tensorflow import keras
|
| 5 |
+
|
| 6 |
+
keras.mixed_precision.set_global_policy("mixed_float16")
|
| 7 |
+
# load keras model
|
| 8 |
+
resolution = 512
|
| 9 |
+
dreambooth_model = keras_cv.models.StableDiffusion(
|
| 10 |
+
img_width=resolution, img_height=resolution, jit_compile=True,
|
| 11 |
+
)
|
| 12 |
+
loaded_diffusion_model = from_pretrained_keras("keras-dreambooth/ignatius")
|
| 13 |
+
dreambooth_model._diffusion_model = loaded_diffusion_model
|
| 14 |
+
|
| 15 |
+
# generate images
|
| 16 |
+
def generate_images(prompt, negative_prompt, num_imgs_to_gen, num_steps, guidance_scale):
|
| 17 |
+
"""
|
| 18 |
+
This function is used to generate images using our fine-tuned keras dreambooth stable diffusion model.
|
| 19 |
+
Args:
|
| 20 |
+
prompt (str): The text input given by the user based on which images will be generated.
|
| 21 |
+
negative_prompt (srt): The text to eliminate from the generation some concepts.
|
| 22 |
+
num_imgs_to_gen (int): The number of images to be generated using given prompt.
|
| 23 |
+
num_steps (int): The number of denoising steps
|
| 24 |
+
guidance_scale (double): Increasing guidance makes generation follow more closely to the prompt.
|
| 25 |
+
Returns:
|
| 26 |
+
generated_img (List): List of images that were generated using the model
|
| 27 |
+
"""
|
| 28 |
+
generated_images = sd_dreambooth_model.text_to_image(
|
| 29 |
+
prompt,
|
| 30 |
+
negative_prompt=negative_prompt,
|
| 31 |
+
batch_size=num_imgs_to_gen,
|
| 32 |
+
num_steps=num_steps,
|
| 33 |
+
unconditional_guidance_scale=guidance_scale
|
| 34 |
+
)
|
| 35 |
+
return generated_images
|
| 36 |
+
|
| 37 |
+
with gr.Blocks() as demo:
|
| 38 |
+
gr.HTML("<h2 style=\"font-size: 2em; font-weight: bold\" align=\"center\">Ignatius Farray - The cavern of the muffled scream</h2>")
|
| 39 |
+
with gr.Row():
|
| 40 |
+
with gr.Column():
|
| 41 |
+
prompt = gr.Textbox(lines=1, value="ignatius in a standup comedy spectacle", label="Base Prompt")
|
| 42 |
+
negative_prompt = gr.Textbox(lines=1, value="deformed", value="bad anatomy, blurry, ugly", label="Negative Prompt")
|
| 43 |
+
samples = gr.Slider(minimum=1, maximum=10, default=1, step=1, label="Number of Image")
|
| 44 |
+
num_steps = gr.Slider(label="Inference Steps",value=50)
|
| 45 |
+
guidance_scale = gr.Number(label="Guidance scale", value=7.5)
|
| 46 |
+
run = gr.Button(value="Run")
|
| 47 |
+
with gr.Column():
|
| 48 |
+
gallery = gr.Gallery(label="Outputs").style(grid=(1,2))
|
| 49 |
+
|
| 50 |
+
run.click(generate_images, inputs=[prompt, negative_prompt, samples, num_steps, guidance_scale], outputs=gallery)
|
| 51 |
+
|
| 52 |
+
gr.Examples([["ignatius on the moon","bad anatomy, blurry, ugly", 2, 150, 15],
|
| 53 |
+
["A photo of ignatius person inside a box","bad anatomy, blurry, ugly", 2, 150, 15],
|
| 54 |
+
["A closeup portrait of ignatius, highly detailed, high qulity","bad anatomy, blurry, ugly", 2, 150, 15]],
|
| 55 |
+
[prompt, negative_prompt, samples, num_steps, guidance_scale], gallery, generate_images)
|
| 56 |
+
gr.Markdown('\n Demo created by: <a href=\"https://huggingface.co/matallanas/\">Eduardo Matallanas</a>')
|
| 57 |
+
|
| 58 |
+
demo.launch(debug=True)
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
keras-cv
|
| 2 |
+
tensorflow
|
| 3 |
+
huggingface-hub
|