GenAILearniverse commited on
Commit
dcd3cf2
1 Parent(s): 2617c83

Upload image-genration-using-sd3.py

Browse files
Files changed (1) hide show
  1. image-genration-using-sd3.py +39 -0
image-genration-using-sd3.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import torch
3
+ from diffusers import StableDiffusion3Pipeline
4
+
5
+ def image_generation(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
+ return image
24
+
25
+ # image_generation("A magician cat doing spell")
26
+
27
+ interface= gr.Interface(
28
+ fn=image_generation,
29
+ inputs = gr.Textbox(lines=2, placeholder="Enter your Prompt..."),
30
+ outputs =gr.Image(type="pil"),
31
+ title ="@GenAiLearnivers Project 9: Image creation using Stable Diffusion 3 Model",
32
+ description="This application will be used to generate awesome images using SD3 model"
33
+ )
34
+
35
+ interface.launch()
36
+
37
+
38
+
39
+