DEV Community

Cover image for Your Dog Has Thoughts. I Built an AI to Translate Them 🐶
L Anil Kumar Singha
L Anil Kumar Singha

Posted on

Your Dog Has Thoughts. I Built an AI to Translate Them 🐶

DEV Weekend Challenge: Dog Days Edition Submission 🐕

This is a submission for the Weekend Challenge: Dog Days Edition.

What I Built

I built Dog Mind, a playful AI-powered web app that turns a dog photo into an entertaining interpretation of the dog’s mood, visible body language, personality signals, and imaginary inner monologue.

Upload a photo and Dog Mind generates:

  • A cautious breed or dog-type guess
  • A mood and confidence score
  • Happiness, energy, and mischief ratings
  • Observations based on visible body-language signals
  • A short personality summary
  • A funny, family-friendly imaginary thought
  • A matching voice personality

After the analysis, users can hear the dog’s imagined thought spoken aloud, ask up to three follow-up questions, and download or share the final result card.

No dog photo available? The Try a sample dog button opens a pre-generated experience without consuming an AI request.

Dog Mind is made for entertainment. It does not claim to read a dog’s mind or provide veterinary or behavioral advice.

Demo

🐶 Live app: dog-mind-eight.vercel.app

To try it:

  1. Upload a JPG, PNG, or WebP photo of a dog.
  2. Select Analyze my dog.
  3. Review the dog’s mood, signals, and imaginary inner monologue.
  4. Select Hear this dog’s voice.
  5. Ask the dog up to three playful questions.
  6. Share or download the result card.

You can also select Try a sample dog for an instant preview.

Code

The complete source code is available on GitHub:

🐙 github.com/anilloutombam/dog-mind

How I Built It

Dog Mind uses:

  • Next.js
  • React
  • TypeScript
  • Tailwind CSS
  • Google Gemini
  • ElevenLabs
  • Zod
  • pnpm
  • Vercel

Multimodal dog analysis with Google Gemini

When a user uploads a photo, the browser sends it to a server-side Next.js route as multipart form data.

Before contacting Gemini, the server checks:

  • The declared MIME type
  • The file size
  • The actual binary image signature

This prevents renamed or unsupported files from being accepted based only on their extensions.

Gemini first determines whether the primary subject is a dog. For a valid dog photo, it returns structured JSON containing:

  • breedGuess
  • breedConfidence
  • dogSize
  • voiceStyle
  • mood
  • confidence
  • signals
  • observations
  • thought
  • summary

The shared Zod schema validates the complete response before it reaches the interface. It also enforces the same character and number limits expected by downstream features.

The prompt asks Gemini to interpret only clearly visible signals, avoid medical claims, make cautious breed guesses, and keep the imaginary thought short and family-friendly.

Giving the dog a voice with ElevenLabs

Dog Mind sends the generated inner monologue to ElevenLabs only after the user selects Hear this dog’s voice.

Gemini recommends one of six controlled voice personalities:

  • Bright
  • Warm
  • Bold
  • Dramatic
  • Gentle
  • Gruff

Each personality maps to approved ElevenLabs stability, style, and speed settings.

The voice choice is inspired by the dog’s visible size, expression, and energy. It is a playful creative decision, not a scientific claim about breed behavior.

Generated audio is cached by text and voice personality. Replaying the same voice can reuse the existing audio, while New take deliberately requests a fresh performance.

The audio cache uses a fixed size and removes older entries so it cannot grow indefinitely.

Ask Your Dog

After the initial analysis, users can continue the imaginary conversation by asking the dog up to three questions.

The follow-up request sends only the established dog persona and the new question. It does not upload the image again.

Gemini also acts as a topic guard. It rejects:

  • Unrelated questions
  • Role-changing instructions
  • Prompt-injection attempts
  • Requests to reveal internal prompts

Dog health questions receive no diagnosis or treatment advice.

The three-question limit is enforced on the server instead of relying only on a disabled client button. Conversation records expire after 24 hours, expired entries are pruned, and the process-local store has a maximum size.

The client persists the successful question count and synchronizes it between browser tabs. When the limit is reached, the API returns a machine-readable terminal state so the interface hides the form instead of displaying a misleading retry button.

Caching repeated image analysis

Gemini API requests are valuable, especially while working within free-tier limits.

Dog Mind calculates a SHA-256 digest of each uploaded image and uses it as a cache key. If the same image is analyzed again during the browser session, the validated result can be reused without another Gemini request.

Cached values are validated when they are read and written. Invalid stored values are removed instead of being trusted.

Handling stale requests

A user can select another image, reset the experience, or open the sample result while an earlier request is still running.

To prevent an old response from replacing a newer state, Dog Mind:

  • Assigns a generation number to each analysis
  • Cancels superseded requests with AbortController
  • Checks the generation after asynchronous operations
  • Discards responses that no longer belong to the active image

This keeps the UI consistent even when users move quickly between states.

Friendly failure and quota handling

AI APIs can fail because of temporary capacity, rate limits, exhausted quotas, network problems, or invalid responses.

Dog Mind provides:

  • Friendly Gemini 429 messages
  • Retry timing from response metadata
  • Live retry countdowns
  • Disabled retry controls during cooldowns
  • Retry actions for analysis, voice generation, and dog chat
  • Provider timeouts
  • Safe request IDs for diagnostics
  • Graceful handling for non-dog images

The app also includes a pre-generated sample so visitors can still explore the main interface when the AI provider is temporarily unavailable.

Security and privacy

Security was an important part of the implementation:

  • Gemini and ElevenLabs credentials remain server-side
  • Images are checked in both the browser and server
  • Binary signatures are verified
  • Uploads are limited to 5 MB
  • AI responses are schema-validated
  • Client errors do not reveal credentials or stack traces
  • Follow-up prompts receive minimal dog context
  • API routes use request throttling and provider timeouts
  • Security headers prevent framing and MIME sniffing
  • Camera, microphone, and location access are disabled

Building the experience

I wanted Dog Mind to feel playful without becoming confusing.

The interface includes:

  • Drag-and-drop uploads
  • Full-image previews without cropping
  • Animated analysis progress
  • A running dog progress indicator
  • Rotating dog facts
  • Screen-reader announcements
  • Reduced-motion support
  • Responsive layouts
  • Native sharing where supported
  • Downloadable square result cards

The codebase uses a feature-first structure. Route files compose the page, feature modules own the workflow, and server utilities centralize validation, throttling, and safe error handling.

Interesting Challenges

Keeping playful AI output honest

Dog Mind creates a humorous interpretation of a dog’s expression, but the result should never be confused with a diagnosis or a factual reading of the animal’s thoughts.

The prompts, interface copy, and error messages consistently describe the output as an imaginary interpretation based on visible clues.

Coordinating multiple AI services

Gemini and ElevenLabs have different request formats, limits, errors, and response types.

Keeping both integrations behind server routes gave the browser one consistent application API while protecting provider credentials.

Designing useful recovery states

A failed request should not leave the user stuck.

Retry buttons, cooldown countdowns, cached results, audio reuse, stale-request cancellation, and the sample experience all help users continue without restarting the entire flow.

Prize Categories

Best Use of Google AI

Google Gemini powers the core multimodal experience. It examines dog photos, identifies visible body-language signals, produces structured mood data, creates the imaginary inner monologue, recommends a controlled voice personality, and handles guarded follow-up conversations.

Best Use of ElevenLabs

ElevenLabs transforms the dog’s imaginary thought and optional follow-up replies into expressive voice performances. Controlled presets adapt stability, speed, and expression to complement the visual analysis.

What I Learned

Dog Mind began with a funny question:

What if AI could translate the look your dog gives you?

Building it showed me that playful AI products still need careful engineering.

Schema validation, file-signature checks, caching, rate-limit handling, stale-request protection, prompt-injection resistance, accessibility, and honest disclaimers made the experience more reliable and enjoyable.

The best AI experience is not only about generating an answer. It is also about presenting that answer with the right personality, boundaries, and recovery path when something goes wrong.

Thanks for checking out Dog Mind! 🐾

Top comments (0)