multimodalart HF Staff commited on
Commit
917acab
·
verified ·
1 Parent(s): 2236799

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -8
app.py CHANGED
@@ -8,23 +8,18 @@ import torch
8
  from diffusers import CosmosTextToImagePipeline
9
  import random
10
 
11
- # Available checkpoints
12
  model_14b_id = "diffusers-internal-dev/ct2i-14B"
13
  model_2b_id = "diffusers-internal-dev/ct2i-2B"
14
 
15
- # Load both pipelines once to avoid repeated loading
16
- print("Loading 14B model...")
17
  pipe_14b = CosmosTextToImagePipeline.from_pretrained(model_14b_id, torch_dtype=torch.bfloat16)
18
  pipe_14b.to("cuda")
19
 
20
- print("Loading 2B model...")
21
  pipe_2b = CosmosTextToImagePipeline.from_pretrained(model_2b_id, torch_dtype=torch.bfloat16)
22
  pipe_2b.to("cuda")
23
 
24
- print("Both models loaded successfully!")
25
-
26
  @spaces.GPU
27
- def generate_image(prompt, negative_prompt, seed, randomize_seed, model_choice, progress=gr.Progress(track_tqdm=True)):
28
  # Select the appropriate pipeline based on model choice
29
  if model_choice == "14B":
30
  pipe = pipe_14b
@@ -42,6 +37,18 @@ def generate_image(prompt, negative_prompt, seed, randomize_seed, model_choice,
42
  ).images[0]
43
  return output, actual_seed
44
 
 
 
 
 
 
 
 
 
 
 
 
 
45
  # Define the Gradio Blocks interface
46
  with gr.Blocks() as demo:
47
  gr.Markdown(
@@ -90,7 +97,13 @@ with gr.Blocks() as demo:
90
 
91
  with gr.Column():
92
  output_image = gr.Image(label="Generated Image", type="pil")
93
-
 
 
 
 
 
 
94
  generate_button.click(
95
  fn=generate_image,
96
  inputs=[prompt_input, negative_prompt_input, seed_input, randomize_seed_checkbox, model_radio],
 
8
  from diffusers import CosmosTextToImagePipeline
9
  import random
10
 
 
11
  model_14b_id = "diffusers-internal-dev/ct2i-14B"
12
  model_2b_id = "diffusers-internal-dev/ct2i-2B"
13
 
14
+
 
15
  pipe_14b = CosmosTextToImagePipeline.from_pretrained(model_14b_id, torch_dtype=torch.bfloat16)
16
  pipe_14b.to("cuda")
17
 
 
18
  pipe_2b = CosmosTextToImagePipeline.from_pretrained(model_2b_id, torch_dtype=torch.bfloat16)
19
  pipe_2b.to("cuda")
20
 
 
 
21
  @spaces.GPU
22
+ 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)):
23
  # Select the appropriate pipeline based on model choice
24
  if model_choice == "14B":
25
  pipe = pipe_14b
 
37
  ).images[0]
38
  return output, actual_seed
39
 
40
+
41
+
42
+ example_prompts = [
43
+ "A well-worn broom sweeps across a dusty wooden floor, its bristles gathering crumbs and flecks of debris in swift, rhythmic strokes. Dust motes dance in the sunbeams filtering through the window, glowing momentarily before settling. The quiet swish of straw brushing wood is interrupted only by the occasional creak of old floorboards. With each pass, the floor grows cleaner, restoring a sense of quiet order to the humble room.",
44
+ "A laundry machine whirs to life, tumbling colorful clothes behind the foggy glass door. Suds begin to form in a frothy dance, clinging to fabric as the drum spins. The gentle thud of shifting clothes creates a steady rhythm, like a heartbeat of the home. Outside the machine, a quiet calm fills the room, anticipation building for the softness and warmth of freshly laundered garments.",
45
+ "A robotic arm tightens a bolt beneath the hood of a car, its tool head rotating with practiced torque. The metal-on-metal sound clicks into place, and the arm pauses briefly before retracting with a soft hydraulic hiss. Overhead lights reflect off the glossy vehicle surface, while scattered tools and screens blink in the background—a garage scene reimagined through the lens of precision engineering.",
46
+ "A nighttime city bus terminal gradually shifts from stillness to subtle movement. At first, multiple double-decker buses are parked under the glow of overhead lights, with a central bus labeled '87D' facing forward and stationary. As the video progresses, the bus in the middle moves ahead slowly, its headlights brightening the surrounding area and casting reflections onto adjacent vehicles. The motion creates space in the lineup, signaling activity within the otherwise quiet station. It then comes to a smooth stop, resuming its position in line. Overhead signage in Chinese characters remains illuminated, enhancing the vibrant, urban night scene.",
47
+ "As the red light shifts to green, the red bus at the intersection begins to move forward, its headlights cutting through the falling snow. The snowy tire tracks deepen as the vehicle inches ahead, casting fresh lines onto the slushy road. Around it, streetlights glow warmer, illuminating the drifting flakes and wet reflections on the asphalt. Other cars behind start to edge forward, their beams joining the scene. The stillness of the urban street transitions into motion as the quiet snowfall is punctuated by the slow advance of traffic through the frosty city corridor.",
48
+ "In the later moments of the video, the female worker in the front, dressed in a white coat and hairnet, performs a repetitive yet precise task. She scoops golden granular material from a wide jar and steadily pours it into the next empty glass bottle on the conveyor belt. Her hand moves with practiced control as she aligns the scoop over each container, ensuring an even fill. The sequence highlights her focused attention and consistent motion, capturing the shift from preparation to active material handling as the production line advances bottle by bottle.",
49
+ "A wide-angle shot captures a sunny suburban street intersection, where the bright sunlight casts sharp shadows across the road. The scene is framed by a row of houses with beige and brown roofs, and lush green lawns. Autumn-colored trees add vibrant red and orange hues to the landscape. Overhead power lines stretch across the sky, and a fire hydrant is visible on the right side of the frame near the curb. A silver sedan is parked on the driveway of a house on the left, while a silver SUV is parked on the street in front of the house at the center of the camera view. The ego vehicle waits to turn right at the t-intersection, yielding to two other vehicles traveling in opposite directions. A black car enters the frame from the right, driving across the intersection and continuing straight ahead. The car's movement is smooth and steady, and it exits the frame to the left. The final frame shows the intersection with a vehicle moving from the left to the right side, the silver sedan and the SUV still parked in their initial positions, and the black car having moved out of view."
50
+ ]
51
+
52
  # Define the Gradio Blocks interface
53
  with gr.Blocks() as demo:
54
  gr.Markdown(
 
97
 
98
  with gr.Column():
99
  output_image = gr.Image(label="Generated Image", type="pil")
100
+
101
+ gr.Examples(
102
+ examples=example_prompts,
103
+ inputs=[prompt_input],
104
+ outputs=[output_image, seed_input],
105
+ cache_examples="lazy"
106
+ )
107
  generate_button.click(
108
  fn=generate_image,
109
  inputs=[prompt_input, negative_prompt_input, seed_input, randomize_seed_checkbox, model_radio],