Spaces:
Running
Running
Load model from local files instead of HF Hub
Browse files
app.py
CHANGED
|
@@ -32,9 +32,8 @@ import gradio as gr
|
|
| 32 |
|
| 33 |
# ========== CONFIGURATION ==========
|
| 34 |
|
| 35 |
-
#
|
| 36 |
-
|
| 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
|
| 63 |
-
print(f"Model
|
| 64 |
print(f"Device: {DEVICE}")
|
| 65 |
|
| 66 |
-
# Load image processor
|
| 67 |
-
processor = AutoImageProcessor.from_pretrained(
|
| 68 |
print("✓ Processor loaded")
|
| 69 |
|
| 70 |
-
# Load model
|
| 71 |
-
model = ConvNextV2ForImageClassification.from_pretrained(
|
| 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")
|