multimodalart HF Staff commited on
Commit
d1520c4
·
verified ·
1 Parent(s): 7e64a04

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -29
app.py CHANGED
@@ -3,25 +3,13 @@ import spaces
3
  import torch
4
  from diffusers import Cosmos2TextToImagePipeline, EDMEulerScheduler
5
  import random
6
-
7
- model_14b_id = "nvidia/Cosmos-Predict2-14B-Text2Image"
8
  model_2b_id = "nvidia/Cosmos-Predict2-2B-Text2Image"
9
 
10
- pipe_14b = Cosmos2TextToImagePipeline.from_pretrained(model_14b_id,
11
- revision="refs/pr/1",
12
- torch_dtype=torch.bfloat16
13
- )
14
-
15
- #pipe_2b = Cosmos2TextToImagePipeline.from_pretrained(model_2b_id,
16
- # revision="refs/pr/2",
17
- # text_encoder=pipe_14b.text_encoder,
18
- # safety_checker=pipe_14b.safety_checker,
19
- # vae=pipe_14b.vae,
20
- # tokenizer=pipe_14b.tokenizer,
21
- # torch_dtype=torch.bfloat16
22
- # )
23
- pipe_14b.to("cuda")
24
- #pipe_2b.to("cuda")
25
 
26
  scheduler = EDMEulerScheduler(
27
  sigma_min=0.002,
@@ -43,17 +31,9 @@ def generate_image(prompt,
43
  negative_prompt="The video captures a series of frames showing ugly scenes, static with no motion, motion blur, over-saturation, shaky footage, low resolution, grainy texture, pixelated images, poorly lit areas, underexposed and overexposed scenes, poor color balance, washed out colors, choppy sequences, jerky movements, low frame rate, artifacting, color banding, unnatural transitions, outdated special effects, fake elements, unconvincing visuals, poorly edited content, jump cuts, visual noise, and flickering. Overall, the video is of poor quality.",
44
  seed=42,
45
  randomize_seed=False,
46
- model_choice="14B",
47
  progress=gr.Progress(track_tqdm=True)
48
  ):
49
-
50
- if model_choice == "14B":
51
- pipe = pipe_14b
52
- #pipe_2b.to("cpu")
53
-
54
- #else:
55
- # pipe = pipe_2b
56
- # pipe_14b.to("cpu")
57
 
58
  if randomize_seed:
59
  actual_seed = random.randint(0, 1000000)
@@ -62,7 +42,7 @@ def generate_image(prompt,
62
 
63
  generator = torch.Generator().manual_seed(actual_seed)
64
 
65
- output = pipe(
66
  prompt=prompt,
67
  negative_prompt=negative_prompt,
68
  generator=generator
@@ -86,7 +66,7 @@ example_prompts = [
86
  with gr.Blocks() as demo:
87
  gr.Markdown(
88
  """
89
- # Cosmos-Predict2 14B Text2Image
90
  [[Model]](https://huggingface.co/nvidia/Cosmos-Predict2-14B-Text2Image), [[Code]](https://github.com/nvidia-cosmos/cosmos-predict2)
91
  """
92
  )
@@ -121,7 +101,7 @@ with gr.Blocks() as demo:
121
 
122
  model_radio = gr.Radio(
123
  choices=["14B", "2B"],
124
- value="14B",
125
  label="Model Selection",
126
  visible=False
127
  )
 
3
  import torch
4
  from diffusers import Cosmos2TextToImagePipeline, EDMEulerScheduler
5
  import random
 
 
6
  model_2b_id = "nvidia/Cosmos-Predict2-2B-Text2Image"
7
 
8
+ pipe_2b = Cosmos2TextToImagePipeline.from_pretrained(model_2b_id,
9
+ revision="refs/pr/2",
10
+ torch_dtype=torch.bfloat16
11
+ )
12
+ pipe_2b.to("cuda")
 
 
 
 
 
 
 
 
 
 
13
 
14
  scheduler = EDMEulerScheduler(
15
  sigma_min=0.002,
 
31
  negative_prompt="The video captures a series of frames showing ugly scenes, static with no motion, motion blur, over-saturation, shaky footage, low resolution, grainy texture, pixelated images, poorly lit areas, underexposed and overexposed scenes, poor color balance, washed out colors, choppy sequences, jerky movements, low frame rate, artifacting, color banding, unnatural transitions, outdated special effects, fake elements, unconvincing visuals, poorly edited content, jump cuts, visual noise, and flickering. Overall, the video is of poor quality.",
32
  seed=42,
33
  randomize_seed=False,
34
+ model_choice="2B",
35
  progress=gr.Progress(track_tqdm=True)
36
  ):
 
 
 
 
 
 
 
 
37
 
38
  if randomize_seed:
39
  actual_seed = random.randint(0, 1000000)
 
42
 
43
  generator = torch.Generator().manual_seed(actual_seed)
44
 
45
+ output = pipe_2b(
46
  prompt=prompt,
47
  negative_prompt=negative_prompt,
48
  generator=generator
 
66
  with gr.Blocks() as demo:
67
  gr.Markdown(
68
  """
69
+ # Cosmos-Predict2 2B Text2Image
70
  [[Model]](https://huggingface.co/nvidia/Cosmos-Predict2-14B-Text2Image), [[Code]](https://github.com/nvidia-cosmos/cosmos-predict2)
71
  """
72
  )
 
101
 
102
  model_radio = gr.Radio(
103
  choices=["14B", "2B"],
104
+ value="2B",
105
  label="Model Selection",
106
  visible=False
107
  )