import streamlit as st import numpy as np from html import escape import torch from transformers import RobertaModel, AutoTokenizer tokenizer = AutoTokenizer.from_pretrained('SajjadAyoubi/clip-fa-text') text_encoder = RobertaModel.from_pretrained('SajjadAyoubi/clip-fa-text').eval() image_embeddings = torch.load('embedding.pt') links = np.load('data.npy', allow_pickle=True) @st.experimental_memo def image_search(query, top_k=10): with torch.no_grad(): text_embedding = text_encoder(**tokenizer(query, return_tensors='pt')).pooler_output _, indices = torch.cosine_similarity(image_embeddings, text_embedding).sort(descending=True) return [links[i] for i in indices[:top_k]] def get_html(url_list): html = "