Spaces:
Runtime error
Runtime error
Download scripts/predict.py from ragkasi/FakeNewsDetector: direct link, hf CLI and curl.
- Browser
- Download file 534 Bytes
-
https://huggingface.co/spaces/ragkasi/FakeNewsDetector/resolve/main/scripts/predict.py
- Command line
-
hf download hf://spaces/ragkasi/FakeNewsDetector/scripts/predict.py
-
curl -L -o predict.py https://huggingface.co/spaces/ragkasi/FakeNewsDetector/resolve/main/scripts/predict.py
534 Bytes
| from transformers import pipeline | |
| # Load the classifier | |
| classifier = pipeline("text-classification", model="models/bert-liar-fake-news", tokenizer="bert-base-uncased") | |
| # Define the predict function | |
| def predict(text): | |
| result = classifier(text) | |
| label = result[0]['label'] | |
| score = result[0]['score'] | |
| return label, score | |
| # Example usage | |
| if __name__ == "__main__": | |
| text = input("Enter a statement to evaluate:\n") | |
| label, score = predict(text) | |
| print(f"Prediction: {label} (Confidence: {score:.2f})") |