multimodalart HF Staff commited on
Commit
845427f
·
verified ·
1 Parent(s): 1c639df

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -23
app.py CHANGED
@@ -5,21 +5,21 @@ 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
 
24
  scheduler = EDMEulerScheduler(
25
  sigma_min=0.002,
@@ -34,17 +34,16 @@ scheduler = EDMEulerScheduler(
34
  )
35
 
36
  pipe_14b.scheduler = scheduler
37
- pipe_2b.scheduler = scheduler
38
 
39
  @spaces.GPU
40
  def generate_image(prompt, 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.", seed=42, randomize_seed=False, model_choice="14B", progress=gr.Progress(track_tqdm=True)):
41
 
42
- if model_choice == "14B":
43
- pipe = pipe_14b
44
- pipe.to("cuda")
45
- else:
46
- pipe = pipe_2b
47
- pipe.to("cuda")
48
 
49
  if randomize_seed:
50
  actual_seed = random.randint(0, 1000000)
@@ -52,9 +51,13 @@ def generate_image(prompt, negative_prompt="The video captures a series of frame
52
  actual_seed = seed
53
 
54
  generator = torch.Generator().manual_seed(actual_seed)
55
- output = pipe(
56
- prompt=prompt, negative_prompt=negative_prompt, generator=generator
 
 
 
57
  ).images[0]
 
58
  return output, actual_seed
59
 
60
 
@@ -73,10 +76,7 @@ example_prompts = [
73
  with gr.Blocks() as demo:
74
  gr.Markdown(
75
  """
76
- # Cosmos Predict-2 Text-to-Image Generator
77
- Enter a detailed prompt to generate an image using the Cosmos model.
78
- You can also provide a negative prompt to guide the generation away from certain elements.
79
- Choose between the 14B model (higher quality, slower) or 2B model (faster, smaller).
80
  """
81
  )
82
  with gr.Row():
@@ -112,6 +112,7 @@ with gr.Blocks() as demo:
112
  choices=["14B", "2B"],
113
  value="14B",
114
  label="Model Selection",
 
115
  )
116
  generate_button = gr.Button("Generate Image")
117
 
 
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
+ pipe_14b.to("cuda")
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
 
24
  scheduler = EDMEulerScheduler(
25
  sigma_min=0.002,
 
34
  )
35
 
36
  pipe_14b.scheduler = scheduler
37
+ # pipe_2b.scheduler = scheduler
38
 
39
  @spaces.GPU
40
  def generate_image(prompt, 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.", seed=42, randomize_seed=False, model_choice="14B", progress=gr.Progress(track_tqdm=True)):
41
 
42
+ #if model_choice == "14B":
43
+ # pipe = pipe_14b
44
+ #else:
45
+ # pipe = pipe_2b
46
+ # pipe.to("cuda")
 
47
 
48
  if randomize_seed:
49
  actual_seed = random.randint(0, 1000000)
 
51
  actual_seed = seed
52
 
53
  generator = torch.Generator().manual_seed(actual_seed)
54
+
55
+ output = pipe_14b(
56
+ prompt=prompt,
57
+ negative_prompt=negative_prompt,
58
+ generator=generator
59
  ).images[0]
60
+
61
  return output, actual_seed
62
 
63
 
 
76
  with gr.Blocks() as demo:
77
  gr.Markdown(
78
  """
79
+ # Cosmos Predict-2 14B Text-to-Image Generator
 
 
 
80
  """
81
  )
82
  with gr.Row():
 
112
  choices=["14B", "2B"],
113
  value="14B",
114
  label="Model Selection",
115
+ visible=False
116
  )
117
  generate_button = gr.Button("Generate Image")
118