File size: 1,033 Bytes
cc0465b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
"""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,
    )