Download 19/classifier.py from dejanseo/chrome_models: direct link, hf CLI and curl.
- Browser
- Download file 897 Bytes
-
https://huggingface.co/dejanseo/chrome_models/resolve/refs%2Fpr%2F13/19/classifier.py
- Command line
-
hf download hf://dejanseo/chrome_models@refs/pr/13/19/classifier.py
-
curl -L -o classifier.py https://huggingface.co/dejanseo/chrome_models/resolve/refs%2Fpr%2F13/19/classifier.py
897 Bytes
| import json | |
| import re | |
| # Load model JSON | |
| with open("en.json", "r") as f: | |
| model_data = json.load(f) | |
| # Define regex patterns | |
| patterns = { | |
| "phone": r"\b\d{3}[-.\s]?\d{3}[-.\s]?\d{4}\b", | |
| "url": r"https?://\S+|www\.\S+", | |
| "email": r"\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b" | |
| } | |
| # Simulate entity classification | |
| def classify_text(text): | |
| annotations = [] | |
| for entity, pattern in patterns.items(): | |
| matches = re.findall(pattern, text) | |
| for match in matches: | |
| annotations.append({"token": match, "type": entity, "confidence_score": 0.9}) | |
| return {"annotations": annotations} | |
| # Test classification | |
| test_text = "Hello world this is Call 123-456-7890 or visit www.example.com or email test@example.com soe other text." | |
| result = classify_text(test_text) | |
| print("Classification Result:", json.dumps(result, indent=2)) | |