amos1088 commited on
Commit
91a655a
·
1 Parent(s): 3aadc38

test gradio

Browse files
Files changed (1) hide show
  1. app.py +22 -29
app.py CHANGED
@@ -13,7 +13,6 @@ login(token=token)
13
  model_path = 'stabilityai/stable-diffusion-3.5-large'
14
  ip_adapter_path = './ip-adapter.bin'
15
  image_encoder_path = "google/siglip-so400m-patch14-384"
16
- ref_img_path = './assets/1.jpg' # Reference image path
17
 
18
  # Load SD3.5 pipeline and components
19
  transformer = SD3Transformer2DModel.from_pretrained(
@@ -31,43 +30,37 @@ pipe.init_ipadapter(
31
 
32
 
33
  @gr.Interface()
34
- def gui_generation(prompt: str, negative_prompt: str, ipadapter_scale: float, num_imgs: int):
35
  """
36
- Generate images based on prompt, negative prompt, and IP-Adapter scale.
37
  """
38
- ref_img = Image.open(ref_img_path).convert('RGB') # Load reference image
39
  generator = torch.Generator("cuda").manual_seed(42) # Reproducibility
40
 
41
- images = []
42
- for _ in range(num_imgs):
43
- output = pipe(
44
- width=1024,
45
- height=1024,
46
- prompt=prompt,
47
- negative_prompt=negative_prompt,
48
- num_inference_steps=24,
49
- guidance_scale=5.0,
50
- generator=generator,
51
- clip_image=ref_img,
52
- ipadapter_scale=ipadapter_scale,
53
- ).images[0]
54
- images.append(output)
55
- return images
56
 
57
 
58
  # Gradio UI elements
59
- prompt_box = gr.Textbox(label="Prompt", placeholder="Enter your generation prompt here")
60
- negative_prompt_box = gr.Textbox(label="Negative Prompt", placeholder="e.g., lowres, worst quality")
61
- ipadapter_slider = gr.Slider(0.1, 1.0, value=0.5, step=0.1, label="IP-Adapter Scale")
62
- number_slider = gr.Slider(1, 5, value=1, step=1, label="Number of Images")
63
- gallery = gr.Gallery(label="Generated Images", columns=[3], rows=[1], object_fit="contain", height="auto")
64
 
65
  interface = gr.Interface(
66
  gui_generation,
67
- inputs=[prompt_box, negative_prompt_box, ipadapter_slider, number_slider],
68
- outputs=gallery,
69
- title="Stable Diffusion 3.5 Image Generation with IP-Adapter",
70
- description="Generate high-quality images with Stable Diffusion 3.5 Large and IP-Adapter guidance."
71
  )
72
 
73
- interface.launch()
 
13
  model_path = 'stabilityai/stable-diffusion-3.5-large'
14
  ip_adapter_path = './ip-adapter.bin'
15
  image_encoder_path = "google/siglip-so400m-patch14-384"
 
16
 
17
  # Load SD3.5 pipeline and components
18
  transformer = SD3Transformer2DModel.from_pretrained(
 
30
 
31
 
32
  @gr.Interface()
33
+ def gui_generation(image: Image, style_image: Image):
34
  """
35
+ Generate an image based on input and style images.
36
  """
 
37
  generator = torch.Generator("cuda").manual_seed(42) # Reproducibility
38
 
39
+ output = pipe(
40
+ width=1024,
41
+ height=1024,
42
+ prompt="",
43
+ negative_prompt="",
44
+ num_inference_steps=24,
45
+ guidance_scale=5.0,
46
+ generator=generator,
47
+ clip_image=style_image,
48
+ ipadapter_scale=0.5,
49
+ ).images[0]
50
+ return output
 
 
 
51
 
52
 
53
  # Gradio UI elements
54
+ image_input = gr.Image(type="pil", label="Input Image")
55
+ style_image_input = gr.Image(type="pil", label="Style Image")
56
+ output_image = gr.Image(label="Generated Image")
 
 
57
 
58
  interface = gr.Interface(
59
  gui_generation,
60
+ inputs=[image_input, style_image_input],
61
+ outputs=output_image,
62
+ title="Image Generation with Style Image",
63
+ description="Upload an input image and a style image to generate a new image based on the style."
64
  )
65
 
66
+ interface.launch()