Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -13,9 +13,10 @@ labels = ['Leggings', 'Jogger', 'Palazzo', 'Cargo', 'Dresspants', 'Chinos']
|
|
| 13 |
logging.info(f"Labels: {labels}")
|
| 14 |
|
| 15 |
# Define paths to the model files (all in the same directory as app.py)
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
|
|
|
| 19 |
|
| 20 |
# Check if all required files exist
|
| 21 |
for path in [model_path, config_path, preprocessor_path]:
|
|
@@ -25,12 +26,9 @@ for path in [model_path, config_path, preprocessor_path]:
|
|
| 25 |
else:
|
| 26 |
logging.info(f"Found file: {path}")
|
| 27 |
|
| 28 |
-
# Load the
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
# Initialize the model with the configuration
|
| 33 |
-
model = ViTForImageClassification.from_pretrained(".", config=config)
|
| 34 |
|
| 35 |
# Ensure the model is in evaluation mode
|
| 36 |
model.eval()
|
|
|
|
| 13 |
logging.info(f"Labels: {labels}")
|
| 14 |
|
| 15 |
# Define paths to the model files (all in the same directory as app.py)
|
| 16 |
+
model_dir = "." # Use current directory
|
| 17 |
+
model_path = os.path.join(model_dir, "model.safetensors")
|
| 18 |
+
config_path = os.path.join(model_dir, "config.json")
|
| 19 |
+
preprocessor_path = os.path.join(model_dir, "preprocessor_config.json")
|
| 20 |
|
| 21 |
# Check if all required files exist
|
| 22 |
for path in [model_path, config_path, preprocessor_path]:
|
|
|
|
| 26 |
else:
|
| 27 |
logging.info(f"Found file: {path}")
|
| 28 |
|
| 29 |
+
# Load the model and feature extractor using the local directory
|
| 30 |
+
feature_extractor = ViTFeatureExtractor.from_pretrained(model_dir)
|
| 31 |
+
model = ViTForImageClassification.from_pretrained(model_dir)
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
# Ensure the model is in evaluation mode
|
| 34 |
model.eval()
|