laloadrianmorales commited on
Commit
89cd2fd
1 Parent(s): 87aac4e

update space

Browse files
Files changed (1) hide show
  1. app.py +61 -1
app.py CHANGED
@@ -1,3 +1,63 @@
1
  import gradio as gr
 
 
 
2
 
3
- gr.load("models/black-forest-labs/FLUX.1-dev").launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
+ from PIL import Image
3
+ import torch
4
+ from diffusers import StableDiffusionPipeline
5
 
6
+ # Load the model
7
+ model_id = "models/black-forest-labs/FLUX.1-dev"
8
+ pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
9
+ pipe = pipe.to("cuda")
10
+
11
+ def generate_image(prompt, negative_prompt, num_inference_steps, guidance_scale, width, height):
12
+ image = pipe(
13
+ prompt=prompt,
14
+ negative_prompt=negative_prompt,
15
+ num_inference_steps=num_inference_steps,
16
+ guidance_scale=guidance_scale,
17
+ width=width,
18
+ height=height
19
+ ).images[0]
20
+ return image
21
+
22
+ def edit_image(image, brightness, contrast, saturation):
23
+ edited = Image.fromarray(image)
24
+ edited = edited.convert('RGB')
25
+ edited = edited.point(lambda p: p * brightness)
26
+ edited = edited.point(lambda p: 128 + (p - 128) * contrast)
27
+ edited = edited.convert('HSV')
28
+ h, s, v = edited.split()
29
+ s = s.point(lambda p: p * saturation)
30
+ edited = Image.merge('HSV', (h, s, v)).convert('RGB')
31
+ return edited
32
+
33
+ with gr.Blocks(css="style.css") as demo:
34
+ gr.Markdown("# FLUX.1 Image Generator")
35
+
36
+ with gr.Tab("Generate"):
37
+ with gr.Row():
38
+ with gr.Column():
39
+ prompt = gr.Textbox(label="Prompt")
40
+ negative_prompt = gr.Textbox(label="Negative Prompt")
41
+ steps = gr.Slider(minimum=1, maximum=100, value=50, step=1, label="Inference Steps")
42
+ guidance = gr.Slider(minimum=1, maximum=20, value=7.5, step=0.1, label="Guidance Scale")
43
+ width = gr.Slider(minimum=256, maximum=1024, value=512, step=64, label="Width")
44
+ height = gr.Slider(minimum=256, maximum=1024, value=512, step=64, label="Height")
45
+ generate_btn = gr.Button("Generate")
46
+ with gr.Column():
47
+ output = gr.Image(label="Generated Image")
48
+
49
+ with gr.Tab("Edit"):
50
+ with gr.Row():
51
+ with gr.Column():
52
+ input_image = gr.Image(label="Input Image")
53
+ brightness = gr.Slider(minimum=0.5, maximum=1.5, value=1.0, step=0.1, label="Brightness")
54
+ contrast = gr.Slider(minimum=0.5, maximum=1.5, value=1.0, step=0.1, label="Contrast")
55
+ saturation = gr.Slider(minimum=0.5, maximum=1.5, value=1.0, step=0.1, label="Saturation")
56
+ edit_btn = gr.Button("Apply Edits")
57
+ with gr.Column():
58
+ edited_output = gr.Image(label="Edited Image")
59
+
60
+ generate_btn.click(generate_image, inputs=[prompt, negative_prompt, steps, guidance, width, height], outputs=output)
61
+ edit_btn.click(edit_image, inputs=[input_image, brightness, contrast, saturation], outputs=edited_output)
62
+
63
+ demo.launch()