BeveledCube commited on
Commit
953f815
1 Parent(s): a2422c2
Files changed (1) hide show
  1. main.py +10 -5
main.py CHANGED
@@ -20,14 +20,19 @@ text = "a cat sitting on a table"
20
  # Tokenize text and get features
21
  inputs = clip_processor(text, return_tensors="pt", padding=True)
22
 
23
- # Generate image features
24
- image_features = clip_model.get_image_features(pixel_values=inputs.pixel_values)
 
 
 
 
 
25
 
26
- # Generate image from features
27
- generated_image = clip_model.generate_images(image_features)
28
 
29
  # Save the generated image
30
  output_image_path = "generated_image.png"
31
- Image.fromarray(generated_image).save(output_image_path)
32
 
33
  print("Image generated and saved as:", output_image_path)
 
20
  # Tokenize text and get features
21
  inputs = clip_processor(text, return_tensors="pt", padding=True)
22
 
23
+ # Generate image from text
24
+ generated_image = clip_model.generate_images(
25
+ input_ids=inputs.input_ids,
26
+ attention_mask=inputs.attention_mask,
27
+ visual_input=None, # We don't provide image input
28
+ return_tensors="pt" # Return PyTorch tensor
29
+ )
30
 
31
+ # Convert the generated image tensor to a NumPy array
32
+ generated_image_np = generated_image[0].cpu().numpy()
33
 
34
  # Save the generated image
35
  output_image_path = "generated_image.png"
36
+ Image.fromarray(generated_image_np).save(output_image_path)
37
 
38
  print("Image generated and saved as:", output_image_path)