Update app.py
Browse files
app.py
CHANGED
@@ -6,20 +6,24 @@ from diffusers import FluxPipeline
|
|
6 |
from huggingface_hub.utils import RepositoryNotFoundError
|
7 |
|
8 |
pipeline = FluxPipeline.from_pretrained("black-forest-labs/FLUX.1-dev", torch_dtype=torch.float16).to("cuda")
|
|
|
9 |
|
10 |
@spaces.GPU(duration=70)
|
11 |
-
def generate(prompt, negative_prompt, width, height, sample_steps, lora_id):
|
12 |
try:
|
13 |
-
pipeline.load_lora_weights(lora_id)
|
|
|
|
|
14 |
except RepositoryNotFoundError:
|
15 |
raise ValueError(f"Recieved invalid FLUX LoRA.")
|
16 |
|
17 |
-
return pipeline(prompt=f"{prompt}\nDO NOT INCLUDE {negative_prompt}", width=width, height=height, num_inference_steps=sample_steps, generator=torch.Generator("cpu").manual_seed(42), guidance_scale=7).images[0]
|
18 |
|
19 |
with gr.Blocks() as interface:
|
20 |
with gr.Column():
|
21 |
with gr.Row():
|
22 |
with gr.Column():
|
|
|
23 |
prompt = gr.Textbox(label="Prompt", info="What do you want?", value="Keanu Reeves holding a neon sign reading 'Hello, world!', 32k HDR, paparazzi", lines=4, interactive=True)
|
24 |
negative_prompt = gr.Textbox(label="Negative Prompt", info="What do you want to exclude from the image?", value="ugly, low quality", lines=4, interactive=True)
|
25 |
with gr.Column():
|
@@ -35,7 +39,7 @@ with gr.Blocks() as interface:
|
|
35 |
sampling_steps = gr.Slider(label="Sampling Steps", info="The number of denoising steps.", value=20, minimum=4, maximum=50, step=1, interactive=True)
|
36 |
lora_id = gr.Textbox(label="Adapter Repository", info="ID of the FLUX LoRA", value="pepper13/fluxfw")
|
37 |
|
38 |
-
generate_button.click(fn=generate, inputs=[prompt, negative_prompt, width, height, sampling_steps, lora_id], outputs=[output])
|
39 |
|
40 |
if __name__ == "__main__":
|
41 |
interface.launch()
|
|
|
6 |
from huggingface_hub.utils import RepositoryNotFoundError
|
7 |
|
8 |
pipeline = FluxPipeline.from_pretrained("black-forest-labs/FLUX.1-dev", torch_dtype=torch.float16).to("cuda")
|
9 |
+
pipelineImg = FluxImg2ImgPipeline.from_pretrained("black-forest-labs/FLUX.1-dev", torch_dtype=torch.float16).to("cuda")
|
10 |
|
11 |
@spaces.GPU(duration=70)
|
12 |
+
def generate(image, prompt, negative_prompt, width, height, sample_steps, lora_id):
|
13 |
try:
|
14 |
+
# pipeline.load_lora_weights(lora_id)
|
15 |
+
init_image = load_image(image).resize((1024, 1024))
|
16 |
+
pipelineImg.load_lora_weights(lora_id)
|
17 |
except RepositoryNotFoundError:
|
18 |
raise ValueError(f"Recieved invalid FLUX LoRA.")
|
19 |
|
20 |
+
return pipeline(prompt=f"{prompt}\nDO NOT INCLUDE {negative_prompt}", image=init_image, width=width, height=height, num_inference_steps=sample_steps, generator=torch.Generator("cpu").manual_seed(42), guidance_scale=7).images[0]
|
21 |
|
22 |
with gr.Blocks() as interface:
|
23 |
with gr.Column():
|
24 |
with gr.Row():
|
25 |
with gr.Column():
|
26 |
+
image = gr.Image(label="Input image", show_label=False, type="filepath")
|
27 |
prompt = gr.Textbox(label="Prompt", info="What do you want?", value="Keanu Reeves holding a neon sign reading 'Hello, world!', 32k HDR, paparazzi", lines=4, interactive=True)
|
28 |
negative_prompt = gr.Textbox(label="Negative Prompt", info="What do you want to exclude from the image?", value="ugly, low quality", lines=4, interactive=True)
|
29 |
with gr.Column():
|
|
|
39 |
sampling_steps = gr.Slider(label="Sampling Steps", info="The number of denoising steps.", value=20, minimum=4, maximum=50, step=1, interactive=True)
|
40 |
lora_id = gr.Textbox(label="Adapter Repository", info="ID of the FLUX LoRA", value="pepper13/fluxfw")
|
41 |
|
42 |
+
generate_button.click(fn=generate, inputs=[image, prompt, negative_prompt, width, height, sampling_steps, lora_id], outputs=[output])
|
43 |
|
44 |
if __name__ == "__main__":
|
45 |
interface.launch()
|