Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -3,12 +3,14 @@ import numpy as np
|
|
3 |
import random
|
4 |
import spaces
|
5 |
import torch
|
6 |
-
|
|
|
7 |
|
8 |
dtype = torch.bfloat16
|
9 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
10 |
|
11 |
-
|
|
|
12 |
|
13 |
MAX_SEED = np.iinfo(np.int32).max
|
14 |
MAX_IMAGE_SIZE = 2048
|
@@ -18,14 +20,19 @@ def infer(prompt, seed=42, randomize_seed=False, width=1024, height=1024, num_in
|
|
18 |
if randomize_seed:
|
19 |
seed = random.randint(0, MAX_SEED)
|
20 |
generator = torch.Generator().manual_seed(seed)
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
|
|
|
|
|
|
|
|
|
|
29 |
return image, seed
|
30 |
|
31 |
examples = [
|
@@ -33,14 +40,12 @@ examples = [
|
|
33 |
"a cat holding a sign that says hello world",
|
34 |
"an anime illustration of a wiener schnitzel",
|
35 |
]
|
36 |
-
|
37 |
css="""
|
38 |
#col-container {
|
39 |
margin: 0 auto;
|
40 |
max-width: 520px;
|
41 |
}
|
42 |
"""
|
43 |
-
|
44 |
with gr.Blocks(css=css) as demo:
|
45 |
|
46 |
with gr.Column(elem_id="col-container"):
|
@@ -111,12 +116,10 @@ with gr.Blocks(css=css) as demo:
|
|
111 |
outputs = [result, seed],
|
112 |
cache_examples="lazy"
|
113 |
)
|
114 |
-
|
115 |
gr.on(
|
116 |
triggers=[run_button.click, prompt.submit],
|
117 |
fn = infer,
|
118 |
inputs = [prompt, seed, randomize_seed, width, height, num_inference_steps],
|
119 |
outputs = [result, seed]
|
120 |
)
|
121 |
-
|
122 |
demo.launch()
|
|
|
3 |
import random
|
4 |
import spaces
|
5 |
import torch
|
6 |
+
# Substituindo a importação da DiffusionPipeline
|
7 |
+
from custom_pipeline import FLUXPipelineWithIntermediateOutputs
|
8 |
|
9 |
dtype = torch.bfloat16
|
10 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
11 |
|
12 |
+
# Instanciando a FLUXPipelineWithIntermediateOutputs
|
13 |
+
pipe = FLUXPipelineWithIntermediateOutputs.from_pretrained("black-forest-labs/FLUX.1-schnell", torch_dtype=dtype).to(device)
|
14 |
|
15 |
MAX_SEED = np.iinfo(np.int32).max
|
16 |
MAX_IMAGE_SIZE = 2048
|
|
|
20 |
if randomize_seed:
|
21 |
seed = random.randint(0, MAX_SEED)
|
22 |
generator = torch.Generator().manual_seed(seed)
|
23 |
+
|
24 |
+
# Ajustando a chamada da função de inferência
|
25 |
+
for img in pipe.generate_images(
|
26 |
+
prompt=prompt,
|
27 |
+
width=width,
|
28 |
+
height=height,
|
29 |
+
num_inference_steps=num_inference_steps,
|
30 |
+
generator=generator,
|
31 |
+
guidance_scale=0.0,
|
32 |
+
output_type="pil" # Certifique-se que sua pipeline retorna imagens PIL
|
33 |
+
):
|
34 |
+
image = img # Pegando a primeira imagem do iterador
|
35 |
+
|
36 |
return image, seed
|
37 |
|
38 |
examples = [
|
|
|
40 |
"a cat holding a sign that says hello world",
|
41 |
"an anime illustration of a wiener schnitzel",
|
42 |
]
|
|
|
43 |
css="""
|
44 |
#col-container {
|
45 |
margin: 0 auto;
|
46 |
max-width: 520px;
|
47 |
}
|
48 |
"""
|
|
|
49 |
with gr.Blocks(css=css) as demo:
|
50 |
|
51 |
with gr.Column(elem_id="col-container"):
|
|
|
116 |
outputs = [result, seed],
|
117 |
cache_examples="lazy"
|
118 |
)
|
|
|
119 |
gr.on(
|
120 |
triggers=[run_button.click, prompt.submit],
|
121 |
fn = infer,
|
122 |
inputs = [prompt, seed, randomize_seed, width, height, num_inference_steps],
|
123 |
outputs = [result, seed]
|
124 |
)
|
|
|
125 |
demo.launch()
|