| # 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)} | |