This is a full-stack chat application that uses AI to analyze and describe images. Users can upload an image or send text prompts, and the application returns a detailed description along with relevant meta tags.
- Image Analysis: Upload images to receive AI-generated descriptions and keyword tags.
- Persistent Chat: Conversation history, including images, is stored in a PostgreSQL database and persists across browser sessions using a unique session ID.
- Full Stack Architecture: Built with a Next.js backend that handles database operations and communication with the AI service.
- Framework: Next.js 15 (App Router)
- Language: TypeScript
- Styling: Tailwind CSS
- Database: Supabase (PostgreSQL)
- ORM: Prisma
- AI Service: Pollinations AI (Proxy for OpenAI/Vision models)
-
Clone the repository.
-
Install dependencies:
npm install
-
Set up your environment variables in
.env(requires aDATABASE_URLfrom Supabase and the hugging face api token, you can also replace it with some other api token of your prefered model). You can also check the.env.examplefile for reference -
Sync the database schema:
npx prisma db push. -
Run the development server:
npm run dev.
You can verify the API is working without using the frontend by running these commands in your terminal.
- Test Image Analysis
Create a file named test-payload.json containing a test session ID and a tiny Base64 image (a red dot):
{
"sessionId": "curl-test-session-1",
"message": "What color is this?",
"imageBase64": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg=="
}Run the curl command to send this file to your local API:
curl -X POST http://localhost:3000/api/chat \
-H "Content-Type: application/json" \
-d @test-payload.json
Expected Output: The AI should reply identifying the image as a "red dot" or "red square".
- Verify Chat History (GET)
Check if the database successfully saved your conversation by retrieving the history for that session:
curl "http://localhost:3000/api/chat?sessionId=curl-test-session-1"Expected Output: A JSON array [...] containing the user message and the AI's response from the previous test.