MoeZilla commited on
Commit
fd31ba2
·
verified ·
1 Parent(s): 33a28fa

Create run.py

Browse files
Files changed (1) hide show
  1. run.py +54 -0
run.py ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import wget
3
+ from stable_diffusion_cpp import StableDiffusion
4
+
5
+ # Define model paths
6
+ vae_url = "https://huggingface.co/pranavajay/flowgram/resolve/main/vae/diffusion_pytorch_model.safetensors"
7
+ model_url = "https://huggingface.co/pranavajay/flowgram/resolve/main/flowgram.safetensors"
8
+ clip_url = "https://huggingface.co/pranavajay/flowgram/resolve/main/text_encoder/clip_l.safetensors"
9
+ t5xxl_url = "https://huggingface.co/pranavajay/flowgram/resolve/main/text_encoder/t5xxl_fp16.safetensors"
10
+
11
+ # Define local save paths
12
+ vae_path = "vae/diffusion_pytorch_model.safetensors"
13
+ model_path = "flowgram.safetensors"
14
+ clip_path = "text_encoder/clip_l.safetensors"
15
+ t5xxl_path = "text_encoder/t5xxl_fp16.safetensors"
16
+
17
+ # Create directories if they don't exist
18
+ os.makedirs("vae", exist_ok=True)
19
+ os.makedirs("text_encoder", exist_ok=True)
20
+
21
+ # Download the models if they do not exist
22
+ if not os.path.exists(vae_path):
23
+ wget.download(vae_url, vae_path)
24
+ if not os.path.exists(model_path):
25
+ wget.download(model_url, model_path)
26
+ if not os.path.exists(clip_path):
27
+ wget.download(clip_url, clip_path)
28
+ if not os.path.exists(t5xxl_path):
29
+ wget.download(t5xxl_url, t5xxl_path)
30
+
31
+ # Initialize the StableDiffusion model
32
+ flowgram_diffusion = StableDiffusion(
33
+ diffusion_model_path=model_path,
34
+ clip_l_path=clip_path,
35
+ t5xxl_path=t5xxl_path,
36
+ vae_path=vae_path,
37
+ )
38
+
39
+ # Function to generate an image from text
40
+ def generate_image(prompt, num_images=1, guidance_scale=7.5):
41
+ # Generate images
42
+ images = flowgram_diffusion.generate(prompt, num_images=num_images, guidance_scale=guidance_scale)
43
+
44
+ # Return the generated images
45
+ return images
46
+
47
+ # Example usage
48
+ if __name__ == "__main__":
49
+ prompt = "A beautiful landscape with mountains and a river"
50
+ generated_images = generate_image(prompt)
51
+
52
+ # Save or display the images
53
+ for i, img in enumerate(generated_images):
54
+ img.save(f"generated_image_{i}.png") # Save each generated image