| |
| |
|
|
| |
| import os |
| import requests |
| from stable_diffusion_cpp import StableDiffusion |
|
|
| |
| def download_file(url, save_path): |
| print(f"Starting download for: {save_path}") |
| response = requests.get(url, stream=True) |
| response.raise_for_status() |
| |
| |
| total_size = int(response.headers.get('content-length', 0)) |
| downloaded_size = 0 |
|
|
| with open(save_path, 'wb') as f: |
| for data in response.iter_content(chunk_size=8192): |
| f.write(data) |
| downloaded_size += len(data) |
| |
| print(f"Downloading {save_path}: {downloaded_size}/{total_size} bytes downloaded", end='\r') |
|
|
| print(f"\nDownloaded {save_path} successfully.") |
|
|
| |
| vae_url = "https://huggingface.co/pranavajay/flowgram/resolve/main/vae/diffusion_pytorch_model.safetensors" |
| model_url = "https://huggingface.co/pranavajay/flowgram/resolve/main/flowgram.safetensors" |
| clip_url = "https://huggingface.co/pranavajay/flowgram/resolve/main/text_encoder/clip_l.safetensors" |
| t5xxl_url = "https://huggingface.co/pranavajay/flowgram/resolve/main/text_encoder/t5xxl_fp16.safetensors" |
|
|
| |
| vae_path = "vae/diffusion_pytorch_model.safetensors" |
| model_path = "flowgram.safetensors" |
| clip_path = "text_encoder/clip_l.safetensors" |
| t5xxl_path = "text_encoder/t5xxl_fp16.safetensors" |
|
|
| |
| os.makedirs("vae", exist_ok=True) |
| os.makedirs("text_encoder", exist_ok=True) |
|
|
| |
| if not os.path.exists(vae_path): |
| download_file(vae_url, vae_path) |
| if not os.path.exists(model_path): |
| download_file(model_url, model_path) |
| if not os.path.exists(clip_path): |
| download_file(clip_url, clip_path) |
| if not os.path.exists(t5xxl_path): |
| download_file(t5xxl_url, t5xxl_path) |
|
|
| |
| flowgram_diffusion = StableDiffusion( |
| diffusion_model_path=model_path, |
| clip_l_path=clip_path, |
| t5xxl_path=t5xxl_path, |
| vae_path=vae_path, |
| ) |
|
|
| |
| def generate_image(prompt, num_images=1, guidance_scale=7.5): |
| |
| images = flowgram_diffusion.generate(prompt, num_images=num_images, guidance_scale=guidance_scale) |
| |
| |
| return images |
|
|
| |
| if __name__ == "__main__": |
| prompt = "A beautiful landscape with mountains and a river" |
| generated_images = generate_image(prompt) |
| |
| |
| for i, img in enumerate(generated_images): |
| img.save(f"generated_image_{i}.png") |
| print(f"Saved generated_image_{i}.png") |