wifix199 commited on
Commit
7467e8a
·
verified ·
1 Parent(s): 576381a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -13
app.py CHANGED
@@ -1,22 +1,31 @@
1
  import gradio as gr
2
- from transformers import Flux1
 
3
 
4
  # Load the model
5
- model = Flux1.from_pretrained("black-forest-labs/flux-1-dev")
 
6
 
7
  def generate_image(prompt):
8
- # Generate an image using the model
9
- image = model(prompt)
 
 
 
 
 
 
 
10
  return image
11
 
12
- # Create the Gradio Interface
13
- demo = gr.Interface(
14
- fn=generate_image,
15
- inputs=gr.Textbox(label="Prompt"),
16
- outputs=gr.Image(label="Generated Image"),
17
- title="FLUX.1-dev Image Generation Bot",
18
- description="Enter a prompt and generate an image using the FLUX.1-dev model."
19
  )
20
 
21
- # Launch the Gradio Interface
22
- demo.launch()
 
1
  import gradio as gr
2
+ import torch
3
+ from diffusers import FluxPipeline
4
 
5
  # Load the model
6
+ pipe = FluxPipeline.from_pretrained("black-forest-labs/FLUX.1-dev", torch_dtype=torch.bfloat16)
7
+ pipe.enable_model_cpu_offload() #save some VRAM by offloading the model to CPU. Remove this if you have enough GPU power
8
 
9
  def generate_image(prompt):
10
+ image = pipe(
11
+ prompt,
12
+ height=1024,
13
+ width=1024,
14
+ guidance_scale=3.5,
15
+ num_inference_steps=50,
16
+ max_sequence_length=512,
17
+ generator=torch.Generator("cpu").manual_seed(0)
18
+ ).images[0]
19
  return image
20
 
21
+ # Create the UI
22
+ ui = gr.Interface(
23
+ generate_image,
24
+ gr.Textbox(lines=2, placeholder="Enter your prompt here..."),
25
+ "image",
26
+ title="FLUX.1-dev Image Generator",
27
+ description="Generate images using the FLUX.1-dev model.",
28
  )
29
 
30
+ # Launch the UI
31
+ ui.launch()