Spaces:
Sleeping
Sleeping
|
Download README.md from Ramasani/WebScrapper-AI: direct link, hf CLI and curl.
- Browser
- Download file 4.62 kB
-
https://huggingface.co/spaces/Ramasani/WebScrapper-AI/resolve/main/README.md
- Command line
-
hf download hf://spaces/Ramasani/WebScrapper-AI/README.md
-
curl -L -o README.md https://huggingface.co/spaces/Ramasani/WebScrapper-AI/resolve/main/README.md
4.62 kB
metadata
title: WebScrapper AI
emoji: π₯
colorFrom: indigo
colorTo: blue
sdk: docker
pinned: false
short_description: This is an ML based web scrapper
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
Web Scraper for Hugging Face Spaces
Efficient web scraper with ML-based content classification, optimized for Hugging Face Docker Spaces with 16GB RAM.
Features
- Memory-efficient Chromium: Single browser instance with page pooling, resource blocking
- SQLite Storage: WAL mode for concurrent access, automatic indexing
- ML Classification: Scikit-learn RandomForest for content categorization (news, blog, product, etc.)
- No LLMs/AI Models: Traditional ML only, minimal dependencies
- Async FastAPI: High-performance async API on port 7860
- Background Jobs: Queue-based scraping with progress tracking
Architecture
βββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ
β FastAPI ββββββΆβ Browser Pool ββββββΆβ SQLite DB β
β (port 7860) β β (Chromium) β β (WAL mode) β
βββββββββββββββββββ ββββββββββββββββββββ ββββββββββ¬βββββββββ
β
ββββββββββββββββββββ β
β ML Classifier ββββββββββββ
β (RandomForest) β
ββββββββββββββββββββ
Quick Start
Local Development
# Build
docker build -t web-scraper .
# Run
docker run -p 7860:7860 web-scraper
Hugging Face Spaces Deployment
- Create new Space with Docker SDK
- Push this repository to the Space
- Space automatically builds and deploys
API Endpoints
| Method | Endpoint | Description |
|---|---|---|
| GET | /health |
Health check |
| POST | /scrape |
Submit URLs for scraping |
| GET | /scrape/{job_id} |
Get job status/results |
| GET | /pages |
List scraped pages |
| GET | /pages/{id} |
Get page details |
| GET | /stats |
Database statistics |
| POST | /model/retrain |
Retrain ML model |
| POST | /model/predict |
Classify HTML content |
| POST | /db/vacuum |
Optimize database |
Example Usage
# Submit scraping job
curl -X POST http://localhost:7860/scrape \
-H "Content-Type: application/json" \
-d '{"urls": ["https://example.com", "https://news.ycombinator.com"]}'
# Check job status
curl http://localhost:7860/scrape/{job_id}
# List pages
curl http://localhost:7860/pages
# Get statistics
curl http://localhost:7860/stats
Configuration (Environment Variables)
| Variable | Default | Description |
|---|---|---|
SCRAPER_DB_PATH |
/tmp/scraper.db |
SQLite database path |
MAX_CONCURRENT_PAGES |
4 |
Max concurrent browser pages |
REQUEST_TIMEOUT |
15000 |
Page load timeout (ms) |
MAX_CONTENT_SIZE |
50000 |
Max HTML content size (chars) |
HEADLESS |
true |
Run Chromium headless |
BLOCK_RESOURCES |
true |
Block images/CSS/fonts |
MODEL_RETRAIN_THRESHOLD |
100 |
Samples before auto-retrain |
MODEL_PATH |
/tmp/scraper_model.joblib |
Model persistence path |
Memory Optimization
With 16GB RAM, the container uses ~2GB:
- Chromium: ~400MB (single instance, resource blocking)
- Python/Dependencies: ~500MB
- SQLite: ~100-500MB
- ML Model: ~100MB
- Buffer: ~500MB
Project Structure
web-scraper/
βββ Dockerfile
βββ requirements.txt
βββ config.py # Configuration management
βββ storage.py # SQLite operations
βββ scraper.py # Playwright browser pool
βββ model.py # ML classifier (scikit-learn)
βββ app.py # FastAPI application
βββ data/ # SQLite database (runtime)
ML Model
The classifier uses:
- Features: 18 HTML/DOM features (tag counts, link density, DOM depth, readability)
- Algorithm: RandomForestClassifier (100 estimators, balanced class weights)
- Categories: news, blog, product, documentation, forum, social, landing, ecommerce, article, other
- Auto-retrain: Triggers after 100 new labeled samples