--- title: Soil Classification Backend emoji: ๐ŸŒฑ colorFrom: green colorTo: yellow sdk: docker app_port: 7860 pinned: false license: mit tags: - soil-classification - cnn - fastapi - agriculture - tensorflow - crop-recommendation short_description: Classify soil types from images and get crop recommendations --- # ๐ŸŒฑ Soil Classification Backend AI-powered **soil image classifier** built with **FastAPI + TensorFlow**. Upload a photo of soil and instantly receive: - ๐Ÿท๏ธ **Soil type** โ€” one of **Black ยท Clayey ยท Loamy ยท Red ยท Sandy** - ๐ŸŒพ **Crop recommendations** โ€” sourced from 8 000+ soil-to-crop mappings - ๐ŸŒ **Multilingual explanations** โ€” English, Hindi, and Odia --- ## ๐Ÿ”Œ API ### `POST /api/classify` **Request** ```json { "imageBase64": "data:image/jpeg;base64,...", "language": "English" } ``` **Response** ```json { "soilType": "Sandy", "explanation": "This soil appears to be Sandy soil...", "recommendedCrops": ["Barley", "Maize", "Millets"] } ``` ### `GET /` Health check โ€” returns model status and supported soil classes. --- ## ๐Ÿง  Model | | | |---|---| | **Architecture** | CNN (Convolutional Neural Network) | | **Framework** | TensorFlow / Keras 2.16 | | **Input** | 224 ร— 224 RGB image | | **Classes** | Black, Clayey, Loamy, Red, Sandy | --- ## ๐Ÿ› ๏ธ Stack | | | |---|---| | Web Framework | FastAPI | | ML | TensorFlow 2.16 (CPU) | | Image Processing | Pillow | | Data | pandas + CSV (8 000+ crop mappings) | | Server | Uvicorn | | Container | Docker | --- ## ๐Ÿ“‚ Files ``` โ”œโ”€โ”€ app.py # FastAPI app + CNN inference โ”œโ”€โ”€ Dockerfile # Docker build โ”œโ”€โ”€ requirements.txt # Python deps โ”œโ”€โ”€ model/ โ”‚ โ””โ”€โ”€ soil_model007.keras โ””โ”€โ”€ data/ โ””โ”€โ”€ data_core.csv # Soil โ†’ Crop mapping ``` --- ## ๐ŸŒ Languages Supported | Language | Code | |---|---| | English | `"English"` | | Hindi | `"Hindi"` | | Odia | `"Odia"` | ---

Made with โค๏ธ for Indian agriculture ยท NIELIT Internship