Spaces:
Sleeping
Sleeping
Upload 6 files
Browse files- .gitattributes +4 -0
- app.py +193 -116
- examples/0052/oe.jpg +3 -0
- examples/0052/ue.jpg +3 -0
- examples/0072/oe.jpg +3 -0
- examples/0072/ue.jpg +3 -0
- requirements.txt +14 -14
.gitattributes
CHANGED
|
@@ -33,3 +33,7 @@ saved_model/**/* 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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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
|
| 36 |
+
examples/0052/oe.jpg filter=lfs diff=lfs merge=lfs -text
|
| 37 |
+
examples/0052/ue.jpg filter=lfs diff=lfs merge=lfs -text
|
| 38 |
+
examples/0072/oe.jpg filter=lfs diff=lfs merge=lfs -text
|
| 39 |
+
examples/0072/ue.jpg filter=lfs diff=lfs merge=lfs -text
|
app.py
CHANGED
|
@@ -1,154 +1,231 @@
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import numpy as np
|
| 3 |
import random
|
| 4 |
-
|
| 5 |
-
#
|
| 6 |
-
from diffusers import DiffusionPipeline
|
| 7 |
import torch
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 10 |
-
model_repo_id = "stabilityai/sdxl-turbo" # Replace to the model you would like to use
|
| 11 |
-
|
| 12 |
if torch.cuda.is_available():
|
| 13 |
torch_dtype = torch.float16
|
| 14 |
else:
|
| 15 |
torch_dtype = torch.float32
|
| 16 |
|
| 17 |
-
pipe = DiffusionPipeline.from_pretrained(model_repo_id, torch_dtype=torch_dtype)
|
| 18 |
-
pipe = pipe.to(device)
|
| 19 |
|
| 20 |
MAX_SEED = np.iinfo(np.int32).max
|
| 21 |
MAX_IMAGE_SIZE = 1024
|
| 22 |
|
| 23 |
-
|
| 24 |
-
# @spaces.GPU #[uncomment to use ZeroGPU]
|
| 25 |
def infer(
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
randomize_seed,
|
| 30 |
-
width,
|
| 31 |
-
height,
|
| 32 |
-
guidance_scale,
|
| 33 |
-
num_inference_steps,
|
| 34 |
-
progress=gr.Progress(track_tqdm=True),
|
| 35 |
):
|
| 36 |
-
if randomize_seed:
|
| 37 |
-
|
|
|
|
| 38 |
|
| 39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
negative_prompt=negative_prompt,
|
| 44 |
-
guidance_scale=guidance_scale,
|
| 45 |
-
num_inference_steps=num_inference_steps,
|
| 46 |
-
width=width,
|
| 47 |
-
height=height,
|
| 48 |
-
generator=generator,
|
| 49 |
-
).images[0]
|
| 50 |
|
| 51 |
-
|
|
|
|
| 52 |
|
|
|
|
|
|
|
| 53 |
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
|
|
|
| 59 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
css = """
|
| 61 |
#col-container {
|
| 62 |
margin: 0 auto;
|
| 63 |
max-width: 640px;
|
| 64 |
}
|
| 65 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
|
| 67 |
-
|
| 68 |
-
with gr.Column(elem_id="col-container"):
|
| 69 |
-
gr.Markdown(" # Text-to-Image Gradio Template")
|
| 70 |
|
| 71 |
-
|
| 72 |
-
prompt = gr.Text(
|
| 73 |
-
label="Prompt",
|
| 74 |
-
show_label=False,
|
| 75 |
-
max_lines=1,
|
| 76 |
-
placeholder="Enter your prompt",
|
| 77 |
-
container=False,
|
| 78 |
-
)
|
| 79 |
|
| 80 |
-
|
| 81 |
|
| 82 |
-
|
|
|
|
| 83 |
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
)
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
value=0,
|
| 98 |
)
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 152 |
|
| 153 |
if __name__ == "__main__":
|
| 154 |
-
demo.
|
|
|
|
|
|
|
|
|
| 1 |
+
# -*- coding: utf-8 -*-
|
| 2 |
+
import os
|
| 3 |
+
import sys
|
| 4 |
import gradio as gr
|
| 5 |
import numpy as np
|
| 6 |
import random
|
| 7 |
+
import spaces #[uncomment to use ZeroGPU]
|
| 8 |
+
# from diffusers import DiffusionPipeline
|
|
|
|
| 9 |
import torch
|
| 10 |
+
from torchvision.transforms import ToTensor, ToPILImage
|
| 11 |
+
import logging
|
| 12 |
+
logging.getLogger("huggingface_hub").setLevel(logging.CRITICAL)
|
| 13 |
+
from huggingface_hub import hf_hub_download, snapshot_download
|
| 14 |
+
|
| 15 |
+
model_name = "iimmortall/UltraFusion"
|
| 16 |
+
auth_token = os.getenv("HF_AUTH_TOKEN")
|
| 17 |
+
# print(auth_token)
|
| 18 |
+
# greet_file = hf_hub_download(repo_id=model_name, filename="main.py", use_auth_token=auth_token)
|
| 19 |
+
# sys.path.append(os.path.split(greet_file)[0])
|
| 20 |
+
model_folder = snapshot_download(repo_id=model_name, token=auth_token)
|
| 21 |
+
# sys.path.append(model_folder)
|
| 22 |
+
sys.path.insert(0, model_folder)
|
| 23 |
+
print(sys.path)
|
| 24 |
+
# exit()
|
| 25 |
+
|
| 26 |
+
from ultrafusion_utils import load_model, run_ultrafusion
|
| 27 |
+
|
| 28 |
+
to_tensor = ToTensor()
|
| 29 |
+
to_pil = ToPILImage()
|
| 30 |
+
ultrafusion_pipe, flow_model = load_model()
|
| 31 |
|
| 32 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
|
|
|
|
|
|
| 33 |
if torch.cuda.is_available():
|
| 34 |
torch_dtype = torch.float16
|
| 35 |
else:
|
| 36 |
torch_dtype = torch.float32
|
| 37 |
|
|
|
|
|
|
|
| 38 |
|
| 39 |
MAX_SEED = np.iinfo(np.int32).max
|
| 40 |
MAX_IMAGE_SIZE = 1024
|
| 41 |
|
| 42 |
+
@spaces.GPU(duration=10) #[uncomment to use ZeroGPU]
|
|
|
|
| 43 |
def infer(
|
| 44 |
+
under_expo_img,
|
| 45 |
+
over_expo_img,
|
| 46 |
+
# progress=gr.Progress(track_tqdm=True),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
):
|
| 48 |
+
# if randomize_seed:
|
| 49 |
+
# seed = random.randint(0, MAX_SEED)
|
| 50 |
+
# generator = torch.Generator().manual_seed(seed)
|
| 51 |
|
| 52 |
+
# image = pipe(
|
| 53 |
+
# prompt=prompt,
|
| 54 |
+
# negative_prompt=negative_prompt,
|
| 55 |
+
# guidance_scale=guidance_scale,
|
| 56 |
+
# num_inference_steps=num_inference_steps,
|
| 57 |
+
# width=width,
|
| 58 |
+
# height=height,
|
| 59 |
+
# generator=generator,
|
| 60 |
+
# ).images[0]
|
| 61 |
|
| 62 |
+
print(under_expo_img.size)
|
| 63 |
+
print("reciving image")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
|
| 65 |
+
under_expo_img = under_expo_img.resize([1500, 1000])
|
| 66 |
+
over_expo_img = over_expo_img.resize([1500, 1000])
|
| 67 |
|
| 68 |
+
ue = to_tensor(under_expo_img).unsqueeze(dim=0).to("cuda")
|
| 69 |
+
oe = to_tensor(over_expo_img).unsqueeze(dim=0).to("cuda")
|
| 70 |
|
| 71 |
+
out = run_ultrafusion(ue, oe, 'test', flow_model=flow_model, pipe=ultrafusion_pipe, consistent_start=None)
|
| 72 |
+
|
| 73 |
+
out = out.clamp(0, 1).squeeze()
|
| 74 |
+
out_pil = to_pil(out)
|
| 75 |
+
|
| 76 |
+
return out_pil
|
| 77 |
|
| 78 |
+
|
| 79 |
+
examples= [
|
| 80 |
+
[os.path.join("examples", img_name, "ue.jpg"),
|
| 81 |
+
os.path.join("examples", img_name, "oe.jpg")] for img_name in sorted(os.listdir("examples"))
|
| 82 |
+
]
|
| 83 |
+
IMG_W = 320
|
| 84 |
+
IMG_H = 240
|
| 85 |
css = """
|
| 86 |
#col-container {
|
| 87 |
margin: 0 auto;
|
| 88 |
max-width: 640px;
|
| 89 |
}
|
| 90 |
"""
|
| 91 |
+
# max-heigh: 1500px;
|
| 92 |
+
|
| 93 |
+
_HEADER_ = '''
|
| 94 |
+
<h2><b>Official 🤗 UltraHDR Demo</b></h2><h2><a href='' target='_blank'><b>UltraHDR: xxx</b></a></h2>
|
| 95 |
+
'''
|
| 96 |
+
|
| 97 |
+
_CITE_ = r"""
|
| 98 |
+
📝 **Citation**
|
| 99 |
+
|
| 100 |
+
If you find our work useful for your research or applications, please cite using this bibtex:
|
| 101 |
+
```bibtex
|
| 102 |
+
@article{xxx,
|
| 103 |
+
title={xxx},
|
| 104 |
+
author={xxx},
|
| 105 |
+
journal={arXiv preprint arXiv:xx.xx},
|
| 106 |
+
year={2024}
|
| 107 |
+
}
|
| 108 |
+
```
|
| 109 |
|
| 110 |
+
📋 **License**
|
|
|
|
|
|
|
| 111 |
|
| 112 |
+
CC BY-NC 4.0. LICENSE.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 113 |
|
| 114 |
+
📧 **Contact**
|
| 115 |
|
| 116 |
+
If you have any questions, feel free to open a discussion or contact us at <b>[email protected]</b>.
|
| 117 |
+
"""
|
| 118 |
|
| 119 |
+
with gr.Blocks(css=css) as demo:
|
| 120 |
+
with gr.Column(elem_id="col-container"):
|
| 121 |
+
gr.Markdown(" # UltraHDR")
|
| 122 |
+
with gr.Row():
|
| 123 |
+
under_expo_img = gr.Image(label="UnderExposureImage", show_label=True,
|
| 124 |
+
image_mode="RGB",
|
| 125 |
+
sources=["upload", ],
|
| 126 |
+
width=IMG_W,
|
| 127 |
+
height=IMG_H,
|
| 128 |
+
type="pil"
|
| 129 |
)
|
| 130 |
+
over_expo_img = gr.Image(label="OverExposureImage", show_label=True,
|
| 131 |
+
image_mode="RGB",
|
| 132 |
+
sources=["upload", ],
|
| 133 |
+
width=IMG_W,
|
| 134 |
+
height=IMG_H,
|
| 135 |
+
type="pil"
|
|
|
|
| 136 |
)
|
| 137 |
+
with gr.Row():
|
| 138 |
+
run_button = gr.Button("Run", variant="primary") # scale=0,
|
| 139 |
+
|
| 140 |
+
result = gr.Image(label="Result", show_label=True,
|
| 141 |
+
type='pil',
|
| 142 |
+
image_mode='RGB',
|
| 143 |
+
format="png",
|
| 144 |
+
width=IMG_W*2,
|
| 145 |
+
height=IMG_H*2,
|
| 146 |
+
)
|
| 147 |
+
|
| 148 |
+
# with gr.Row():
|
| 149 |
+
# prompt = gr.Text(
|
| 150 |
+
# label="Prompt",
|
| 151 |
+
# show_label=False,
|
| 152 |
+
# max_lines=1,
|
| 153 |
+
# placeholder="Enter your prompt",
|
| 154 |
+
# container=False,
|
| 155 |
+
# )
|
| 156 |
+
# negative_prompt = gr.Text(
|
| 157 |
+
# label="Negative prompt",
|
| 158 |
+
# max_lines=1,
|
| 159 |
+
# placeholder="Enter a negative prompt",
|
| 160 |
+
# visible=False,
|
| 161 |
+
# )
|
| 162 |
+
# with gr.Accordion("Advanced Settings", open=False):
|
| 163 |
+
# negative_prompt = gr.Text(
|
| 164 |
+
# label="Negative prompt",
|
| 165 |
+
# max_lines=1,
|
| 166 |
+
# placeholder="Enter a negative prompt",
|
| 167 |
+
# visible=False,
|
| 168 |
+
# )
|
| 169 |
+
|
| 170 |
+
# seed = gr.Slider(
|
| 171 |
+
# label="Seed",
|
| 172 |
+
# minimum=0,
|
| 173 |
+
# maximum=MAX_SEED,
|
| 174 |
+
# step=1,
|
| 175 |
+
# value=0,
|
| 176 |
+
# )
|
| 177 |
+
|
| 178 |
+
# randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
|
| 179 |
+
|
| 180 |
+
# with gr.Row():
|
| 181 |
+
# width = gr.Slider(
|
| 182 |
+
# label="Width",
|
| 183 |
+
# minimum=256,
|
| 184 |
+
# maximum=MAX_IMAGE_SIZE,
|
| 185 |
+
# step=32,
|
| 186 |
+
# value=1024, # Replace with defaults that work for your model
|
| 187 |
+
# )
|
| 188 |
+
|
| 189 |
+
# height = gr.Slider(
|
| 190 |
+
# label="Height",
|
| 191 |
+
# minimum=256,
|
| 192 |
+
# maximum=MAX_IMAGE_SIZE,
|
| 193 |
+
# step=32,
|
| 194 |
+
# value=1024, # Replace with defaults that work for your model
|
| 195 |
+
# )
|
| 196 |
+
|
| 197 |
+
# with gr.Row():
|
| 198 |
+
# guidance_scale = gr.Slider(
|
| 199 |
+
# label="Guidance scale",
|
| 200 |
+
# minimum=0.0,
|
| 201 |
+
# maximum=10.0,
|
| 202 |
+
# step=0.1,
|
| 203 |
+
# value=0.0, # Replace with defaults that work for your model
|
| 204 |
+
# )
|
| 205 |
+
|
| 206 |
+
# num_inference_steps = gr.Slider(
|
| 207 |
+
# label="Number of inference steps",
|
| 208 |
+
# minimum=1,
|
| 209 |
+
# maximum=50,
|
| 210 |
+
# step=1,
|
| 211 |
+
# value=2, # Replace with defaults that work for your model
|
| 212 |
+
# )
|
| 213 |
+
|
| 214 |
+
gr.Examples(
|
| 215 |
+
examples=examples,
|
| 216 |
+
inputs=[under_expo_img, over_expo_img],
|
| 217 |
+
label="Examples",
|
| 218 |
+
# examples_per_page=10,
|
| 219 |
+
cache_examples=False,
|
| 220 |
+
# fn=infer,
|
| 221 |
+
)
|
| 222 |
+
# gr.Markdown(_CITE_)
|
| 223 |
+
run_button.click(fn=infer,
|
| 224 |
+
inputs=[under_expo_img, over_expo_img],
|
| 225 |
+
outputs=[result,],
|
| 226 |
+
)
|
| 227 |
|
| 228 |
if __name__ == "__main__":
|
| 229 |
+
demo.queue(max_size=10)
|
| 230 |
+
demo.launch(share=True)
|
| 231 |
+
# demo.launch(server_name="0.0.0.0", debug=True, show_api=True, show_error=True, share=False)
|
examples/0052/oe.jpg
ADDED
|
Git LFS Details
|
examples/0052/ue.jpg
ADDED
|
Git LFS Details
|
examples/0072/oe.jpg
ADDED
|
Git LFS Details
|
examples/0072/ue.jpg
ADDED
|
Git LFS Details
|
requirements.txt
CHANGED
|
@@ -1,15 +1,15 @@
|
|
| 1 |
-
accelerate
|
| 2 |
-
diffusers
|
| 3 |
-
invisible_watermark
|
| 4 |
-
transformers
|
| 5 |
-
xformers
|
| 6 |
-
torch==2.4.1
|
| 7 |
-
torchvision==0.19.1
|
| 8 |
-
omegaconf
|
| 9 |
-
numpy
|
| 10 |
-
pillow
|
| 11 |
-
einops
|
| 12 |
-
scipy
|
| 13 |
-
numpy
|
| 14 |
-
ftfy
|
| 15 |
pytorch_lightning==2.4
|
|
|
|
| 1 |
+
accelerate
|
| 2 |
+
diffusers
|
| 3 |
+
invisible_watermark
|
| 4 |
+
transformers
|
| 5 |
+
xformers
|
| 6 |
+
torch==2.4.1
|
| 7 |
+
torchvision==0.19.1
|
| 8 |
+
omegaconf
|
| 9 |
+
numpy
|
| 10 |
+
pillow
|
| 11 |
+
einops
|
| 12 |
+
scipy
|
| 13 |
+
numpy
|
| 14 |
+
ftfy
|
| 15 |
pytorch_lightning==2.4
|