import spaces from transformers import pipeline #@spaces.GPU(duration=60) def classify(tweet, event_model, hftoken, threshold): # event type prediction event_predictor = pipeline(task="text-classification", model=event_model, batch_size=512, token=hftoken, device="cpu") tokenizer_kwargs = {'padding': True, 'truncation': True, 'max_length': 512} results = {"text": None, "event": None, "score": None} prediction = event_predictor(tweet, **tokenizer_kwargs)[0] results["text"] = tweet if prediction["label"] != "none" and round(prediction["score"], 2) <= threshold: results["event"] = "none" results["score"] = prediction["score"] else: results["event"] = prediction["label"] results["score"] = prediction["score"] return results