|
| 1 | +--- |
| 2 | +title: Greenify | Localized community-driven greenification/plantation solution with AI |
| 3 | +description: Greenify is a mobile application designed to encourage and facilitate sustainable practices by analyzing live image and building community via Perplexity Sonar API. |
| 4 | +sidebar_position: 6 |
| 5 | +keywords: [image processing, community, maps, expo, react native, flask, Perplexity, sonar] |
| 6 | +--- |
| 7 | + |
| 8 | +# Greenify |
| 9 | + |
| 10 | + |
| 11 | + |
| 12 | +The inspiration for Greenify stems from the growing need to address environmental challenges and promote sustainable living. With the rise of urbanization and technology, we wanted to create a platform that merges innovation with eco-consciousness. Greenify aims to empower individuals and communities to take actionable steps toward a greener future by leveraging technology to make sustainability accessible and engaging. |
| 13 | + |
| 14 | +## Features |
| 15 | + |
| 16 | +Greenify is a mobile application designed to encourage and facilitate sustainable practices. It provides users with tools and resources to: |
| 17 | + |
| 18 | +- Participate in community-driven eco-friendly challenges and initiatives. |
| 19 | +- Access a curated library of tips, guides, and resources for sustainable living. |
| 20 | +- Connect with like-minded individuals through a community platform to share ideas and inspire action. |
| 21 | + |
| 22 | +The app is designed to be user-friendly, visually appealing, and impactful, making it easier for users to integrate sustainability into their daily lives. |
| 23 | + |
| 24 | +## Prerequisites |
| 25 | + |
| 26 | +- NodeJS 20.19.4 or later |
| 27 | +- Python 3.10.0 or later |
| 28 | +- Perplexity API key for Sonar integration |
| 29 | +- Expo (SDK version 51 or later) ([Setup guide](https://docs.expo.dev/)) |
| 30 | +- Android SDK/studio set up for local build or simulator run ([Setup guide](https://developer.android.com/about/versions/14/setup-sdk)) |
| 31 | +- Xcode installed if using Mac and for simulator run ([Setup guide](https://developer.apple.com/documentation/safari-developer-tools/installing-xcode-and-simulators)) |
| 32 | +- An Android/iPhone device for image capture with camera |
| 33 | + |
| 34 | +## Installation |
| 35 | + |
| 36 | +This is an [Expo](https://expo.dev) project created with [`create-expo-app`](https://www.npmjs.com/package/create-expo-app). Also there is a ```/service``` folder in the root directory of the project which contains the Flask API for communicating between frontend and Perplexity API. |
| 37 | + |
| 38 | +1. Install dependencies |
| 39 | + |
| 40 | + ```bash |
| 41 | + npm install |
| 42 | + ``` |
| 43 | + |
| 44 | +2. Start the app |
| 45 | + |
| 46 | + ```bash |
| 47 | + npx expo start |
| 48 | + ``` |
| 49 | + |
| 50 | +In the output, you'll find options to open the app in a |
| 51 | + |
| 52 | +- [development build](https://docs.expo.dev/develop/development-builds/introduction/) |
| 53 | +- [Android emulator](https://docs.expo.dev/workflow/android-studio-emulator/) |
| 54 | +- [iOS simulator](https://docs.expo.dev/workflow/ios-simulator/) |
| 55 | +- [Expo Go](https://expo.dev/go), a limited sandbox for trying out app development with Expo |
| 56 | + |
| 57 | +3. In another terminal navigate to ```/service``` folder and install dependencies |
| 58 | +```bash |
| 59 | +pip install -r requirements.txt |
| 60 | +``` |
| 61 | +4. Set ```PPLX_API_KEY``` in ```.env``` file inside the ```/service``` folder (create ```.env``` file if doesn't exist) |
| 62 | +4. Run Flask app |
| 63 | +```bash |
| 64 | +python app.py |
| 65 | +``` |
| 66 | +5. To open app in mobile |
| 67 | +##### Option 1 |
| 68 | +* Install Expo Go app from Play Store or App Store |
| 69 | +* Scan the QR code shown in the terminal |
| 70 | + |
| 71 | +##### Option 2 |
| 72 | +Open web browser in your smartphone and navigate to the URL shown in the console. |
| 73 | + |
| 74 | +## Abstract Data Flow Diagram |
| 75 | + |
| 76 | + |
| 77 | + |
| 78 | +## Usage |
| 79 | + |
| 80 | +After running the app in your own setup or through the hosted URL, the following steps can be followed: |
| 81 | + |
| 82 | +### First Step: Greenification |
| 83 | + |
| 84 | +| | | |
| 85 | +|------|-------------| |
| 86 | +|  | <ul><li>The user opens the app, which requests permission to capture a photo and access the user's location.</li><li>The user takes a photo of their space (e.g., a balcony), and the app automatically captures their coordinates (latitude, longitude, and altitude).</li><li>The image is sent to the Perplexity <code>sonar-pro</code> model to analyze the environment (e.g., balcony, roadside), sunlight exposure, and available space for plants.</li><li>The resulting analysis and user coordinates are sent to the Perplexity <code>sonar-deep-research</code> model to get real-time weather information, assess plant growth suitability, and receive up to five plant suggestions.</li><li>The API returns an analysis of which plants are suitable based on the location type, sunlight, and whether it's an indoor or outdoor space.</li><li>The API also provides a list of suitable plants based on sunlight and average weather conditions for the location.</li><li>Finally, the user can share these plant suggestions with other users in the same locality.</li></ul> | |
| 87 | + |
| 88 | +### Second Step: Community Building |
| 89 | + |
| 90 | +| | | |
| 91 | +|-------------|------| |
| 92 | +| <ul><li>The community screen displays nearby users and the plant suggestions they received from the photos they uploaded.</li><li>The user clicks the “Start Matching” button to get AI-suggested matches with other users based on similar interests, plant suggestions, and the potential for sharing resources.</li><li>The API suggests community groups for matched users based on shared interests and recommended plants.</li><li>Each community group shows the matched users and an explanation for why they were matched.</li><li>The app also explains how the community can positively impact the local ecosystem and promote economic growth.</li></ul> |  | |
| 93 | + |
| 94 | +## Code Explanation |
| 95 | + |
| 96 | +Greenify was built using the [Expo](https://expo.dev) framework, which allowed us to create a cross-platform application for Android, iOS, and the web. Key technologies and tools used include: |
| 97 | + |
| 98 | +- **Frontend**: React Native with Expo for building the user interface and ensuring a seamless user experience. |
| 99 | +- **Backend**: A Python-based service using Flask to handle data processing and API endpoints. |
| 100 | +- **Perplexity AI**: Using Perplexity AI's sonar-pro and sonar-deep-research models to classify image, plant suggestions based on image and coordinates by realtime research, creating a community by matching users of similar plant suggestions |
| 101 | +- **Design**: Using React Native UI Kitten for custom themes and assets, including fonts and icons, to create a visually cohesive and engaging interface. |
| 102 | +- **File-based routing**: Leveraging Expo's file-based routing system for intuitive navigation. |
| 103 | +- **Community features**: Implemented using React Native components and hooks for real-time interaction. |
| 104 | + |
| 105 | +** Pydantic models ** |
| 106 | +```python |
| 107 | +from pydantic import BaseModel, Field |
| 108 | + |
| 109 | + |
| 110 | +class Plant(BaseModel): |
| 111 | + name: str |
| 112 | + image: str = Field(description="Image URL of the plant") |
| 113 | + description: str = Field(description="Description of the plant") |
| 114 | + care_instructions: str = Field(description="Care instructions for the plant") |
| 115 | + care_tips: str = Field(description="Care tips for the plant") |
| 116 | + AR_model: str = Field(description="AR model URL for the plant") |
| 117 | + |
| 118 | + |
| 119 | +class Answer1(BaseModel): |
| 120 | + description: str |
| 121 | + |
| 122 | +class Answer2(BaseModel): |
| 123 | + plants: list[Plant] |
| 124 | + |
| 125 | + |
| 126 | +class Benefit(BaseModel): |
| 127 | + type: str = Field(description="Type of the environmental benefit") |
| 128 | + amount: str = Field(description="How much percentage of improvement") |
| 129 | + direction: bool = Field(description="True means increasing, False means decreasing") |
| 130 | + |
| 131 | + |
| 132 | +class Group(BaseModel): |
| 133 | + users: list[str] = Field( |
| 134 | + description="List at least 2 or more users with similar plant suggestions and how they can combine same job in term of place, activities and plantation" |
| 135 | + ) |
| 136 | + description: list[str] = Field( |
| 137 | + description="Short description of how these people match with each other" |
| 138 | + ) |
| 139 | + benefits: list[Benefit] = Field( |
| 140 | + description="How this combination helps benefit the environment with parameter, percentage value" |
| 141 | + ) |
| 142 | + |
| 143 | + |
| 144 | +class Community(BaseModel): |
| 145 | + match: list[Group] |
| 146 | +``` |
| 147 | + |
| 148 | +** Image Analysis and Insights about the captured image using sonar-pro and structured JSON output ** |
| 149 | +```python |
| 150 | +payload = { |
| 151 | + "model": "sonar-pro", |
| 152 | + "messages": [ |
| 153 | + { |
| 154 | + "role": "user", |
| 155 | + "content": [ |
| 156 | + { |
| 157 | + "type": "text", |
| 158 | + "text": f"Analyze this image and return short description of the place with respect to suitability of plant growth ", |
| 159 | + }, |
| 160 | + {"type": "image_url", "image_url": {"url": image}}, |
| 161 | + ], |
| 162 | + }, |
| 163 | + ], |
| 164 | + "stream": False, |
| 165 | + "response_format": { |
| 166 | + "type": "json_schema", |
| 167 | + "json_schema": {"schema": Answer1.model_json_schema()}, |
| 168 | + }, |
| 169 | +} |
| 170 | +``` |
| 171 | + |
| 172 | +** Matching people with similar plant suggestions and interests and create a matching community using sonar-deep-research ** |
| 173 | +```python |
| 174 | +payload_research = { |
| 175 | + "model": "sonar-deep-research", |
| 176 | + "messages": [ |
| 177 | + { |
| 178 | + "role": "system", |
| 179 | + "content": "You are a plant growth expert. You are given a description of a place where an user want to grow some plants. You are also given latitude, longitude and altitude of the user. Your task is to suggest at most 5 plant that can be grown by the user in that particular place according to average weather.", |
| 180 | + }, |
| 181 | + { |
| 182 | + "role": "user", |
| 183 | + "content": f"I am standing in a place having coordinates [{lat}, {lng}] and altitude {alt}]. The place can be described as follows: {answer1}" |
| 184 | + "Suggest at most five suitable plants that can be grown here.", |
| 185 | + }, |
| 186 | + ], |
| 187 | + "stream": False, |
| 188 | + "response_format": { |
| 189 | + "type": "json_schema", |
| 190 | + "json_schema": {"schema": Answer2.model_json_schema()}, |
| 191 | + }, |
| 192 | +} |
| 193 | +``` |
| 194 | + |
| 195 | + |
| 196 | +## Links |
| 197 | + |
| 198 | +- [GitHub Repository](https://github.com/deepjyotipaulhere/greenify) |
| 199 | +- [Live Demo](https://greenify.expo.app) |
| 200 | + |
| 201 | + |
| 202 | +- Youtube Demo |
| 203 | + |
| 204 | +[](https://www.youtube.com/watch?v=IFP0EiHqd7Y) |
0 commit comments