test_model / model.py
embedingHF's picture
Upload folder using huggingface_hub
4225683 verified
from sentence_transformers import SentenceTransformer
import torch
class EmbeddingModel:
def __init__(self, model_name="embedingHF/Sentence_Transformer"):
# Aapka apna HF model ya koi bhi pre-trained
self.device = "cuda" if torch.cuda.is_available() else "cpu"
print(f"Loading model on {self.device}...")
self.model = SentenceTransformer(model_name, device=self.device)
print("Model loaded successfully!")
def get_embedding(self, text: str):
"""Convert text to vector embedding"""
embedding = self.model.encode(text, convert_to_tensor=True)
return embedding.cpu().numpy().tolist()
# Global instance (ek baar load hoga, baar baar nahi)
model_instance = EmbeddingModel()