Jofthomas HF staff commited on
Commit
2e463bb
1 Parent(s): 457648b

Create diffusion.py

Browse files
Files changed (1) hide show
  1. TextGen/diffusion.py +15 -0
TextGen/diffusion.py ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from diffusers import StableDiffusion3Pipeline
3
+
4
+ pipe = StableDiffusion3Pipeline.from_pretrained("stabilityai/stable-diffusion-3-medium-diffusers",token=os.environ["HF_TOKEN"], torch_dtype=torch.float16)
5
+ pipe = pipe.to("cuda")
6
+
7
+
8
+ def generate_image(prompt):
9
+ image = pipe(
10
+ prompt,
11
+ negative_prompt="",
12
+ num_inference_steps=28,
13
+ guidance_scale=7.0,
14
+ ).images[0]
15
+ return image