File size: 701 Bytes
d5dc6c1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import torch
from transformers import CLIPProcessor, CLIPModel

# Load the pre-trained model and processor
model = CLIPModel.from_pretrained("openai/clip-vit-base-patch32")
processor = CLIPProcessor.from_pretrained("openai/clip-vit-base-patch32")

# Define the text prompt
text_prompt = "a futuristic city at sunset"

# Process the text prompt
inputs = processor(text=[text_prompt], return_tensors="pt", padding=True)

# Generate the image
with torch.no_grad():
    outputs = model(**inputs)
    logits_per_image = outputs.logits_per_image
    probs = logits_per_image.softmax(dim=1)

# Display the generated image (this is just an example; adjust as necessary for your chatbot framework)
print(probs)