hoh2000 commited on
Commit
e828422
·
verified ·
1 Parent(s): 236b00b

Create inference.py

Browse files
Files changed (1) hide show
  1. inference.py +14 -0
inference.py ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from pathlib import Path
2
+ from PIL import Image
3
+ from transformers import AutoProcessor, AutoModel
4
+ import torch
5
+
6
+ # Load model and processor
7
+ model = AutoModel.from_pretrained("cloudqi/cqi_text_to_image_pt_v0", trust_remote_code=True)
8
+ processor = AutoProcessor.from_pretrained("cloudqi/cqi_text_to_image_pt_v0", trust_remote_code=True)
9
+
10
+ def generate_image(prompt):
11
+ inputs = processor(prompt, return_tensors="pt")
12
+ with torch.no_grad():
13
+ output = model(**inputs).images[0] # assumes .images exists
14
+ return Image.fromarray(output)