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