PhyscalX commited on
Commit
5283d70
1 Parent(s): d4ea260

Initial app

Browse files
Files changed (5) hide show
  1. .flake8 +21 -0
  2. .gitignore +55 -0
  3. README.md +2 -2
  4. app.py +152 -4
  5. requirements.txt +6 -0
.flake8 ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [flake8]
2
+ max-line-length = 100
3
+ ignore =
4
+ # whitespace before ':' (conflicted with Black)
5
+ E203,
6
+ # ambiguous variable name
7
+ E741,
8
+ # ‘from module import *’ used; unable to detect undefined names
9
+ F403,
10
+ # name may be undefined, or defined from star imports: module
11
+ F405,
12
+ # redefinition of unused name from line N
13
+ F811,
14
+ # undefined name
15
+ F821,
16
+ # line break before binary operator
17
+ W503,
18
+ # line break after binary operator
19
+ W504
20
+ # module imported but unused
21
+ per-file-ignores = __init__.py: F401
.gitignore ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Compiled Object files
2
+ *.slo
3
+ *.lo
4
+ *.o
5
+ *.cuo
6
+
7
+ # Compiled Dynamic libraries
8
+ *.so
9
+ *.dll
10
+ *.dylib
11
+
12
+ # Compiled Static libraries
13
+ *.lai
14
+ *.la
15
+ *.a
16
+ *.lib
17
+
18
+ # Compiled python
19
+ *.pyc
20
+ __pycache__
21
+
22
+ # Compiled MATLAB
23
+ *.mex*
24
+
25
+ # IPython notebook checkpoints
26
+ .ipynb_checkpoints
27
+
28
+ # Editor temporaries
29
+ *.swp
30
+ *~
31
+
32
+ # Sublime Text settings
33
+ *.sublime-workspace
34
+ *.sublime-project
35
+
36
+ # Eclipse Project settings
37
+ *.*project
38
+ .settings
39
+
40
+ # QtCreator files
41
+ *.user
42
+
43
+ # VSCode files
44
+ .vscode
45
+
46
+ # IDEA files
47
+ .idea
48
+
49
+ # OSX dir files
50
+ .DS_Store
51
+
52
+ # Android files
53
+ .gradle
54
+ *.iml
55
+ local.properties
README.md CHANGED
@@ -1,5 +1,5 @@
1
  ---
2
- title: Nova D48w1024 Sdxl1024
3
  emoji: 📉
4
  colorFrom: purple
5
  colorTo: gray
@@ -8,7 +8,7 @@ sdk_version: 5.9.1
8
  app_file: app.py
9
  pinned: false
10
  license: apache-2.0
11
- short_description: 'NOVA-0.6B Text-to-Image 1024x1024 '
12
  ---
13
 
14
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
  ---
2
+ title: nova-d48w1024-sdxl1024
3
  emoji: 📉
4
  colorFrom: purple
5
  colorTo: gray
 
8
  app_file: app.py
9
  pinned: false
10
  license: apache-2.0
11
+ short_description: 'NOVA Text-to-Image APP'
12
  ---
13
 
14
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py CHANGED
@@ -1,7 +1,155 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
 
3
- def greet(name):
4
- return "Hello " + name + "!!"
 
5
 
6
- demo = gr.Interface(fn=greet, inputs="text", outputs="text")
7
- demo.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright (c) 2024-present, BAAI. All Rights Reserved.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ ##############################################################################
15
+ """NOVA T2I application."""
16
+
17
+ import argparse
18
+ import os
19
+
20
  import gradio as gr
21
+ import numpy as np
22
+ import spaces
23
+ import torch
24
+
25
+ from diffnext.pipelines import NOVAPipeline
26
+ from diffnext.utils import export_to_image
27
+
28
+ # Switch to the allocator optimized for dynamic shape.
29
+ os.environ["PYTORCH_CUDA_ALLOC_CONF"] = "expandable_segments:True"
30
+
31
+
32
+ def parse_args():
33
+ """Parse arguments."""
34
+ parser = argparse.ArgumentParser(description="Serve NOVA T2I application")
35
+ parser.add_argument("--model", default="", help="model path")
36
+ parser.add_argument("--device", type=int, default=0, help="device index")
37
+ parser.add_argument("--precision", default="float16", help="compute precision")
38
+ return parser.parse_args()
39
+
40
+
41
+ @spaces.GPU()
42
+ def generate_image4(
43
+ prompt,
44
+ negative_prompt,
45
+ seed,
46
+ randomize_seed,
47
+ guidance_scale,
48
+ num_inference_steps,
49
+ num_diffusion_steps,
50
+ progress=gr.Progress(track_tqdm=True),
51
+ ):
52
+ """Generate 4 images."""
53
+ args = locals()
54
+ seed = np.random.randint(2147483647) if randomize_seed else seed
55
+ device = getattr(pipe, "_offload_device", pipe.device)
56
+ generator = torch.Generator(device=device).manual_seed(seed)
57
+ images = pipe(generator=generator, num_images_per_prompt=4, **args).images
58
+ return [export_to_image(image, quality=95) for image in images] + [seed]
59
+
60
+
61
+ css = """#col-container {margin: 0 auto; max-width: 1366px}"""
62
+ title = "Autoregressive Video Generation without Vector Quantization"
63
+ abbr = "<strong>NO</strong>n-quantized <strong>V</strong>ideo <strong>A</strong>utoregressive"
64
+ header = (
65
+ "<div align='center'>"
66
+ "<h2>Autoregressive Video Generation without Vector Quantization</h2>"
67
+ "<h3><a href='https://arxiv.org/abs/2412.14169' target='_blank' rel='noopener'>[paper]</a>"
68
+ "<a href='https://github.com/baaivision/NOVA' target='_blank' rel='noopener'>[code]</a></h3>"
69
+ "</div>"
70
+ )
71
+ header2 = f"<div align='center'><h3>🖼️ A {abbr} model for continuous visual generation</h3></div>"
72
+
73
+ examples = [
74
+ "a selfie of an old man with a white beard.",
75
+ "a woman with long hair next to a luminescent bird.",
76
+ "a digital artwork of a cat styled in a whimsical fashion. The overall vibe is quirky and artistic.", # noqa
77
+ "a shiba inu wearing a beret and black turtleneck.",
78
+ "a beautiful afghan women by red hair and green eyes.",
79
+ "beautiful fireworks in the sky with red, white and blue.",
80
+ "A dragon perched majestically on a craggy, smoke-wreathed mountain.",
81
+ "A photo of llama wearing sunglasses standing on the deck of a spaceship with the Earth in the background.", # noqa
82
+ "Two pandas in fluffy slippers and bathrobes, lazily munching on bamboo.",
83
+ ]
84
+
85
+
86
+ if __name__ == "__main__":
87
+ args = parse_args()
88
+
89
+ device_type = "cuda" if torch.cuda.is_available() else "cpu"
90
+ device, dtype = torch.device(device_type, args.device), getattr(torch, args.precision.lower())
91
+ pipe = NOVAPipeline.from_pretrained(args.model, torch_dtype=dtype).to(device)
92
+
93
+ # Main Application.
94
+ app = gr.Blocks(css=css, theme="origin").__enter__()
95
+ container = gr.Column(elem_id="col-container").__enter__()
96
+ _, main_row = gr.Markdown(header), gr.Row().__enter__()
97
+
98
+ # Input.
99
+ input_col = gr.Column().__enter__()
100
+ prompt = gr.Text(
101
+ label="Prompt",
102
+ placeholder="Describe the video you want to generate",
103
+ value="a shiba inu wearing a beret and black turtleneck.",
104
+ lines=5,
105
+ )
106
+ negative_prompt = gr.Text(
107
+ label="Negative Prompt",
108
+ placeholder="Describe what you don't want in the image",
109
+ value="low quality, deformed, distorted, disfigured, fused fingers, bad anatomy, weird hand", # noqa
110
+ lines=5,
111
+ )
112
+ # fmt: off
113
+ adv_opt = gr.Accordion("Advanced Options", open=True).__enter__()
114
+ seed = gr.Slider(label="Seed", maximum=2147483647, step=1, value=0)
115
+ randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
116
+ guidance_scale = gr.Slider(label="Guidance scale", minimum=1, maximum=10, step=0.1, value=5)
117
+ with gr.Row():
118
+ num_inference_steps = gr.Slider(label="Inference steps", minimum=1, maximum=128, step=1, value=64) # noqa
119
+ num_diffusion_steps = gr.Slider(label="Diffusion steps", minimum=1, maximum=50, step=1, value=25) # noqa
120
+ adv_opt.__exit__()
121
+ generate = gr.Button("Generate Image", variant="primary", size="lg")
122
+ input_col.__exit__()
123
+ # fmt: on
124
+
125
+ # Results.
126
+ result_col, _ = gr.Column().__enter__(), gr.Markdown(header2)
127
+ with gr.Row():
128
+ result1 = gr.Image(label="Result1", show_label=False)
129
+ result2 = gr.Image(label="Result2", show_label=False)
130
+ with gr.Row():
131
+ result3 = gr.Image(label="Result3", show_label=False)
132
+ result4 = gr.Image(label="Result4", show_label=False)
133
+ result_col.__exit__(), main_row.__exit__()
134
 
135
+ # Examples.
136
+ with gr.Row():
137
+ gr.Examples(examples=examples, inputs=[prompt])
138
 
139
+ # Events.
140
+ container.__exit__()
141
+ gr.on(
142
+ triggers=[generate.click, prompt.submit, negative_prompt.submit],
143
+ fn=generate_image4,
144
+ inputs=[
145
+ prompt,
146
+ negative_prompt,
147
+ seed,
148
+ randomize_seed,
149
+ guidance_scale,
150
+ num_inference_steps,
151
+ num_diffusion_steps,
152
+ ],
153
+ outputs=[result1, result2, result3, result4, seed],
154
+ )
155
+ app.__exit__(), app.launch()
requirements.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ torch
2
+ diffusers
3
+ transformers
4
+ accelerate
5
+ imageio[ffmpeg]
6
+ git+https://github.com/baaivision/NOVA.git