realmanise commited on
Commit
4606f2a
·
verified ·
1 Parent(s): 8eec78f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -5
app.py CHANGED
@@ -1,5 +1,6 @@
1
  import os
2
-
 
3
  os.environ["CUDA_VISIBLE_DEVICES"] = "-1"
4
  os.environ["TF_ENABLE_ONEDNN_OPTS"] = "0"
5
 
@@ -9,14 +10,13 @@ import tensorflow as tf
9
  import keras
10
  import zipfile
11
  import json
12
- import spaces
13
 
14
  # 1. Stand-in function for your model's Lambda layer structure
15
  @keras.saving.register_keras_serializable(package="Custom")
16
  def preprocess_input(x):
17
  return x
18
 
19
- # 2. Helper function to scrub out the bad parameters from the inner json dictionary
20
  def strip_quantization_keys(config):
21
  if isinstance(config, dict):
22
  config.pop('quantization_config', None)
@@ -56,8 +56,6 @@ model_loaded = load_sanitized_model('garbage_classifier.keras')
56
 
57
  lookup = {0: "Cardboard", 1: "Glass", 2: "Metal", 3: "Paper", 4: "Plastic", 5: "Trash"}
58
 
59
- # 4. Wrap the inference function so ZeroGPU yields control correctly
60
- @spaces.GPU
61
  def predict_image(img):
62
  if img is None:
63
  return "No image provided"
 
1
  import os
2
+ # FORCE TensorFlow to completely ignore the GPU during model loading/startup.
3
+ # This prevents it from breaking the CUDA driver state before ZeroGPU wraps it.
4
  os.environ["CUDA_VISIBLE_DEVICES"] = "-1"
5
  os.environ["TF_ENABLE_ONEDNN_OPTS"] = "0"
6
 
 
10
  import keras
11
  import zipfile
12
  import json
 
13
 
14
  # 1. Stand-in function for your model's Lambda layer structure
15
  @keras.saving.register_keras_serializable(package="Custom")
16
  def preprocess_input(x):
17
  return x
18
 
19
+ # 2. Helper function to recursively scrub out the bad parameters from the inner json dictionary
20
  def strip_quantization_keys(config):
21
  if isinstance(config, dict):
22
  config.pop('quantization_config', None)
 
56
 
57
  lookup = {0: "Cardboard", 1: "Glass", 2: "Metal", 3: "Paper", 4: "Plastic", 5: "Trash"}
58
 
 
 
59
  def predict_image(img):
60
  if img is None:
61
  return "No image provided"