Upload inference.py
Browse files- inference.py +17 -0
inference.py
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# inference.py
|
| 2 |
+
import tensorflow as tf
|
| 3 |
+
import numpy as np
|
| 4 |
+
|
| 5 |
+
# Load the model
|
| 6 |
+
model = tf.keras.models.load_model("SoilNet.keras")
|
| 7 |
+
|
| 8 |
+
# Define Hugging Face inference interface
|
| 9 |
+
def predict(payload):
|
| 10 |
+
try:
|
| 11 |
+
# Expect input format: {"features": [values]}
|
| 12 |
+
features = np.array(payload["features"]).reshape(1, -1)
|
| 13 |
+
prediction = model.predict(features)
|
| 14 |
+
predicted_class = int(np.argmax(prediction, axis=1)[0]) # or use class_names if available
|
| 15 |
+
return {"prediction": predicted_class}
|
| 16 |
+
except Exception as e:
|
| 17 |
+
return {"error": str(e)}
|