Spaces:
Runtime error
Runtime error
Delete keras_txt2img.py
Browse files- keras_txt2img.py +0 -116
keras_txt2img.py
DELETED
|
@@ -1,116 +0,0 @@
|
|
| 1 |
-
from huggingface_hub import from_pretrained_keras
|
| 2 |
-
from keras_cv import models
|
| 3 |
-
from tensorflow import keras
|
| 4 |
-
|
| 5 |
-
import gradio as gr
|
| 6 |
-
|
| 7 |
-
stable_model_list = [
|
| 8 |
-
"keras-dreambooth/dreambooth_diffusion_model"
|
| 9 |
-
]
|
| 10 |
-
|
| 11 |
-
stable_prompt_list = [
|
| 12 |
-
"a photo of a man.",
|
| 13 |
-
"a photo of a girl."
|
| 14 |
-
]
|
| 15 |
-
|
| 16 |
-
stable_negative_prompt_list = [
|
| 17 |
-
"bad, ugly",
|
| 18 |
-
"deformed"
|
| 19 |
-
]
|
| 20 |
-
|
| 21 |
-
def keras_stable_diffusion(
|
| 22 |
-
model_path:str,
|
| 23 |
-
prompt:str,
|
| 24 |
-
negative_prompt:str,
|
| 25 |
-
guidance_scale:int,
|
| 26 |
-
num_inference_step:int,
|
| 27 |
-
height:int,
|
| 28 |
-
width:int,
|
| 29 |
-
):
|
| 30 |
-
|
| 31 |
-
keras.mixed_precision.set_global_policy("mixed_float16")
|
| 32 |
-
|
| 33 |
-
sd_dreambooth_model = models.StableDiffusion(
|
| 34 |
-
img_width=height,
|
| 35 |
-
img_height=width
|
| 36 |
-
)
|
| 37 |
-
|
| 38 |
-
db_diffusion_model = from_pretrained_keras(model_path)
|
| 39 |
-
sd_dreambooth_model._diffusion_model = db_diffusion_model
|
| 40 |
-
|
| 41 |
-
generated_images = sd_dreambooth_model.text_to_image(
|
| 42 |
-
prompt=prompt,
|
| 43 |
-
negative_prompt=negative_prompt,
|
| 44 |
-
num_steps=num_inference_step,
|
| 45 |
-
unconditional_guidance_scale=guidance_scale
|
| 46 |
-
)
|
| 47 |
-
|
| 48 |
-
return generated_images
|
| 49 |
-
|
| 50 |
-
def keras_stable_diffusion_app():
|
| 51 |
-
with gr.Tab('Keras Diffusion'):
|
| 52 |
-
keras_text2image_model_path = gr.Dropdown(
|
| 53 |
-
choices=stable_model_list,
|
| 54 |
-
value=stable_model_list[0],
|
| 55 |
-
label='Text-Image Model Id'
|
| 56 |
-
)
|
| 57 |
-
|
| 58 |
-
keras_text2image_prompt = gr.Textbox(
|
| 59 |
-
lines=1,
|
| 60 |
-
value=stable_prompt_list[0],
|
| 61 |
-
label='Prompt'
|
| 62 |
-
)
|
| 63 |
-
|
| 64 |
-
keras_text2image_negative_prompt = gr.Textbox(
|
| 65 |
-
lines=1,
|
| 66 |
-
value=stable_negative_prompt_list[0],
|
| 67 |
-
label='Negative Prompt'
|
| 68 |
-
)
|
| 69 |
-
|
| 70 |
-
with gr.Accordion("Advanced Options", open=False):
|
| 71 |
-
keras_text2image_guidance_scale = gr.Slider(
|
| 72 |
-
minimum=0.1,
|
| 73 |
-
maximum=15,
|
| 74 |
-
step=0.1,
|
| 75 |
-
value=7.5,
|
| 76 |
-
label='Guidance Scale'
|
| 77 |
-
)
|
| 78 |
-
|
| 79 |
-
keras_text2image_num_inference_step = gr.Slider(
|
| 80 |
-
minimum=1,
|
| 81 |
-
maximum=100,
|
| 82 |
-
step=1,
|
| 83 |
-
value=50,
|
| 84 |
-
label='Num Inference Step'
|
| 85 |
-
)
|
| 86 |
-
|
| 87 |
-
keras_text2image_height = gr.Slider(
|
| 88 |
-
minimum=128,
|
| 89 |
-
maximum=1280,
|
| 90 |
-
step=32,
|
| 91 |
-
value=512,
|
| 92 |
-
label='Image Height'
|
| 93 |
-
)
|
| 94 |
-
|
| 95 |
-
keras_text2image_width = gr.Slider(
|
| 96 |
-
minimum=128,
|
| 97 |
-
maximum=1280,
|
| 98 |
-
step=32,
|
| 99 |
-
value=768,
|
| 100 |
-
label='Image Height'
|
| 101 |
-
)
|
| 102 |
-
|
| 103 |
-
keras_text2image_predict = gr.Button(value='Generator')
|
| 104 |
-
|
| 105 |
-
variables = {
|
| 106 |
-
"model_path": keras_text2image_model_path,
|
| 107 |
-
"prompt": keras_text2image_prompt,
|
| 108 |
-
"negative_prompt": keras_text2image_negative_prompt,
|
| 109 |
-
"guidance_scale": keras_text2image_guidance_scale,
|
| 110 |
-
"num_inference_step": keras_text2image_num_inference_step,
|
| 111 |
-
"height": keras_text2image_height,
|
| 112 |
-
"width": keras_text2image_width,
|
| 113 |
-
"predict": keras_text2image_predict
|
| 114 |
-
}
|
| 115 |
-
|
| 116 |
-
return variables
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|