Spaces:
Runtime error
Runtime error
Added app.py and requirements.txt
Browse files- app.py +36 -0
- requirements.txt +4 -0
app.py
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from huggingface_hub import from_pretrained_keras
|
| 2 |
+
from keras_cv import models
|
| 3 |
+
import gradio as gr
|
| 4 |
+
|
| 5 |
+
dreambooth_model = models.StableDiffusion(img_width=512, img_height=512)
|
| 6 |
+
|
| 7 |
+
diffusion_model = from_pretrained_keras("moizsajid/dreambooth-markhor")
|
| 8 |
+
dreambooth_model._diffusion_model = diffusion_model
|
| 9 |
+
|
| 10 |
+
# generate images
|
| 11 |
+
def infer(prompt: str, negative_prompt: str, num_imgs_to_gen: int, num_steps: int, guidance_scale: float):
|
| 12 |
+
generated_images = dreambooth_model.text_to_image(
|
| 13 |
+
prompt,
|
| 14 |
+
negative_prompt=negative_prompt,
|
| 15 |
+
batch_size=num_imgs_to_gen,
|
| 16 |
+
num_steps=num_steps,
|
| 17 |
+
unconditional_guidance_scale=guidance_scale
|
| 18 |
+
)
|
| 19 |
+
return generated_images
|
| 20 |
+
|
| 21 |
+
# pass function, input type for prompt, the output for multiple images
|
| 22 |
+
gr.Interface(
|
| 23 |
+
infer, [
|
| 24 |
+
gr.Textbox(label="Positive Prompt", value="a teddy_holmes dog astronaut in space"),
|
| 25 |
+
gr.Textbox(label="Negative Prompt", value="bad anatomy, blurry"),
|
| 26 |
+
gr.Slider(label='Number of gen image', minimum=1, maximum=4, value=2, step=1),
|
| 27 |
+
gr.Slider(label="Inference Steps",value=100),
|
| 28 |
+
gr.Number(label='Guidance scale', value=10),
|
| 29 |
+
], [
|
| 30 |
+
gr.Gallery(show_label=False),
|
| 31 |
+
],
|
| 32 |
+
title="Dreambooth Markhor Demo",
|
| 33 |
+
description = "This model is fine-tuned on images of Markhor from the internet (iStock). To use the demo, please add {markhor} to the input string.",
|
| 34 |
+
examples = [["a picture of markhor upside down", "", 4, 100, 10]],
|
| 35 |
+
).launch()
|
| 36 |
+
|
requirements.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
tensorflow
|
| 2 |
+
huggingface-hub
|
| 3 |
+
keras-cv
|
| 4 |
+
pycocotools
|