Tharunika1601 commited on
Commit
2883ce2
1 Parent(s): 9a435e2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -4
app.py CHANGED
@@ -24,9 +24,14 @@ if st.button("Generate Image") and text:
24
  # Process image and get CLIP features for image
25
  image_features = clip_processor(images=example_image, return_tensors="pt", padding=True)
26
 
 
 
 
 
 
27
  # Concatenate text and image features
28
  combined_features = {
29
- "pixel_values": torch.cat([text_features.pixel_values, image_features.pixel_values], dim=-1)
30
  }
31
 
32
  # Forward pass through CLIP
@@ -38,6 +43,3 @@ if st.button("Generate Image") and text:
38
 
39
  # Display the generated image
40
  st.image(generated_image, caption="Generated Image", use_column_width=True)
41
-
42
- # Save the generated image to a file (change the file path as needed)
43
- generated_image.save("generated_image.jpg")
 
24
  # Process image and get CLIP features for image
25
  image_features = clip_processor(images=example_image, return_tensors="pt", padding=True)
26
 
27
+ # Ensure the dimensions of pixel_values are the same for text and image features
28
+ max_len = max(text_features.pixel_values.shape[1], image_features.pixel_values.shape[1])
29
+ text_features.pixel_values = torch.nn.functional.pad(text_features.pixel_values, (0, max_len - text_features.pixel_values.shape[1]))
30
+ image_features.pixel_values = torch.nn.functional.pad(image_features.pixel_values, (0, max_len - image_features.pixel_values.shape[1]))
31
+
32
  # Concatenate text and image features
33
  combined_features = {
34
+ "pixel_values": torch.cat([text_features.pixel_values, image_features.pixel_values], dim=1)
35
  }
36
 
37
  # Forward pass through CLIP
 
43
 
44
  # Display the generated image
45
  st.image(generated_image, caption="Generated Image", use_column_width=True)