arshadrana commited on
Commit
e6dd921
·
verified ·
1 Parent(s): 2c2ed8c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -32
app.py CHANGED
@@ -1,38 +1,32 @@
1
  import torch
2
- import gradio as gr
3
  from diffusers import StableDiffusion3Pipeline
 
4
 
5
- def image_generator(prompt):
6
- device = "cuda" if torch.cuda.is_available() else "cpu"
7
- pipeline = StableDiffusion3Pipeline.from_pretrained("stabilityai/stable-diffusion-3-medium-diffusers",
8
- torch_dtype=torch.float16 if device == "cuda" else torch.float32,
9
- text_encoder_3=None,
10
- tokenizer_3 = None)
11
- #pipeline.enable_model_cpu_offload()
12
- pipeline.to(device)
13
-
14
- image = pipeline(
15
- prompt=prompt,
16
- negative_prompt="blurred, ugly, watermark, low, resolution, blurry",
17
- num_inference_steps=40,
18
- height=1024,
19
- width=1024,
20
- guidance_scale=9.0
21
  ).images[0]
22
-
23
- #image.show()
24
  return image
25
 
26
- #image_generator("A magical cat doing spell")
27
-
28
- interface = gr.Interface(
29
- fn=image_generator,
30
- inputs=gr.Textbox(lines=2, placeholder = "Enter your prompt..."),
31
- outputs=gr.Image(type = "pil"),
32
- title = "Image Generator App",
33
- description = "This is a simple image generator app using HuggingFace's Stable Diffusion 3 model.")
34
-
35
- interface.launch()
36
-
37
-
38
- print(interface)
 
1
  import torch
 
2
  from diffusers import StableDiffusion3Pipeline
3
+ import gradio as gr
4
 
5
+ # Load the Stable Diffusion pipeline
6
+ pipe = StableDiffusion3Pipeline.from_pretrained(
7
+ "stabilityai/stable-diffusion-3-medium-diffusers",
8
+ torch_dtype=torch.float16
9
+ )
10
+ pipe = pipe.to("cuda")
11
+
12
+ # Function to generate images
13
+ def generate_image(prompt):
14
+ image = pipe(
15
+ prompt,
16
+ negative_prompt="",
17
+ num_inference_steps=28,
18
+ guidance_scale=7.0,
 
 
19
  ).images[0]
 
 
20
  return image
21
 
22
+ # Create a Gradio interface
23
+ iface = gr.Interface(
24
+ fn=generate_image, # Function to call
25
+ inputs=gr.Textbox(label="Enter a prompt"), # Input component
26
+ outputs=gr.Image(label="Generated Image"), # Output component
27
+ title="Stable Diffusion 3 Image Generator",
28
+ description="Enter a prompt to generate an image using Stable Diffusion 3."
29
+ )
30
+
31
+ # Launch the Gradio app
32
+ iface.launch()