kasper-boy commited on
Commit
8b228ab
1 Parent(s): 28d219b

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +31 -1
main.py CHANGED
@@ -1,3 +1,33 @@
1
  import gradio as gr
2
  import torch
3
- from duffusers import
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
  import torch
3
+ from duffusers import StableDiffusers3Pipeline
4
+
5
+ def image_generation(prompt):
6
+ device = "cuda" if torch.cuda.is_available() else "cpu"
7
+ pipeline = StableDiffusers3Pipeline.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.to(device)
12
+ pipeline.enable_model_cpu_offload()
13
+
14
+ image = pipeline(
15
+ prompt = prompt,
16
+ negative_prompt = "blurred, ugly, watermark, low resolution, blurry, nude",
17
+ num_inference_steps = 40,
18
+ height=1024,
19
+ width=1024,
20
+ guidance_scale=8.0
21
+ ).images[0]
22
+
23
+ image.show()
24
+
25
+ interface= gr.interface(
26
+ fn=image_generation,
27
+ inputs = gr.Textbox(lines="2", placeholder="Enter Your Prompt ..."),
28
+ outputs = gr.Image(type="pil"),
29
+ title = "AI Text Generation By SD-3M",
30
+ examples = "A magician cat doing spell"
31
+ )
32
+
33
+ interface.launch()