Spaces:
Sleeping
Sleeping
Download app.py from ZZW45/image-classifier: direct link, hf CLI and curl.
- Browser
- Download file 1.03 kB
-
https://huggingface.co/spaces/ZZW45/image-classifier/resolve/main/app.py
- Command line
-
hf download hf://spaces/ZZW45/image-classifier/app.py
-
curl -L -o app.py https://huggingface.co/spaces/ZZW45/image-classifier/resolve/main/app.py
1.03 kB
| """Hugging Face Spaces entry point for the existing Gradio classifier.""" | |
| import os | |
| from pathlib import Path | |
| os.environ.setdefault("GRADIO_ANALYTICS_ENABLED", "False") | |
| os.environ.setdefault("GRADIO_TEMP_DIR", "/tmp/gradio") | |
| os.environ.setdefault("OMP_NUM_THREADS", "2") | |
| os.environ.setdefault("MKL_NUM_THREADS", "2") | |
| ZERO_GPU = os.getenv("SPACES_ZERO_GPU", "").lower() in {"1", "true", "yes"} | |
| prediction_decorator = None | |
| if ZERO_GPU: | |
| # ZeroGPU must patch CUDA before torch or the classifier is imported. | |
| import spaces | |
| prediction_decorator = spaces.GPU(duration=10) | |
| import torch | |
| from plant_classifier.gui import launch_app | |
| torch.set_num_threads(2) | |
| ROOT = Path(__file__).resolve().parent | |
| if __name__ == "__main__": | |
| launch_app( | |
| checkpoint_path=str(ROOT / "outputs/experiment/final/best.pt"), | |
| device="cuda" if ZERO_GPU else "cpu", | |
| host="0.0.0.0", | |
| port=7860, | |
| example_path=str(ROOT / "outputs/validation_example.png"), | |
| prediction_decorator=prediction_decorator, | |
| ) | |