Meet2304 commited on
Commit
d87f7c0
·
1 Parent(s): ca4908b

Load model from local directory instead of Hugging Face Hub

Browse files
Files changed (2) hide show
  1. app.py +6 -6
  2. requirements.txt +4 -4
app.py CHANGED
@@ -32,8 +32,8 @@ import gradio as gr
32
 
33
  # ========== CONFIGURATION ==========
34
 
35
- # Hugging Face model ID
36
- HF_MODEL_ID = os.getenv("HF_MODEL_ID", "Meet2304/convnextv2-cervical-cell-classification")
37
 
38
  # Class names
39
  CLASS_NAMES = [
@@ -58,16 +58,16 @@ DEVICE = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
58
 
59
  # ========== MODEL LOADING ==========
60
 
61
- print("Loading model from Hugging Face...")
62
- print(f"Model ID: {HF_MODEL_ID}")
63
  print(f"Device: {DEVICE}")
64
 
65
  # Load image processor
66
- processor = AutoImageProcessor.from_pretrained(HF_MODEL_ID)
67
  print("✓ Processor loaded")
68
 
69
  # Load model
70
- model = ConvNextV2ForImageClassification.from_pretrained(HF_MODEL_ID)
71
  model = model.to(DEVICE)
72
  model.eval()
73
  print("✓ Model loaded and set to evaluation mode")
 
32
 
33
  # ========== CONFIGURATION ==========
34
 
35
+ # Model directory (local path relative to this file)
36
+ MODEL_DIR = os.path.join(os.path.dirname(__file__), "convnextv2_cervical_v0.1")
37
 
38
  # Class names
39
  CLASS_NAMES = [
 
58
 
59
  # ========== MODEL LOADING ==========
60
 
61
+ print("Loading model from local directory...")
62
+ print(f"Model directory: {MODEL_DIR}")
63
  print(f"Device: {DEVICE}")
64
 
65
  # Load image processor
66
+ processor = AutoImageProcessor.from_pretrained(MODEL_DIR)
67
  print("✓ Processor loaded")
68
 
69
  # Load model
70
+ model = ConvNextV2ForImageClassification.from_pretrained(MODEL_DIR)
71
  model = model.to(DEVICE)
72
  model.eval()
73
  print("✓ Model loaded and set to evaluation mode")
requirements.txt CHANGED
@@ -1,8 +1,8 @@
1
  torch>=2.0.0
2
  torchvision>=0.15.0
3
  transformers>=4.30.0
4
- gradio==4.0.0
5
- opencv-python-headless==4.8.1.78
6
- numpy~=1.24.0
7
- Pillow>=10.0.0,<11.0.0
8
  grad-cam>=1.4.8
 
1
  torch>=2.0.0
2
  torchvision>=0.15.0
3
  transformers>=4.30.0
4
+ gradio>=4.0.0
5
+ opencv-python>=4.8.0
6
+ numpy>=1.24.0
7
+ Pillow>=10.0.0
8
  grad-cam>=1.4.8