iimmortall commited on
Commit
c1d8208
·
verified ·
1 Parent(s): 4bae4fb

Upload 6 files

Browse files
.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
- # import spaces #[uncomment to use ZeroGPU]
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
- prompt,
27
- negative_prompt,
28
- seed,
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
- seed = random.randint(0, MAX_SEED)
 
38
 
39
- generator = torch.Generator().manual_seed(seed)
 
 
 
 
 
 
 
 
40
 
41
- image = pipe(
42
- prompt=prompt,
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
- return image, seed
 
52
 
 
 
53
 
54
- examples = [
55
- "Astronaut in a jungle, cold color palette, muted colors, detailed, 8k",
56
- "An astronaut riding a green horse",
57
- "A delicious ceviche cheesecake slice",
58
- ]
 
59
 
 
 
 
 
 
 
 
60
  css = """
61
  #col-container {
62
  margin: 0 auto;
63
  max-width: 640px;
64
  }
65
  """
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66
 
67
- with gr.Blocks(css=css) as demo:
68
- with gr.Column(elem_id="col-container"):
69
- gr.Markdown(" # Text-to-Image Gradio Template")
70
 
71
- with gr.Row():
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
- run_button = gr.Button("Run", scale=0, variant="primary")
81
 
82
- result = gr.Image(label="Result", show_label=False)
 
83
 
84
- with gr.Accordion("Advanced Settings", open=False):
85
- negative_prompt = gr.Text(
86
- label="Negative prompt",
87
- max_lines=1,
88
- placeholder="Enter a negative prompt",
89
- visible=False,
 
 
 
 
90
  )
91
-
92
- seed = gr.Slider(
93
- label="Seed",
94
- minimum=0,
95
- maximum=MAX_SEED,
96
- step=1,
97
- value=0,
98
  )
99
-
100
- randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
101
-
102
- with gr.Row():
103
- width = gr.Slider(
104
- label="Width",
105
- minimum=256,
106
- maximum=MAX_IMAGE_SIZE,
107
- step=32,
108
- value=1024, # Replace with defaults that work for your model
109
- )
110
-
111
- height = gr.Slider(
112
- label="Height",
113
- minimum=256,
114
- maximum=MAX_IMAGE_SIZE,
115
- step=32,
116
- value=1024, # Replace with defaults that work for your model
117
- )
118
-
119
- with gr.Row():
120
- guidance_scale = gr.Slider(
121
- label="Guidance scale",
122
- minimum=0.0,
123
- maximum=10.0,
124
- step=0.1,
125
- value=0.0, # Replace with defaults that work for your model
126
- )
127
-
128
- num_inference_steps = gr.Slider(
129
- label="Number of inference steps",
130
- minimum=1,
131
- maximum=50,
132
- step=1,
133
- value=2, # Replace with defaults that work for your model
134
- )
135
-
136
- gr.Examples(examples=examples, inputs=[prompt])
137
- gr.on(
138
- triggers=[run_button.click, prompt.submit],
139
- fn=infer,
140
- inputs=[
141
- prompt,
142
- negative_prompt,
143
- seed,
144
- randomize_seed,
145
- width,
146
- height,
147
- guidance_scale,
148
- num_inference_steps,
149
- ],
150
- outputs=[result, seed],
151
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
152
 
153
  if __name__ == "__main__":
154
- demo.launch()
 
 
 
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>xxx@gmail.com</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

  • SHA256: d52803ca665d3d9f4ddf75ae000c40bbd26fbdfba70515a248c679a1e2492a33
  • Pointer size: 132 Bytes
  • Size of remote file: 6.1 MB
examples/0052/ue.jpg ADDED

Git LFS Details

  • SHA256: 9029b5c8946f6a14118975d78cbddaf29e0ac3c4ccadb4370e40b9ef9035c889
  • Pointer size: 132 Bytes
  • Size of remote file: 4.03 MB
examples/0072/oe.jpg ADDED

Git LFS Details

  • SHA256: fd4bbaab7aa1e40e65a052f03ad390472b127ff5b1796ea63890a40a55e5df32
  • Pointer size: 132 Bytes
  • Size of remote file: 8.91 MB
examples/0072/ue.jpg ADDED

Git LFS Details

  • SHA256: 2862696c5ac0ad0ead8883b011ff8963ee2c819fc01d301298e1204e3553040e
  • Pointer size: 132 Bytes
  • Size of remote file: 1.78 MB
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