CoolFace
Modelpublic

LH-Tech-AI/CritiqueCore_v1

sourceHugging Facemitupdated 6mo agoView on Hugging Face
1likes
inference.py39 linesDownload Raw Back to root
1import torch2from transformers import AutoTokenizer, AutoModelForSequenceClassification3 4class CritiqueCoreInference:5    def __init__(self, model_path):6        self.device = torch.device("cuda" if torch.cuda.is_available() else "cpu")7        self.tokenizer = AutoTokenizer.from_pretrained(model_path)8        self.model = AutoModelForSequenceClassification.from_pretrained(model_path).to(self.device)9        self.model.eval()10 11    def analyze(self, text):12        inputs = self.tokenizer(13            text, 14            return_tensors="pt", 15            padding=True, 16            truncation=True, 17            max_length=12818        ).to(self.device)19 20        with torch.no_grad():21            outputs = self.model(**inputs)22            probs = torch.nn.functional.softmax(outputs.logits, dim=-1)23            conf, pred = torch.max(probs, dim=-1)24 25        result = "POSITIVE" if pred.item() == 1 else "NEGATIVE"26        return {27            "text": text,28            "label": result,29            "confidence": f"{conf.item() * 100:.2f}%"30        }31 32# Usage33if __name__ == "__main__":34    # Point this to your unzipped folder35    engine = CritiqueCoreInference("./CritiqueCore_v1_HF")36    37    sample = "The plot was a bit slow, but overall a great experience."38    prediction = engine.analyze(sample)39    print(f"Result: {prediction['label']} | Confidence: {prediction['confidence']}")