Spaces:
Runtime error
Runtime error
Commit
·
953f815
1
Parent(s):
a2422c2
Pls work
Browse files
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
|
| 24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
-
#
|
| 27 |
-
|
| 28 |
|
| 29 |
# Save the generated image
|
| 30 |
output_image_path = "generated_image.png"
|
| 31 |
-
Image.fromarray(
|
| 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)
|