Nick088 commited on
Commit
827c867
1 Parent(s): c6484ad

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -4
app.py CHANGED
@@ -1,5 +1,5 @@
1
  import torch
2
- from diffusers import StableDiffusionPipeline
3
  import gradio as gr
4
  import os
5
  import spaces
@@ -14,19 +14,39 @@ else:
14
  print("Using CPU")
15
 
16
  # Initialize the pipeline and download the model
17
- pipe = StableDiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-3-medium", torch_dtype=torch.float16, use_auth_token=HF_TOKEN)
18
  pipe.to(device)
19
 
20
  # Define the image generation function
21
  @spaces.GPU(duration=60)
22
  def generate_image(prompt):
23
- image = pipe(prompt=prompt, num_inference_steps=1, guidance_scale=0.0).images[0]
 
 
 
 
 
 
 
24
  return image
25
 
26
  # Create the Gradio interface
 
 
 
 
 
 
 
 
 
 
 
 
 
27
  interface = gr.Interface(
28
  fn=generate_image,
29
- inputs=gr.Textbox(placeholder="Insert Prompt Here..."),
30
  outputs="image",
31
  title="Stable Diffusion 3 Medium",
32
  description="Made by [Nick088](https://linktr.ee/Nick088"
 
1
  import torch
2
+ from diffusers import StableDiffusion3Pipeline
3
  import gradio as gr
4
  import os
5
  import spaces
 
14
  print("Using CPU")
15
 
16
  # Initialize the pipeline and download the model
17
+ pipe = StableDiffusion3Pipeline.from_pretrained("stabilityai/stable-diffusion-3-medium", torch_dtype=torch.float16, use_auth_token=HF_TOKEN)
18
  pipe.to(device)
19
 
20
  # Define the image generation function
21
  @spaces.GPU(duration=60)
22
  def generate_image(prompt):
23
+ image = pipe(
24
+ prompt=prompt,
25
+ negative_prompt=negative_prompt,
26
+ num_inference_steps=num_inference_steps,
27
+ height=height,
28
+ width=width,
29
+ guidance_scale=guidance_scale,
30
+ ).images[0]
31
  return image
32
 
33
  # Create the Gradio interface
34
+
35
+ prompt = gr.Textbox(label="Prompt", info="Describe the image you want", placeholder="A cat...")
36
+
37
+ negative_prompt = gr.Textbox(label="Negative Prompt", info="Describe what you don't want in the image", placeholder="Ugly, bad anatomy...")
38
+
39
+ num_inference_steps = gr.Number(label="Number of Inference Steps", precision=0, value=25)
40
+
41
+ height = gr.Number(label="Number of Inference Steps", precision=0, value=1024)
42
+
43
+ width = gr.Number(label="Number of Inference Steps", precision=0, value=1024)
44
+
45
+ guidance_scale = gr.Number(minimum=0.1, value=7.5, label="Guidance Scale", info="The number of denoising steps of the image. More denoising steps usually lead to a higher quality image at the cost of slower inference")
46
+
47
  interface = gr.Interface(
48
  fn=generate_image,
49
+ inputs=[prompt, negative_prompt, num_inference_steps, height, width, guidance_scale]
50
  outputs="image",
51
  title="Stable Diffusion 3 Medium",
52
  description="Made by [Nick088](https://linktr.ee/Nick088"