Spaces:
Sleeping
Sleeping
File size: 5,682 Bytes
8347836 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
import gradio as gr
import torch
from transformers import pipeline
from diffusers import StableDiffusionXLPipeline
import spaces
default_model = "lucianosb/acaraje-brazil-xl"
default_prompt = "delicious acarajé"
@spaces.GPU
pipeline = StableDiffusionXLPipeline.from_single_file(
"https://huggingface.co/lucianosb/sinteticoXL-models/blob/main/sinteticoXL_v1dot2.safetensors",
torch_dtype=torch.float16,
variant="fp16",
use_safetensors=True,
).to("cuda")
def make_description(model):
pipeline.unload_lora_weights()
model_keywords = {
"lucianosb/acaraje-brazil-xl": ["acarajé", "acaraje"],
"lucianosb/boto-brazil-xl": ["boto"],
"lucianosb/cathedral-of-brasilia-brazil-xl": ["cathedral of brasilia", "cathedral", "house/building"],
"lucianosb/jkbridge-brazil-xl": ["jkbridge"],
"lucianosb/mamulengo-brazil-xl": ["mamulengo puppet"],
"lucianosb/marajoara-brazil-xl": ["marajoara patterns", "marajo patterns", "marajo"],
"lucianosb/masp-brazil-xl": ["masp", "sampa", "sao_paulo", "masp building"],
"lucianosb/ofobridge-brazil-xl": ["ofobridge", "bridge", "ponte_estaiada_sp", "ponte"],
"lucianosb/tacaca-brazil-xl": ["tacacá"],
"lucianosb/timbalada-brazil-xl": ["timbalada body painting", "body painting"],
"lucianosb/veropeso-brazil-xl": ["veropeso", "veropa"]
}
keywords = model_keywords.get(model, ["unknown model"])
return "Triggered with the following keywords: \n\n" + "- " + "\n- ".join(keywords)
def make_prompt(model):
prompts = {
"lucianosb/acaraje-brazil-xl": "delicious acarajé",
"lucianosb/boto-brazil-xl": "beautiful boto in a river",
"lucianosb/cathedral-of-brasilia-brazil-xl": "stunning cathedral of brasilia",
"lucianosb/jkbridge-brazil-xl": "charming jkbridge",
"lucianosb/mamulengo-brazil-xl": "enchanting mamulengo puppet in the clouds",
"lucianosb/marajoara-brazil-xl": "a vase in marajoara patterns",
"lucianosb/masp-brazil-xl": "elegant masp building, by sunrise in sao_paulo",
"lucianosb/ofobridge-brazil-xl": "fascinating ofobridge",
"lucianosb/tacaca-brazil-xl": "delicious tacaca, 4k masterpiece",
"lucianosb/timbalada-brazil-xl": "beautiful timbalada body painting",
"lucianosb/veropeso-brazil-xl": "dreamy veropeso landscape"
}
prompt = prompts.get(model, "")
return prompt
@spaces.GPU
def make_image(model, prompt):
weight_file_names = {
"lucianosb/acaraje-brazil-xl": "Acarajé_-_Brazil_XL.safetensors",
"lucianosb/boto-brazil-xl": "Boto_-_Brazil_XL.safetensors",
"lucianosb/cathedral-of-brasilia-brazil-xl": "Cathedral_of_Brasilia_-_Brazil_XL.safetensors",
"lucianosb/jkbridge-brazil-xl": "JK_Bridge_-_Brazil_XL.safetensors",
"lucianosb/mamulengo-brazil-xl": "Mamulengo_-_Brazil_XL.safetensors",
"lucianosb/marajoara-brazil-xl": "Marajoara-_Brazil_XL.safetensors",
"lucianosb/masp-brazil-xl": "MASP_-_Brazil_XL.safetensors",
"lucianosb/ofobridge-brazil-xl": "OFO_Bridge_-_Brazil_XL.safetensors",
"lucianosb/tacaca-brazil-xl": "Tacacá_-_Brazil_XL.safetensors",
"lucianosb/timbalada-brazil-xl": "Timbalada_-_Brazil_XL.safetensors",
"lucianosb/veropeso-brazil-xl": "VeroPeso_-_Brazil_XL.safetensors"
}
weight_file_name = weight_file_names.get(model, None)
if weight_file_name is None:
raise ValueError(f"Invalid model: {model}")
pipeline.load_lora_weights(model, weight_name=weight_file_name)
prompt = prompt
image = pipeline(prompt, guidance_scale=6.0, num_inference_steps=20).images[0]
return image
with gr.Blocks(title="Brazil XL") as demo:
gr.Markdown("# Brazil XL Demo")
gr.Markdown('''
Brazil XL is an iniative that brings better representations of Brazilian culture to Stable Diffusion. This demo uses Stable Diffusion models from the [SinteticoXL](https://huggingface.co/lucianosb/sinteticoXL-models) family.
## How to use
1. Choose a model
2. Describe your input
3. Click "Generate!"
4. See the result
''')
with gr.Row():
with gr.Column():
model_dropdown = gr.Dropdown(
label="Choose a model",
choices=[
"lucianosb/acaraje-brazil-xl",
"lucianosb/boto-brazil-xl",
"lucianosb/cathedral-of-brasilia-brazil-xl",
"lucianosb/jkbridge-brazil-xl",
"lucianosb/mamulengo-brazil-xl",
"lucianosb/marajoara-brazil-xl",
"lucianosb/masp-brazil-xl",
"lucianosb/ofobridge-brazil-xl",
"lucianosb/tacaca-brazil-xl",
"lucianosb/timbalada-brazil-xl",
"lucianosb/veropeso-brazil-xl"
],
value=default_model
)
description = gr.Markdown("Describe your input for " + default_model)
prompt = gr.Textbox(
label="Prompt",
info="use the proper keyword",
lines=3,
value=default_prompt,
)
btn = gr.Button("Generate!")
with gr.Column():
output = gr.Image()
model_dropdown.change(fn=make_description, inputs=model_dropdown, outputs=description)
model_dropdown.change(fn=make_prompt, inputs=model_dropdown, outputs=prompt)
btn.click(fn=make_image, inputs=[model_dropdown, prompt], outputs=output)
demo.launch() |