A modern web application that uses AI to identify plants from uploaded images. Built with Next.js 14 and powered by Google's Gemini 1.5 Flash model.
- Instant Plant Identification: Upload any plant image and get detailed information
- AI-Powered Analysis: Uses Google Gemini 1.5 Flash for accurate plant recognition
- Modern UI: Clean, responsive interface built with Tailwind CSS
- Secure API Handling: Server-side API routes protect sensitive keys
- Error Handling: Comprehensive error handling and loading states
- Mobile Responsive: Works seamlessly on all device sizes
Upload an image of any plant and get:
- Common and scientific names
- Care instructions
- Interesting botanical facts
- Growing conditions
- And much more!
- Framework: Next.js 14 (App Router)
- AI Model: Google Gemini 1.5 Flash
- Styling: Tailwind CSS
- Language: JavaScript/JSX
- API: Google Generative AI SDK
Before you begin, ensure you have:
- Node.js 18.0 or higher
- npm or yarn package manager
- Google AI Studio API key
-
Clone the repository
git clone https://github.com/rabibsust/plant-identifier.git cd plant-identifier -
Install dependencies
npm install # or yarn install -
Set up environment variables Create a
.env.localfile in the root directory:GEMINI_API_KEY=your_google_ai_studio_api_key_here
-
Get your Google AI Studio API key
- Visit Google AI Studio
- Sign in with your Google account
- Click "Create API key"
- Copy the generated key to your
.env.localfile
-
Run the development server
npm run dev # or yarn dev -
Open your browser Navigate to http://localhost:3000
plant-identifier/
βββ app/
β βββ api/
β β βββ identify-plant/
β β βββ route.js # API route for plant identification
β βββ globals.css # Global styles
β βββ layout.js # Root layout
β βββ page.js # Main page component
βββ .env.local # Environment variables (create this)
βββ .gitignore
βββ next.config.js # Next.js configuration
βββ package.json
βββ README.md
βββ tailwind.config.js # Tailwind CSS configuration
The application uses Google's Gemini 1.5 Flash model for plant identification. The API key is securely handled on the server-side through Next.js API routes.
| Variable | Description | Required |
|---|---|---|
GEMINI_API_KEY |
Your Google AI Studio API key | Yes |
- Upload Image: Click the file input to select a plant image
- Identify: Click the "Identify Plant" button
- View Results: Get detailed information about the identified plant
- JPEG
- PNG
- WebP
- GIF
- Image Upload: User selects an image file
- Frontend Processing: Image is converted to base64 format
- API Call: Secure POST request to
/api/identify-plant - AI Analysis: Google Gemini 1.5 Flash analyzes the image
- Response: Detailed plant information is returned and displayed
- API keys are stored server-side only
- Input validation for image uploads
- Error handling for malformed requests
- Secure API route implementation
"API key not configured" error
- Ensure
.env.localfile is in the root directory - Verify your API key is correct
- Restart the development server after adding environment variables
"Failed to identify plant" error
- Check your internet connection
- Verify the uploaded image is a valid format
- Ensure your API key has sufficient quota
Model deprecation errors
- The app uses
gemini-1.5-flash(current model) - If you encounter deprecation errors, check the code uses the latest model
Enable detailed logging by checking the browser console and server terminal for:
- API request/response details
- Error messages and stack traces
- Network request information
- Push your code to GitHub
- Connect your repository to Vercel
- Add
GEMINI_API_KEYto environment variables in Vercel dashboard - Deploy!
The app can be deployed to any platform that supports Next.js:
- Netlify
- Railway
- Heroku
- Docker
Remember to set the GEMINI_API_KEY environment variable in your deployment platform.
- Modify
app/globals.cssfor global styles - Update Tailwind classes in components
- Customize the color scheme in
tailwind.config.js
- Edit the prompt in
app/api/identify-plant/route.js - Adjust the model parameters for different responses
- Add additional context or formatting instructions
- Plant identification history
- Favorite plants feature
- Detailed care guides
- Plant health assessment
- Social sharing capabilities
- Multiple language support
- Plant disease identification
- Offline mode with cached results
This project was built using AI assistance. Here's the prompt used:
Create a plant identifier website in next js 14 using the app directory and no src folder. As soon as the website loads, the user should be given the option to upload an image of a plant. And the website should show the name and other improtant informations on the screen. As for identifying the plants, you can use the Google gemini API. Also make sure to style the website in a modern way using tailwind css
Key Requirements:
Next.js 14 with App Router (no src folder)
Google Gemini for plant identification
Secure API routes for handling API keys
Modern UI with Tailwind CSS
Image upload with real-time results
Comprehensive error handling
Environment:
GEMINI_API_KEY=your_api_key_here
Features:
Upload plant images
AI-powered identification
Display plant names, care instructions, and facts
Mobile-responsive design
Professional error handling
Feel free to use this as a template for similar projects!
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Google AI Studio for providing the Gemini API
- Next.js team for the excellent framework
- Tailwind CSS for the utility-first CSS framework
- The open-source community for inspiration and support
Rabib Ahmad - @rabibsust
Project Link: https://github.com/rabibsust/plant-identifier
β If you found this project helpful, please give it a star!