Spaces:
Sleeping
Sleeping
Commit
•
d312027
1
Parent(s):
0710d1c
Update app.py
Browse files
app.py
CHANGED
@@ -11,14 +11,26 @@ clip_model = CLIPModel.from_pretrained("openai/clip-vit-base-patch16")
|
|
11 |
|
12 |
text = st.text_area("Enter a description:")
|
13 |
if st.button("Generate Image") and text:
|
14 |
-
# Process text and get CLIP features
|
15 |
text_features = clip_processor(text, return_tensors="pt", padding=True)
|
16 |
|
17 |
-
#
|
18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
|
20 |
# For visualization, you can convert the image representation back to an image
|
21 |
-
image_array = image_representation.squeeze().
|
22 |
image = Image.fromarray((image_array * 255).astype('uint8'))
|
23 |
|
24 |
# Display the generated image
|
|
|
11 |
|
12 |
text = st.text_area("Enter a description:")
|
13 |
if st.button("Generate Image") and text:
|
14 |
+
# Process text and get CLIP features for text
|
15 |
text_features = clip_processor(text, return_tensors="pt", padding=True)
|
16 |
|
17 |
+
# Load an example image (replace this with your image loading logic)
|
18 |
+
example_image_path = "path/to/your/image.jpg"
|
19 |
+
example_image = Image.open(example_image_path)
|
20 |
+
|
21 |
+
# Process image and get CLIP features for image
|
22 |
+
image_features = clip_processor(images=example_image, return_tensors="pt", padding=True)
|
23 |
+
|
24 |
+
# Concatenate text and image features
|
25 |
+
combined_features = {
|
26 |
+
"pixel_values": torch.cat([text_features.pixel_values, image_features.pixel_values], dim=-1)
|
27 |
+
}
|
28 |
+
|
29 |
+
# Forward pass through CLIP
|
30 |
+
image_representation = clip_model(**combined_features).last_hidden_state.mean(dim=1)
|
31 |
|
32 |
# For visualization, you can convert the image representation back to an image
|
33 |
+
image_array = image_representation.squeeze().cpu().numpy()
|
34 |
image = Image.fromarray((image_array * 255).astype('uint8'))
|
35 |
|
36 |
# Display the generated image
|