Spaces:
Runtime error
Runtime error
Commit
·
c9f916a
1
Parent(s):
8a04a17
Upload app.py
Browse filesapp.py first version
app.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from huggingface_hub import from_pretrained_keras
|
| 2 |
+
from keras_cv import models
|
| 3 |
+
import gradio as gr
|
| 4 |
+
|
| 5 |
+
from tensorflow import keras
|
| 6 |
+
|
| 7 |
+
keras.mixed_precision.set_global_policy("mixed_float16")
|
| 8 |
+
|
| 9 |
+
# prepare model
|
| 10 |
+
|
| 11 |
+
sd_dreambooth_model = models.StableDiffusion(
|
| 12 |
+
img_width=512, img_height=512
|
| 13 |
+
)
|
| 14 |
+
db_diffusion_model = from_pretrained_keras("Jayabalambika/my_repo")
|
| 15 |
+
sd_dreambooth_model._diffusion_model = db_diffusion_model
|
| 16 |
+
|
| 17 |
+
# generate images
|
| 18 |
+
def infer(prompt):
|
| 19 |
+
generated_images = sd_dreambooth_model.text_to_image(
|
| 20 |
+
prompt, batch_size=2
|
| 21 |
+
)
|
| 22 |
+
return generated_images
|
| 23 |
+
|
| 24 |
+
output = gr.Gallery(label="Outputs").style(grid=(1,2))
|
| 25 |
+
|
| 26 |
+
# customize interface
|
| 27 |
+
title = "Dreambooth Demo on Dog Images"
|
| 28 |
+
description = "This is a dreambooth model fine-tuned on mobile phone images. To try it, input the concept with {mobile phones}."
|
| 29 |
+
examples=[["a photo of mobile phone in outer space"]]
|
| 30 |
+
gr.Interface(infer, inputs=["text"], outputs=[output], title=title, description=description, examples=examples).queue().launch()
|