Kvikontent commited on
Commit
56f24ed
·
1 Parent(s): 3e18ae4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -7
app.py CHANGED
@@ -1,4 +1,3 @@
1
-
2
  import gradio as gr
3
  from PIL import Image
4
  from diffusers import DiffusionPipeline
@@ -6,9 +5,9 @@ from diffusers import DiffusionPipeline
6
  # Load model and scheduler
7
  ldm = DiffusionPipeline.from_pretrained("CompVis/ldm-text2im-large-256")
8
 
9
- def generate_image(prompt, negative_prompt="Low quality", width=512, height=512):
10
  # Run pipeline in inference (sample random noise and denoise)
11
- images = ldm([prompt], num_inference_steps=50, eta=0.3, guidance_scale=6, negative_prompts=[negative_prompt]).images
12
  # Resize image to desired width and height
13
  resized_images = [image.resize((width, height)) for image in images]
14
  # Save images
@@ -19,13 +18,35 @@ def generate_image(prompt, negative_prompt="Low quality", width=512, height=512)
19
  # Define the interface
20
  iface = gr.Interface(
21
  fn=generate_image,
22
- inputs=["text", "text", "number", "number"],
 
 
 
 
 
 
 
 
23
  outputs="text",
24
  layout="vertical",
25
  title="Image Generation",
26
- description="Generate images based on prompts.",
27
- article="For more information, visit the documentation: [link](https://docs.gradio.app/)",
28
- examples=[["A painting of a squirrel eating a burger", "Low quality", 512, 512]]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
  )
30
 
31
  # Launch the interface
 
 
1
  import gradio as gr
2
  from PIL import Image
3
  from diffusers import DiffusionPipeline
 
5
  # Load model and scheduler
6
  ldm = DiffusionPipeline.from_pretrained("CompVis/ldm-text2im-large-256")
7
 
8
+ def generate_image(prompt, negative_prompt="Low quality", width=512, height=512, num_steps=50, eta=0.3, guidance_scale=6):
9
  # Run pipeline in inference (sample random noise and denoise)
10
+ images = ldm([prompt], num_inference_steps=num_steps, eta=eta, guidance_scale=guidance_scale, negative_prompts=[negative_prompt]).images
11
  # Resize image to desired width and height
12
  resized_images = [image.resize((width, height)) for image in images]
13
  # Save images
 
18
  # Define the interface
19
  iface = gr.Interface(
20
  fn=generate_image,
21
+ inputs=[
22
+ gr.inputs.Textbox(label="Prompt", lines=2),
23
+ gr.inputs.Textbox(label="Negative Prompt (optional)", lines=2),
24
+ gr.inputs.Number(label="Width (optional)", default=512),
25
+ gr.inputs.Number(label="Height (optional)", default=512),
26
+ gr.inputs.Number(label="Number of Inference Steps (optional)", default=50),
27
+ gr.inputs.Number(label="Eta (optional)", default=0.3),
28
+ gr.inputs.Number(label="Guidance Scale (optional)", default=6),
29
+ ],
30
  outputs="text",
31
  layout="vertical",
32
  title="Image Generation",
33
+ description="Generate images based on prompts. Adjust the optional parameters for customization. The generated images will be resized to the specified width and height.",
34
+ article="Check out the documentation for more information: [link](https://docs.gradio.app/)",
35
+ examples=[
36
+ ["A painting of a squirrel eating a burger", "Low quality", 512, 512, 50, 0.3, 6],
37
+ ["A breathtaking landscape with mountains", "Blurry", 800, 600, 30, 0.5, 8],
38
+ ["An abstract artwork with vibrant colors", "Dull", 1024, 768, 70, 0.2, 10],
39
+ ],
40
+ )
41
+
42
+ # Configure styling options
43
+ iface.configure(
44
+ label_font="Arial",
45
+ label_font_size=18,
46
+ border_width=2,
47
+ border_color="blue",
48
+ button_bg_color="lightblue",
49
+ button_text_color="black",
50
  )
51
 
52
  # Launch the interface