π½ Maize Disease Detection
A deep learning model that can detect two common maize diseases from leaf images:
- Maize Streak Virus (MSV)
- Maize Lethal Necrosis (MLN)
π Try it out!
- Upload an image of a maize leaf
- The model will predict if the leaf is healthy or affected by MSV or MLN
- Get detailed confidence scores for each class
π Model Details
- Architecture: ResNet-style CNN
- Input size: 128x96 pixels
- Classes: Healthy, MSV, MLN
- Accuracy: 98%
π» API Usage
You can use this model in your applications via the Hugging Face Inference API:
import requests
API_URL = "https://api-inference.huggingface.co/models/YOUR_USERNAME/maize-disease-detection"
headers = {"Authorization": "Bearer YOUR_API_TOKEN"}
def query(filename):
with open(filename, "rb") as f:
data = f.read()
response = requests.post(API_URL, headers=headers, data=data)
return response.json()
π§ Next.js Integration
To use this model in a Next.js application:
- Create an API route in your Next.js app:
// pages/api/predict.ts
import type { NextApiRequest, NextApiResponse } from 'next'
export default async function handler(
req: NextApiRequest,
res: NextApiResponse
) {
if (req.method !== 'POST') {
return res.status(405).json({ message: 'Method not allowed' })
}
try {
const response = await fetch(
'https://api-inference.huggingface.co/models/YOUR_USERNAME/maize-disease-detection',
{
method: 'POST',
headers: {
'Authorization': `Bearer ${process.env.HUGGINGFACE_API_KEY}`,
'Content-Type': 'application/json',
},
body: JSON.stringify(req.body),
}
)
const data = await response.json()
res.status(200).json(data)
} catch (error) {
res.status(500).json({ message: 'Error processing request' })
}
}
- Create a component to use the API:
// components/DiseaseDetector.tsx
import { useState } from 'react'
export default function DiseaseDetector() {
const [file, setFile] = useState<File | null>(null)
const [prediction, setPrediction] = useState<any>(null)
const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault()
if (!file) return
const formData = new FormData()
formData.append('file', file)
try {
const response = await fetch('/api/predict', {
method: 'POST',
body: formData,
})
const data = await response.json()
setPrediction(data)
} catch (error) {
console.error('Error:', error)
}
}
return (
<div>
<form onSubmit={handleSubmit}>
<input
type="file"
accept="image/*"
onChange={(e) => setFile(e.target.files?.[0] || null)}
/>
<button type="submit">Analyze</button>
</form>
{prediction && (
<div>
<h3>Results:</h3>
<pre>{JSON.stringify(prediction, null, 2)}</pre>
</div>
)}
</div>
)
}
π License
MIT License
π Acknowledgments
- Model trained on the Nelson Mandela African Institution of Science and Technology Maize dataset
- Special thanks to the researchers who contributed to the dataset
Inference Providers NEW
This model isn't deployed by any Inference Provider. π Ask for provider support