Spaces:
Running
on
L40S
Running
on
L40S
Rishi Desai
commited on
Commit
·
a12f521
1
Parent(s):
15f2ccc
more work on readme; gif creator
Browse files- README.md +14 -20
- examples/create_comparison_gif.py +94 -0
- examples/elon_compare.gif +3 -0
- run.py +1 -2
README.md
CHANGED
@@ -1,21 +1,14 @@
|
|
1 |
# FaceEnhance
|
2 |
Enhancing faces in AI generated images.
|
3 |
|
4 |
-
<div style="
|
5 |
-
<
|
6 |
-
<h4>Before</h4>
|
7 |
-
<img src="examples/chatgpt_elon.png" alt="Elon Before" width="300"/>
|
8 |
-
</div>
|
9 |
-
<div>
|
10 |
-
<h4>After</h4>
|
11 |
-
<img src="examples/enhanced_elon.png" alt="Elon After" width="300"/>
|
12 |
-
</div>
|
13 |
</div>
|
14 |
|
15 |
## Installation
|
16 |
|
17 |
### Prerequisites
|
18 |
-
- Python 3.
|
19 |
- 1 GPU with 48GB VRAM
|
20 |
- At least 50GB of free disk space
|
21 |
|
@@ -23,12 +16,13 @@ Enhancing faces in AI generated images.
|
|
23 |
|
24 |
1. Set up your Hugging Face token:
|
25 |
- Create a token at [Hugging Face](https://huggingface.co/settings/tokens)
|
26 |
-
- Set the
|
27 |
```
|
28 |
export HUGGINGFACE_TOKEN=your_token_here
|
29 |
export HF_HOME=/path/to/your/huggingface_cache
|
30 |
```
|
31 |
- Models will be downloaded to `$HF_HOME` and then symlinked to `./ComfyUI/models/`
|
|
|
32 |
|
33 |
2. Create the virtual environment:
|
34 |
```
|
@@ -46,12 +40,18 @@ This will
|
|
46 |
- Install ComfyUI, custom nodes, and required dependencies to your venv
|
47 |
- Download all required models (Flux.1-dev, ControlNet, text encoders, PuLID, and more)
|
48 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
49 |
## Configuration
|
50 |
|
51 |
Create a .env file in the project root directory with your API keys:
|
52 |
```
|
53 |
touch .env
|
54 |
-
echo "OPENAI_API_KEY=your_openai_api_key_here" >> .env
|
55 |
echo "FAL_API_KEY=your_fal_api_key_here" >> .env
|
56 |
```
|
57 |
|
@@ -59,20 +59,14 @@ These API keys are required for certain features of the application to work prop
|
|
59 |
|
60 |
# Gradio Demo
|
61 |
|
62 |
-
A web interface for the face enhancement workflow.
|
63 |
|
64 |
1. Run
|
65 |
|
66 |
```bash
|
67 |
python gradio_demo.py
|
68 |
```
|
69 |
-
|
70 |
-
2. Run this on a separate terminal for port-forwarding
|
71 |
-
```bash
|
72 |
-
ssh -L 7860:localhost:7860 root@[IP_ADDRESS] -p [SERVER_PORT] -i [PRIVATE_KEY]
|
73 |
-
```
|
74 |
-
|
75 |
-
3. Go to http://localhost:7860
|
76 |
|
77 |
### Notes
|
78 |
- The script and demo run a ComfyUI server ephemerally
|
|
|
1 |
# FaceEnhance
|
2 |
Enhancing faces in AI generated images.
|
3 |
|
4 |
+
<div style="text-align: center;">
|
5 |
+
<img src="examples/elon_compare.gif" alt="Elon Comparison" width="600"/>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
</div>
|
7 |
|
8 |
## Installation
|
9 |
|
10 |
### Prerequisites
|
11 |
+
- Python 3.11 or higher
|
12 |
- 1 GPU with 48GB VRAM
|
13 |
- At least 50GB of free disk space
|
14 |
|
|
|
16 |
|
17 |
1. Set up your Hugging Face token:
|
18 |
- Create a token at [Hugging Face](https://huggingface.co/settings/tokens)
|
19 |
+
- Set the following environment variables:
|
20 |
```
|
21 |
export HUGGINGFACE_TOKEN=your_token_here
|
22 |
export HF_HOME=/path/to/your/huggingface_cache
|
23 |
```
|
24 |
- Models will be downloaded to `$HF_HOME` and then symlinked to `./ComfyUI/models/`
|
25 |
+
- Hugging Face requires login for downloading Flux
|
26 |
|
27 |
2. Create the virtual environment:
|
28 |
```
|
|
|
40 |
- Install ComfyUI, custom nodes, and required dependencies to your venv
|
41 |
- Download all required models (Flux.1-dev, ControlNet, text encoders, PuLID, and more)
|
42 |
|
43 |
+
## Running on ComfyUI
|
44 |
+
|
45 |
+
Using the ComfyUI workflows is the fastest way to get started. Run `python run_comfy.py`
|
46 |
+
- `./workflows/FaceEnhancementProd.json` for face enhancement
|
47 |
+
- `./workflows/FaceEmbedDist.json` for computing the face embed distance
|
48 |
+
|
49 |
+
|
50 |
## Configuration
|
51 |
|
52 |
Create a .env file in the project root directory with your API keys:
|
53 |
```
|
54 |
touch .env
|
|
|
55 |
echo "FAL_API_KEY=your_fal_api_key_here" >> .env
|
56 |
```
|
57 |
|
|
|
59 |
|
60 |
# Gradio Demo
|
61 |
|
62 |
+
A simple web interface for the face enhancement workflow.
|
63 |
|
64 |
1. Run
|
65 |
|
66 |
```bash
|
67 |
python gradio_demo.py
|
68 |
```
|
69 |
+
2. Go to http://localhost:7860. You may need to enable port forwarding.
|
|
|
|
|
|
|
|
|
|
|
|
|
70 |
|
71 |
### Notes
|
72 |
- The script and demo run a ComfyUI server ephemerally
|
examples/create_comparison_gif.py
ADDED
@@ -0,0 +1,94 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python
|
2 |
+
import argparse
|
3 |
+
from pathlib import Path
|
4 |
+
from PIL import Image
|
5 |
+
import numpy as np
|
6 |
+
|
7 |
+
def create_comparison_gif(before_img_path, after_img_path, output_path=None, duration=100, frames=20):
|
8 |
+
"""
|
9 |
+
Create a comparison GIF with a vertical bar revealing the 'after' image.
|
10 |
+
|
11 |
+
Args:
|
12 |
+
before_img_path (str): Path to the 'before' image
|
13 |
+
after_img_path (str): Path to the 'after' image
|
14 |
+
output_path (str, optional): Path for the output GIF. Defaults to 'comparison.gif'
|
15 |
+
duration (int, optional): Duration of each frame in ms. Defaults to 100.
|
16 |
+
frames (int, optional): Number of frames in the GIF. Defaults to 20.
|
17 |
+
|
18 |
+
Returns:
|
19 |
+
str: Path to the created GIF
|
20 |
+
"""
|
21 |
+
# Default output path
|
22 |
+
if output_path is None:
|
23 |
+
output_path = 'comparison.gif'
|
24 |
+
|
25 |
+
# Open images and ensure they have the same size
|
26 |
+
before_img = Image.open(before_img_path)
|
27 |
+
after_img = Image.open(after_img_path)
|
28 |
+
|
29 |
+
# Resize if they're different
|
30 |
+
if before_img.size != after_img.size:
|
31 |
+
after_img = after_img.resize(before_img.size, Image.LANCZOS)
|
32 |
+
|
33 |
+
width, height = before_img.size
|
34 |
+
|
35 |
+
# Create frames for the GIF
|
36 |
+
gif_frames = []
|
37 |
+
|
38 |
+
for i in range(frames + 1):
|
39 |
+
# Calculate position of the reveal bar
|
40 |
+
bar_position = int((width * i) / frames)
|
41 |
+
|
42 |
+
# Create a new frame
|
43 |
+
frame = Image.new('RGBA', (width, height))
|
44 |
+
|
45 |
+
# Paste the 'before' image
|
46 |
+
frame.paste(before_img, (0, 0))
|
47 |
+
|
48 |
+
# Create a mask for the 'after' image
|
49 |
+
mask = Image.new('L', (width, height), 0)
|
50 |
+
mask_array = np.array(mask)
|
51 |
+
mask_array[:, :bar_position] = 255
|
52 |
+
mask = Image.fromarray(mask_array)
|
53 |
+
|
54 |
+
# Paste the 'after' image with the mask
|
55 |
+
frame.paste(after_img, (0, 0), mask)
|
56 |
+
|
57 |
+
# Add to frames
|
58 |
+
gif_frames.append(frame.convert('RGBA'))
|
59 |
+
|
60 |
+
# Save as GIF
|
61 |
+
gif_frames[0].save(
|
62 |
+
output_path,
|
63 |
+
save_all=True,
|
64 |
+
append_images=gif_frames[1:],
|
65 |
+
optimize=False,
|
66 |
+
duration=duration,
|
67 |
+
loop=0,
|
68 |
+
disposal=2
|
69 |
+
)
|
70 |
+
|
71 |
+
return output_path
|
72 |
+
|
73 |
+
def main():
|
74 |
+
parser = argparse.ArgumentParser(description='Create a before/after comparison GIF with a sliding reveal effect')
|
75 |
+
parser.add_argument('before_image', help='Path to the before image')
|
76 |
+
parser.add_argument('after_image', help='Path to the after image')
|
77 |
+
parser.add_argument('--output', '-o', help='Output path for the GIF', default='comparison.gif')
|
78 |
+
parser.add_argument('--duration', '-d', type=int, help='Duration of each frame in ms', default=100)
|
79 |
+
parser.add_argument('--frames', '-f', type=int, help='Number of frames to generate', default=20)
|
80 |
+
|
81 |
+
args = parser.parse_args()
|
82 |
+
|
83 |
+
output_path = create_comparison_gif(
|
84 |
+
args.before_image,
|
85 |
+
args.after_image,
|
86 |
+
args.output,
|
87 |
+
args.duration,
|
88 |
+
args.frames
|
89 |
+
)
|
90 |
+
|
91 |
+
print(f"Created comparison GIF: {output_path}")
|
92 |
+
|
93 |
+
if __name__ == "__main__":
|
94 |
+
main()
|
examples/elon_compare.gif
ADDED
![]() |
Git LFS Details
|
run.py
CHANGED
@@ -15,5 +15,4 @@ def run_comfyui():
|
|
15 |
|
16 |
if __name__ == "__main__":
|
17 |
run_comfyui()
|
18 |
-
print(
|
19 |
-
f"Now run port-forwarding\nssh -L {PORT}:localhost:{PORT} root@[IP_ADDRESS] -p [RUNPOD_PORT] -i ~/.ssh/[PRIVATE_KEY_NAME]")
|
|
|
15 |
|
16 |
if __name__ == "__main__":
|
17 |
run_comfyui()
|
18 |
+
print(f"Enable port-forwarding\nssh -L {PORT}:localhost:{PORT} [NAME]@[IP_ADDRESS] -p [SERVER_PORT] -i [PRIVATE_KEY]")
|
|