File size: 588 Bytes
1a29ba4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# inference.py
import tensorflow as tf
import numpy as np

# Load the model
model = tf.keras.models.load_model("SoilNet.keras")

# Define Hugging Face inference interface
def predict(payload):
    try:
        # Expect input format: {"features": [values]}
        features = np.array(payload["features"]).reshape(1, -1)
        prediction = model.predict(features)
        predicted_class = int(np.argmax(prediction, axis=1)[0])  # or use class_names if available
        return {"prediction": predicted_class}
    except Exception as e:
        return {"error": str(e)}