Download predict.py from dnnsdunca/DdroidAI: direct link, hf CLI and curl.
- Browser
- Download file 740 Bytes
-
https://huggingface.co/dnnsdunca/DdroidAI/resolve/main/predict.py
- Command line
-
hf download hf://dnnsdunca/DdroidAI/predict.py
-
curl -L -o predict.py https://huggingface.co/dnnsdunca/DdroidAI/resolve/main/predict.py
740 Bytes
| from transformers import AutoModelForSequenceClassification, AutoTokenizer | |
| import torch | |
| import json | |
| # Load configuration | |
| with open('../config/config.json') as f: | |
| config = json.load(f) | |
| # Load model and tokenizer | |
| model = AutoModelForSequenceClassification.from_pretrained('../model') | |
| tokenizer = AutoTokenizer.from_pretrained(config['model_name']) | |
| def predict(text): | |
| inputs = tokenizer(text, return_tensors="pt", padding="max_length", truncation=True) | |
| with torch.no_grad(): | |
| outputs = model(**inputs) | |
| logits = outputs.logits | |
| prediction = torch.argmax(logits, dim=-1) | |
| return prediction.item() | |
| # Example usage | |
| text = "Example text for prediction" | |
| prediction = predict(text) | |
| print(f"Prediction: {prediction}") | |