"""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, )