YACWC
This commit is contained in:
31
clip_endpoint.py
Normal file
31
clip_endpoint.py
Normal file
@@ -0,0 +1,31 @@
|
||||
import open_clip
|
||||
import torch
|
||||
|
||||
do_load = True
|
||||
if do_load:
|
||||
|
||||
#model_name = 'hf-hub:timm/ViT-L-16-SigLIP2-512'
|
||||
# model, preprocess = open_clip.create_model_from_pretrained('hf-hub:timm/ViT-L-16-SigLIP2-512')
|
||||
|
||||
|
||||
model_name = 'ViT-SO400M-14-SigLIP-384'
|
||||
pretrained_name = 'webli'
|
||||
model, _, preprocess = open_clip.create_model_and_transforms(model_name, pretrained=pretrained_name)
|
||||
device = 'cpu'
|
||||
model.eval()
|
||||
tokenizer = open_clip.get_tokenizer(model_name)
|
||||
|
||||
from bottle import route, run, template, request, debug
|
||||
@route('/encode')
|
||||
def get_matches():
|
||||
query = request.query.get('query','A large bird eating corn')
|
||||
with torch.no_grad():
|
||||
text_tokenized = tokenizer(query)
|
||||
vec = model.encode_text(text_tokenized).detach().cpu().tolist()
|
||||
|
||||
return {'vector':vec}
|
||||
|
||||
|
||||
|
||||
debug(True)
|
||||
run(host='0.0.0.0', port=53004, server='bjoern')
|
||||
Reference in New Issue
Block a user