Commit
•
1427b84
0
Parent(s):
Duplicate from FFusion/FFusionXL-SDXL-DEV
Browse files- .gitattributes +35 -0
- README.md +14 -0
- app.py +102 -0
- requirements.txt +12 -0
.gitattributes
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
28 |
+
*.tar filter=lfs diff=lfs merge=lfs -text
|
29 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
30 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
31 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
32 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
33 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
title: FFusionXL - SDXL - DEMO
|
3 |
+
emoji: 🐨
|
4 |
+
colorFrom: pink
|
5 |
+
colorTo: indigo
|
6 |
+
sdk: gradio
|
7 |
+
sdk_version: 3.35.2
|
8 |
+
app_file: app.py
|
9 |
+
pinned: true
|
10 |
+
license: other
|
11 |
+
duplicated_from: FFusion/FFusionXL-SDXL-DEV
|
12 |
+
---
|
13 |
+
|
14 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
@@ -0,0 +1,102 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import gradio.components as gc
|
3 |
+
import torch
|
4 |
+
import numpy as np
|
5 |
+
from diffusers import DiffusionPipeline
|
6 |
+
from huggingface_hub import login, HfApi, HfFolder
|
7 |
+
from PIL import Image
|
8 |
+
import os
|
9 |
+
from datetime import datetime
|
10 |
+
|
11 |
+
|
12 |
+
# Get your Hugging Face API token
|
13 |
+
folder = HfFolder()
|
14 |
+
token = folder.get_token()
|
15 |
+
|
16 |
+
# Instantiate the Hugging Face API
|
17 |
+
api = HfApi()
|
18 |
+
|
19 |
+
login(token=os.environ.get('HF_KEY'))
|
20 |
+
|
21 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
22 |
+
|
23 |
+
torch.cuda.max_memory_allocated(device=device)
|
24 |
+
|
25 |
+
pipe1 = DiffusionPipeline.from_pretrained("FFusion/FFusionXL-09-SDXL", torch_dtype=torch.float16, variant="fp16", use_safetensors=True)
|
26 |
+
pipe2 = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-refiner-0.9", torch_dtype=torch.float16, variant="fp16", use_safetensors=True)
|
27 |
+
|
28 |
+
pipe1 = pipe1.to(device)
|
29 |
+
pipe1.enable_xformers_memory_efficient_attention()
|
30 |
+
|
31 |
+
pipe2 = pipe2.to(device)
|
32 |
+
pipe2.enable_xformers_memory_efficient_attention()
|
33 |
+
|
34 |
+
def save_image_to_hf_space(image_np, image_name):
|
35 |
+
# Name of your Hugging Face repo
|
36 |
+
repo_name = "FFusion/FFusionXL-SDXL-DEMO"
|
37 |
+
|
38 |
+
# Convert the numpy array to an image
|
39 |
+
image = Image.fromarray(image_np.astype('uint8'))
|
40 |
+
|
41 |
+
# Append a timestamp to the filename
|
42 |
+
timestamp = datetime.now().strftime("%Y%m%d-%H%M%S")
|
43 |
+
image_name_with_timestamp = f"{image_name}-{timestamp}"
|
44 |
+
|
45 |
+
# Save the image locally
|
46 |
+
image_path = f"./{image_name_with_timestamp}.png"
|
47 |
+
image.save(image_path)
|
48 |
+
|
49 |
+
# Upload the image to your Hugging Face repo
|
50 |
+
api.upload_file(
|
51 |
+
token=token,
|
52 |
+
path_or_fileobj=image_path,
|
53 |
+
repo_id=repo_name,
|
54 |
+
filename=image_name_with_timestamp,
|
55 |
+
)
|
56 |
+
|
57 |
+
|
58 |
+
def genie (prompt, negative_prompt, scale, steps, seed):
|
59 |
+
torch.cuda.empty_cache()
|
60 |
+
generator = torch.Generator(device=device).manual_seed(seed)
|
61 |
+
int_images = pipe1(prompt, negative_prompt=negative_prompt, num_inference_steps=steps, guidance_scale=scale, num_images_per_prompt=1, generator=generator).images
|
62 |
+
torch.cuda.empty_cache()
|
63 |
+
refined_images = pipe2(prompt=prompt, image=int_images).images
|
64 |
+
int_image_np = np.array(int_images[0])
|
65 |
+
refined_image_np = np.array(refined_images[0])
|
66 |
+
|
67 |
+
# Save the generated images to Hugging Face Spaces
|
68 |
+
# save_image_to_hf_space(int_image_np, "int_image")
|
69 |
+
# save_image_to_hf_space(refined_image_np, "refined_image")
|
70 |
+
|
71 |
+
return int_image_np, refined_image_np
|
72 |
+
|
73 |
+
|
74 |
+
gr.Interface(fn=genie,
|
75 |
+
inputs=[gr.Textbox(label='Describe your FFusion idea. 77 Token Limit.'),
|
76 |
+
gr.Textbox(label='Things the AI should not create (negative prompt)'),
|
77 |
+
gr.Slider(1, 15, 10), gr.Slider(25, maximum=100, value=50, step=1),
|
78 |
+
gr.Slider(minimum=1, step=1, maximum=999999999999999999, randomize=True)],
|
79 |
+
outputs=[gc.Image(type='numpy', label="Generated Image"), gc.Image(type='numpy', label="Refined Image")],
|
80 |
+
title="FFusionXL - Generate and Refine",
|
81 |
+
description='<div style="display: flex; flex-wrap: wrap; gap: 2px;"><a href="https://huggingface.co/FFusion/FFusionXL-09-SDXL" target="_new" rel="ugc"><img src="https://img.shields.io/badge/FFusionXL--09--SDXL-Model-pink" alt="FFusionXL-09-SDXL"></a> <a href="https://huggingface.co/FFusion/FFusionXL-09-SDXL/blob/main/LICENSE.md" target="_new" rel="ugc"><img src="https://img.shields.io/badge/License-FFXL%20Research%20License-blue"></a></div>',
|
82 |
+
article = '**Citation** \
|
83 |
+
Please note that the demo is intended for academic and research purposes ONLY. Any use of the demo for generating inappropriate content is strictly prohibited. The responsibility for any misuse or inappropriate use of the demo lies solely with the users who generated such content, and this demo shall not be held liable for any such use. Original code: Manjushri. By interacting within this environment, you hereby acknowledge and agree to the terms of the SDXL 0.9 Research License. \
|
84 |
+
Attribution: SDXL 0.9 is licensed under the SDXL Research License, Copyright (c) Stability AI Ltd. All Rights Reserved. \
|
85 |
+
**License** \
|
86 |
+
[SDXL 0.9 Research License](https://huggingface.co/stabilityai/stable-diffusion-xl-base-0.9/blob/main/LICENSE.md) \
|
87 |
+
[FFXL 0.9 Research License](https://huggingface.co/FFusion/FFusionXL-09-SDXL/blob/main/LICENSE.md) \
|
88 |
+
<div style="display: flex; flex-wrap: wrap; gap: 2px;">\
|
89 |
+
<img src="https://img.shields.io/badge/%F0%9F%94%A5%20Refiner%20Compatible-Yes-success"> \
|
90 |
+
<img src="https://img.shields.io/badge/%F0%9F%92%BB%20CLIP--ViT%2FG%20and%20CLIP--ViT%2FL%20tested-Yes-success"> \
|
91 |
+
<img src="https://img.shields.io/badge/%F0%9F%A7%A8%20FFXL%20Diffusers-available-brightgreen"> \
|
92 |
+
</div>\
|
93 |
+
\
|
94 |
+
<div style="display: flex; flex-wrap: wrap; gap: 2px;">\
|
95 |
+
<a href="https://github.com/1e-2" target="_new" rel="ugc"><img src="https://img.shields.io/badge/GitHub-1e--2-green"></a> \
|
96 |
+
<a href="https://www.facebook.com/FFusionAI/" target="_new" rel="ugc"><img src="https://img.shields.io/badge/Facebook-FFusionAI-blue"></a> \
|
97 |
+
<a href="https://civitai.com/models/82039/ffusion-ai-sd-21" target="_new" rel="ugc"><img src="https://img.shields.io/badge/Civitai-FFusionAI-blue"></a> \
|
98 |
+
</div>\
|
99 |
+
\
|
100 |
+
![ffusionXL.jpg](https://cdn-uploads.huggingface.co/production/uploads/6380cf05f496d57325c12194/iM_2uykpHRQsZgLvIjJJl.jpeg) \
|
101 |
+
\
|
102 |
+
<a href="mailto:di@ffusion.ai"><img src="https://img.shields.io/badge/Email-di%40ffusion.ai-blue?style=for-the-badge&logo=gmail"></a>').launch(debug=True, max_threads=10)
|
requirements.txt
ADDED
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
diffusers>=0.18.2
|
2 |
+
transformers
|
3 |
+
accelerate
|
4 |
+
invisible-watermark>=0.2.0
|
5 |
+
torch==2.0.1
|
6 |
+
torchvision
|
7 |
+
torchaudio
|
8 |
+
safetensors
|
9 |
+
ftfy
|
10 |
+
modin[all]
|
11 |
+
xformers
|
12 |
+
pillow
|