66 lines
1.8 KiB
Python
66 lines
1.8 KiB
Python
import sys, os
|
|
sys.path.append("/home/thebears/Web/Nuggets/SearchInterface/SearchUtil")
|
|
sys.path.append("/home/thebears/Web/Nuggets/SearchInterface/VectorService/util")
|
|
import embed_scores as ES
|
|
import numpy as np
|
|
import time
|
|
from CommonCode import kwq
|
|
|
|
# %%
|
|
from CommonCode.video_meta import FTPVide
|
|
o
|
|
|
|
|
|
video_path = '/home/thebears/temp/dog.mp4'
|
|
prompt = 'hello'
|
|
|
|
video_embeds = ES.get_embeddings_for_a_file(video_path)
|
|
prompt_embeds = ES.get_query_vector(prompt)
|
|
video_norm_embeds = FTPVideo.vec_norm(video_embeds['embeds'])
|
|
prompt_norm_embed = FTPVideo.vec_norm(prompt_embeds)
|
|
scores = np.dot(video_norm_embeds, prompt_norm_embed.T).squeeze().tolist()
|
|
|
|
|
|
|
|
ff = FTPVideo(file_path, ignore_filename = True)
|
|
res = ff.embeddings
|
|
results = np.asarray([res['frame_offsets'], scores])
|
|
results.T.tolist()
|
|
# %%
|
|
def get_embed_cache_file_search_path(file_path):
|
|
return os.path.splitext(file_path)[0]+'.oclip_embeds.npz'
|
|
|
|
|
|
|
|
|
|
file_search_path = get_embed_cache_file_search_path(file_path)
|
|
force_score = False
|
|
llvec = None
|
|
if os.path.exists(file_search_path):
|
|
llvec = np.load(file_search_path)
|
|
frs = llvec['frame_numbers']
|
|
if set(np.unique(np.diff(frs))) != {1}:
|
|
force_score = True
|
|
llvec = None
|
|
|
|
|
|
if not os.path.exists(file_search_path) or force_score:
|
|
kwq.publish(kwq.TOPICS.enter_60_videos_embed_priority, file_path, {'push_to_db':False, 'frame_interval':1, 'force_score':force_score})
|
|
|
|
|
|
|
|
if llvec is None:
|
|
for i in range(120):
|
|
print('waiting')
|
|
if os.path.exists(file_search_path):
|
|
print('Found embedding path!')
|
|
llvec = np.load(file_search_path)
|
|
break
|
|
else:
|
|
time.sleep(1)
|
|
|
|
|
|
|
|
|
|
|