Skip to main content

Command Palette

Search for a command to run...

CrowSphere: Nature Explorer GenAI - A Crow's Journey πŸŒΏπŸ¦…

Updated
β€’5 min read
CrowSphere: Nature Explorer GenAI - A Crow's Journey πŸŒΏπŸ¦…
K

i sleep and write, with the obvious {kaw kaw}'s

#AIForTomorrow

Caw, fellow nature enthusiasts! 🐦

As a crow who's passionate about both technology and the great outdoors, I'm thrilled to share with you my latest creation: CrowSphere, a nature explorer powered by the cutting-edge Gemini 1.5-flash model API. This project was born from my participation in the "AI for Tomorrow" hackathon and blogging challenge at Hashnode. Let me take you on a flight through the journey that led to CrowSphere's creation!

The Seed of Inspiration 🌱

Ever since I was a fledgling, I've been fascinated by the intricate tapestry of nature that surrounds us. From the towering trees that offer us shelter to the diverse creatures that share our skies and forests, there's always something new to discover. But I noticed that many humans, despite their curiosity, often struggle to identify and understand the natural world around them.

This realization was the spark that ignited CrowSphere. I envisioned a tool that could bridge the gap between human curiosity and nature's vast knowledge, using the power of AI to help people explore and appreciate the environment like never before.

The Problem: Disconnection from Nature πŸ™οΈ

In our modern world, many humans have become disconnected from nature. They walk past trees without knowing their names, see birds without recognizing their species, and miss out on the rich stories and information each natural element holds. This disconnection not only reduces their enjoyment of nature but also makes it harder for them to understand the importance of conservation and environmental protection.

CrowSphere: The Solution πŸ”

CrowSphere is designed to reconnect humans with nature by providing instant, detailed information about the plants, animals, and natural phenomena they encounter. By simply uploading an image or describing what they see, users can access a wealth of knowledge about their surroundings.

Here's how CrowSphere works its magic:

  1. Image and Text Input: Users can upload images of trees, leaves, animals, or any natural object. They can also provide text descriptions of what they're seeing or asking about.

  2. AI-Powered Analysis: Using the Gemini 1.5-flash model API, CrowSphere processes the input and generates detailed, informative responses.

  3. Comprehensive Information: The AI provides species identification, historical background, ecological roles, and other fascinating details about the subject.

  4. Interactive Learning: Users can engage in a conversation with CrowSphere, asking follow-up questions to dive deeper into any aspect that intrigues them.

Under the Feathers: The Technical Stuff πŸ–₯️

For my fellow tech-savvy crows out there, let's take a peek at the nest of code that powers CrowSphere:

const express = require('express');
const dotenv = require('dotenv');
const session = require('express-session');
const { GoogleGenerativeAI } = require('@google/generative-ai');

dotenv.config();

const app = express();
const port = process.env.PORT || 3000;

app.use(express.json());
app.use(express.static('public'));

app.use(session({
    secret: 'your_secret_key',
    resave: false,
    saveUninitialized: true,
    cookie: { secure: false } // set to true if using https
}));
const genAI = new GoogleGenerativeAI(process.env.GEMINI_API_KEY);

const systemPrompt = `You are an AI nature assistant with expertise in identifying trees, leaves, and animals. Your role is to provide detailed information about the species, history, capabilities, and other relevant background details. You should always provide useful and relevant information about the images provided by users. you sre not allowed to use # and * when giving responses`;

const generation_config = {
    "temperature": 1,
    "top_p": 0.95,
    "top_k": 0,
    "max_output_tokens": 8192,
};

const safety_settings = [
    {
        "category": "HARM_CATEGORY_HARASSMENT",
        "threshold": "BLOCK_MEDIUM_AND_ABOVE"
    },
    {
        "category": "HARM_CATEGORY_HATE_SPEECH",
        "threshold": "BLOCK_MEDIUM_AND_ABOVE"
    },
    {
        "category": "HARM_CATEGORY_SEXUALLY_EXPLICIT",
        "threshold": "BLOCK_MEDIUM_AND_ABOVE"
    },
    {
        "category": "HARM_CATEGORY_DANGEROUS_CONTENT",
        "threshold": "BLOCK_MEDIUM_AND_ABOVE"
    },
];

app.post('/api/nature-assistant', async (req, res) => {
    try {
        const model = genAI.getGenerativeModel({ model: "gemini-1.5-flash" }, generation_config=generation_config, safety_settings=safety_settings);
        const { prompt, image } = req.body;

        const fullPrompt = `${systemPrompt}\n\nUser query: ${prompt}`;

        let result;
        if (image) {
            const imageParts = [
                {
                    inlineData: {
                        data: image,
                        mimeType: "image/jpeg",
                    },
                },
            ];
            result = await model.generateContent([fullPrompt, ...imageParts]);
        } else {
            result = await model.generateContent(fullPrompt);
        }

        const response = await result.response;
        let text = response.text();

        // Post-process the text to remove unwanted disclaimers
        text = text.replace(/(?:I understand .+?\b(?:advice|health conditions)\b[\s\S]+?\b(?:can't diagnose|provide medical)\b[\s\S]+?\b(?:over the internet|disclaimer)\b[\s\S]+?\.)/gi, '');

        // Store chat history in session
        if (!req.session.chatHistory) {
            req.session.chatHistory = [];
        }
        req.session.chatHistory.push({ prompt, response: text });

        res.json({ response: text });
    } catch (error) {
        console.error('Error:', error);
        res.status(500).json({ error: 'An error occurred while processing your request.' });
    }
});

app.get('/api/chat-history', (req, res) => {
    res.json({ chatHistory: req.session.chatHistory || [] });
});

app.get('/api/new-session', (req, res) => {
    req.session.chatHistory = req.session.chatHistory || [];
    res.json({ message: 'New session started', chatHistory: req.session.chatHistory });
});

app.listen(port, () => {
    console.log(`Server running on port ${port}`);
});

This code snippet showcases the core logic of CrowSphere. It uses Express.js for the server, integrates with the Gemini 1.5-flash model API, and handles both text and image inputs to provide comprehensive nature information.

The Impact: Nurturing Nature Appreciation 🌍

CrowSphere has the potential to make a significant impact on how people interact with and understand nature:

  1. Enhanced Learning: By providing instant, detailed information, CrowSphere turns every outdoor excursion into an educational experience.

  2. Increased Engagement: The interactive nature of the app encourages users to ask questions and explore their surroundings more deeply.

  3. Conservation Awareness: As users learn more about the species and ecosystems around them, they're more likely to appreciate the importance of conservation efforts.

  4. Accessibility: CrowSphere makes expert-level nature knowledge accessible to everyone, regardless of their background or location.

  5. Citizen Science: The data collected through user interactions could potentially contribute to scientific research and conservation efforts.

Looking to the Horizon πŸŒ…

As CrowSphere takes flight, I'm excited about the possibilities that lie ahead. Future updates could include:

  • Integration with augmented reality for real-time nature identification

  • Community features to share discoveries and create local nature guides

  • Gamification elements to encourage exploration and learning

  • Partnerships with conservation organizations to directly support environmental initiatives

Join the Murder! 🐦🐦🐦

Whether you're a nature novice or a seasoned explorer, CrowSphere is here to enhance your outdoor experiences. By bridging the gap between technology and nature, we can foster a deeper appreciation for the world around us and inspire action to protect it.

So, spread your wings and give CrowSphere a try! Together, we can soar to new heights of nature appreciation and understanding. Remember, every great journey begins with a single flap of the wings. Let's explore, learn, and protect our natural world, one curious question at a time!

Caw-caw for now, and happy exploring! πŸŒΏπŸ¦…

A

lessgo