Meet2304 commited on
Commit
9c62e8c
·
1 Parent(s): f943f9f

Load model from local files instead of HF Hub

Browse files
Files changed (1) hide show
  1. app.py +8 -9
app.py CHANGED
@@ -32,9 +32,8 @@ import gradio as gr
32
 
33
  # ========== CONFIGURATION ==========
34
 
35
- # Hugging Face model ID and token
36
- HF_MODEL_ID = os.getenv("HF_MODEL_ID", "Meet2304/convnextv2-cervical-cell-classification")
37
- HF_TOKEN = os.getenv("HF_TOKEN")
38
 
39
  # Class names
40
  CLASS_NAMES = [
@@ -59,16 +58,16 @@ DEVICE = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
59
 
60
  # ========== MODEL LOADING ==========
61
 
62
- print("Loading model from Hugging Face...")
63
- print(f"Model ID: {HF_MODEL_ID}")
64
  print(f"Device: {DEVICE}")
65
 
66
- # Load image processor
67
- processor = AutoImageProcessor.from_pretrained(HF_MODEL_ID, token=HF_TOKEN)
68
  print("✓ Processor loaded")
69
 
70
- # Load model
71
- model = ConvNextV2ForImageClassification.from_pretrained(HF_MODEL_ID, token=HF_TOKEN)
72
  model = model.to(DEVICE)
73
  model.eval()
74
  print("✓ Model loaded and set to evaluation mode")
 
32
 
33
  # ========== CONFIGURATION ==========
34
 
35
+ # Model path (local files in the Space)
36
+ MODEL_PATH = os.path.dirname(os.path.abspath(__file__))
 
37
 
38
  # Class names
39
  CLASS_NAMES = [
 
58
 
59
  # ========== MODEL LOADING ==========
60
 
61
+ print("Loading model from local files...")
62
+ print(f"Model path: {MODEL_PATH}")
63
  print(f"Device: {DEVICE}")
64
 
65
+ # Load image processor from local files
66
+ processor = AutoImageProcessor.from_pretrained(MODEL_PATH)
67
  print("✓ Processor loaded")
68
 
69
+ # Load model from local files
70
+ model = ConvNextV2ForImageClassification.from_pretrained(MODEL_PATH)
71
  model = model.to(DEVICE)
72
  model.eval()
73
  print("✓ Model loaded and set to evaluation mode")