├── awsvision ├── demo.jpg ├── face.jpg ├── ppe.jpg ├── nudity.jpg ├── objimg.jpeg ├── requirements.txt ├── __pycache__ │ └── utility.cpython-38.pyc ├── markdowns │ ├── newabout.md │ └── welcome.md ├── style.css ├── utility.py └── app.py ├── README.md └── LICENSE /awsvision/demo.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AIAnytime/AWSVision/main/awsvision/demo.jpg -------------------------------------------------------------------------------- /awsvision/face.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AIAnytime/AWSVision/main/awsvision/face.jpg -------------------------------------------------------------------------------- /awsvision/ppe.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AIAnytime/AWSVision/main/awsvision/ppe.jpg -------------------------------------------------------------------------------- /awsvision/nudity.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AIAnytime/AWSVision/main/awsvision/nudity.jpg -------------------------------------------------------------------------------- /awsvision/objimg.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AIAnytime/AWSVision/main/awsvision/objimg.jpeg -------------------------------------------------------------------------------- /awsvision/requirements.txt: -------------------------------------------------------------------------------- 1 | Pillow == 7.0.0 2 | altair == 4.1.0 3 | boto3 == 1.16.63 4 | numpy == 1.19.5 5 | streamlit == 0.79.0 6 | -------------------------------------------------------------------------------- /awsvision/__pycache__/utility.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AIAnytime/AWSVision/main/awsvision/__pycache__/utility.cpython-38.pyc -------------------------------------------------------------------------------- /awsvision/markdowns/newabout.md: -------------------------------------------------------------------------------- 1 | # Little About Me :man: 2 | 3 | **I am an AI Engineer, content creator, and technopreneur, currently working on multiple fronts where Deep Learning and Computer Vision are mysterious, including understanding business needs, rethinking AI capacity, and research opportunities that leads to a better society.** 4 | 5 | 6 | 7 | 8 | ### Find me here :point_down: 9 | 10 | - **Sonu Kumar** :raised_hand: 11 | 12 | * _Email:_ **sonu1000raw@gmail.com** 13 | 14 | * _LinkedIn:_ **[Sonu Kumar](https://www.linkedin.com/in/sonucr7/)** 15 | 16 | * _GitHub:_ **[sonucr7](https://github.com/sonucr7)** 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /awsvision/style.css: -------------------------------------------------------------------------------- 1 | @import url('https://fonts.googleapis.com/css2?family=Montserrat:wght@100;200;300;400;500;600;700;800;900&display=swap'); 2 | 3 | 4 | #MainMenuButton{ 5 | background-color: #F08D2C; 6 | } 7 | .sidebar{ 8 | background-color: #31333F; 9 | } 10 | 11 | .sidebar-collapse-control{ 12 | background-color: #F08D2C; 13 | } 14 | 15 | .stButton>button { 16 | color: #ffffff; 17 | border-radius: 50px; 18 | padding: 10px 20px; 19 | background-color: #F08D2C; 20 | border: 2px solid #F08D2C; 21 | font-weight: 600; 22 | } 23 | 24 | .stButton>button:hover { 25 | color: #F08D2C; 26 | border-radius: 50px; 27 | padding: 10px 20px; 28 | background-color: transparent; 29 | border: 2px solid #F08D2C; 30 | font-weight: 600; 31 | } 32 | 33 | .stSelectbox>label{ 34 | color:#F08D2C !important; 35 | font-size: 16px; 36 | font-weight: 600; 37 | } 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Amazon-Rekognition-Services-App 2 | An application to show the capabilities of Amazon Rekognition and its several APIs built using Streamlit. 3 | 4 | Amazon Rekognition is Deep Learning based image and video analytics service by Amazon Web Services (AWS). It has tons of features that you can use for your business needs. If you want to develop robust and scalable Image or Video analytics solutions for your clients/needs, You can use the service of Amazon Rekognition with ease. If you want to find unsafe contents to flag them for CSAM detection, analyze human faces for automated employee attendance, detect PPEs for worker's safety, extraction of texts from images for marketing and survey, detect objects and scenes in images, etc, You can do all with the help of Amazon Rekognition. If there is a need for a Custom solution on custom data, It provides you the option of "Custom Labels" too that is fully equipped with automation. 5 | 6 | Find the live application here: 👉 http://3.137.179.35:8501/ (on EC2) 7 | 8 | See "Amazon Rekognition" here: 👉https://lnkd.in/ed7bDcp 9 | 10 | 11 | -------------------------------------------------------------------------------- /awsvision/markdowns/welcome.md: -------------------------------------------------------------------------------- 1 | # Amazon Rekognition Services App 2 | This application uses several APIs of Amazon Machine Learning service "**Amazon Rekognition** ". It shows the possibilities and capabilities of Amazon Rekognition for **Image and Video analysis in real-time on your browser.** 3 | 4 | Rekognition-1 5 | 6 | Currently, The application uses five different APIs of Amazon Rekognition as below: 7 | 8 | - **Object and Scene Detection**: Helps to detect labels in an Image. 9 | - **Image Moderation**: Find out Explicit, Nudes, or Sensitive contents in an Image. 10 | - **Facial Analysis**: Facial analysis like Gender, Age, Emotions, etc. 11 | - **Text Extraction in Image**: Extraction of texts in an Image. 12 | - **PPE Detection in Image**: Detect if a Human has wore PPE or not in an Image. 13 | 14 | The app is built using **Streamlit, Amazon Rekognition and ❤️**. For SDK, "boto3" has been used for Python 🐍. 15 | 16 | ## Next Step 17 | The application is under development and will be updated soon with a couple of more services like "Face Comparisons", and "Celebrity Recognition". Parallelly, We are also integrating "Video Analysis" too in the application. Wait for the update of the App soon.......... 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /awsvision/utility.py: -------------------------------------------------------------------------------- 1 | import base64 2 | from pathlib import Path 3 | import streamlit as st 4 | import altair as alt 5 | 6 | 7 | def streamlit_theme(): 8 | font = "IBM Plex Mono" 9 | primary_color = "#F63366" 10 | font_color = "#262730" 11 | grey_color = "#f0f2f6" 12 | base_size = 16 13 | lg_font = base_size * 1.25 14 | sm_font = base_size * 0.8 # st.table size 15 | xl_font = base_size * 1.75 # noqa 16 | 17 | config = { 18 | "config": { 19 | "arc": {"fill": primary_color}, 20 | "area": {"fill": primary_color}, 21 | "circle": {"fill": primary_color, "stroke": font_color, "strokeWidth": 0.5}, 22 | "line": {"stroke": primary_color}, 23 | "path": {"stroke": primary_color}, 24 | "point": {"stroke": primary_color}, 25 | "rect": {"fill": primary_color}, 26 | "shape": {"stroke": primary_color}, 27 | "symbol": {"fill": primary_color}, 28 | "title": { 29 | "font": font, 30 | "color": font_color, 31 | "fontSize": lg_font, 32 | "anchor": "start", 33 | }, 34 | "axis": { 35 | "titleFont": font, 36 | "titleColor": font_color, 37 | "titleFontSize": sm_font, 38 | "labelFont": font, 39 | "labelColor": font_color, 40 | "labelFontSize": sm_font, 41 | "gridColor": grey_color, 42 | "domainColor": font_color, 43 | "tickColor": "#fff", 44 | }, 45 | "header": { 46 | "labelFont": font, 47 | "titleFont": font, 48 | "labelFontSize": base_size, 49 | "titleFontSize": base_size, 50 | }, 51 | "legend": { 52 | "titleFont": font, 53 | "titleColor": font_color, 54 | "titleFontSize": sm_font, 55 | "labelFont": font, 56 | "labelColor": font_color, 57 | "labelFontSize": sm_font, 58 | }, 59 | "range": { 60 | "category": ["#f63366", "#fffd80", "#0068c9", "#ff2b2b", "#09ab3b"], 61 | "diverging": [ 62 | "#850018", 63 | "#cd1549", 64 | "#f6618d", 65 | "#fbafc4", 66 | "#f5f5f5", 67 | "#93c5fe", 68 | "#5091e6", 69 | "#1d5ebd", 70 | "#002f84", 71 | ], 72 | "heatmap": [ 73 | "#ffb5d4", 74 | "#ff97b8", 75 | "#ff7499", 76 | "#fc4c78", 77 | "#ec245f", 78 | "#d2004b", 79 | "#b10034", 80 | "#91001f", 81 | "#720008", 82 | ], 83 | "ramp": [ 84 | "#ffb5d4", 85 | "#ff97b8", 86 | "#ff7499", 87 | "#fc4c78", 88 | "#ec245f", 89 | "#d2004b", 90 | "#b10034", 91 | "#91001f", 92 | "#720008", 93 | ], 94 | "ordinal": [ 95 | "#ffb5d4", 96 | "#ff97b8", 97 | "#ff7499", 98 | "#fc4c78", 99 | "#ec245f", 100 | "#d2004b", 101 | "#b10034", 102 | "#91001f", 103 | "#720008", 104 | ], 105 | }, 106 | } 107 | } 108 | return config 109 | 110 | 111 | def streamlit_theme_alt(): 112 | font = "IBM Plex Mono" 113 | primary_color = "#F63366" 114 | font_color = "#262730" 115 | grey_color = "#f0f2f6" 116 | base_size = 16 117 | lg_font = base_size * 1.25 118 | sm_font = base_size * 0.8 # st.table size 119 | xl_font = base_size * 1.75 # noqa 120 | 121 | config = { 122 | "config": { 123 | "view": {"fill": grey_color}, 124 | "arc": {"fill": primary_color}, 125 | "area": {"fill": primary_color}, 126 | "circle": {"fill": primary_color, "stroke": font_color, "strokeWidth": 0.5}, 127 | "line": {"stroke": primary_color}, 128 | "path": {"stroke": primary_color}, 129 | "point": {"stroke": primary_color}, 130 | "rect": {"fill": primary_color}, 131 | "shape": {"stroke": primary_color}, 132 | "symbol": {"fill": primary_color}, 133 | "title": { 134 | "font": font, 135 | "color": font_color, 136 | "fontSize": lg_font, 137 | "anchor": "start", 138 | }, 139 | "axis": { 140 | "titleFont": font, 141 | "titleColor": font_color, 142 | "titleFontSize": sm_font, 143 | "labelFont": font, 144 | "labelColor": font_color, 145 | "labelFontSize": sm_font, 146 | "grid": True, 147 | "gridColor": "#fff", 148 | "gridOpacity": 1, 149 | "domain": False, 150 | # "domainColor": font_color, 151 | "tickColor": font_color, 152 | }, 153 | "header": { 154 | "labelFont": font, 155 | "titleFont": font, 156 | "labelFontSize": base_size, 157 | "titleFontSize": base_size, 158 | }, 159 | "legend": { 160 | "titleFont": font, 161 | "titleColor": font_color, 162 | "titleFontSize": sm_font, 163 | "labelFont": font, 164 | "labelColor": font_color, 165 | "labelFontSize": sm_font, 166 | }, 167 | "range": { 168 | "category": ["#f63366", "#fffd80", "#0068c9", "#ff2b2b", "#09ab3b"], 169 | "diverging": [ 170 | "#850018", 171 | "#cd1549", 172 | "#f6618d", 173 | "#fbafc4", 174 | "#f5f5f5", 175 | "#93c5fe", 176 | "#5091e6", 177 | "#1d5ebd", 178 | "#002f84", 179 | ], 180 | "heatmap": [ 181 | "#ffb5d4", 182 | "#ff97b8", 183 | "#ff7499", 184 | "#fc4c78", 185 | "#ec245f", 186 | "#d2004b", 187 | "#b10034", 188 | "#91001f", 189 | "#720008", 190 | ], 191 | "ramp": [ 192 | "#ffb5d4", 193 | "#ff97b8", 194 | "#ff7499", 195 | "#fc4c78", 196 | "#ec245f", 197 | "#d2004b", 198 | "#b10034", 199 | "#91001f", 200 | "#720008", 201 | ], 202 | "ordinal": [ 203 | "#ffb5d4", 204 | "#ff97b8", 205 | "#ff7499", 206 | "#fc4c78", 207 | "#ec245f", 208 | "#d2004b", 209 | "#b10034", 210 | "#91001f", 211 | "#720008", 212 | ], 213 | }, 214 | } 215 | } 216 | return config 217 | 218 | 219 | category_large = [ 220 | "#f63366", 221 | "#0068c9", 222 | "#fffd80", 223 | "#7c61b0", 224 | "#ffd37b", 225 | "#ae5897", 226 | "#ffa774", 227 | "#d44a7e", 228 | "#fd756d", 229 | ] 230 | 231 | alt.themes.register("streamlit", streamlit_theme) 232 | alt.themes.enable("streamlit") 233 | 234 | 235 | 236 | 237 | def img_to_bytes(img_path): 238 | img_bytes = Path(img_path).read_bytes() 239 | encoded = base64.b64encode(img_bytes).decode() 240 | return encoded 241 | 242 | 243 | @st.cache 244 | def read_markdown_file(markdown_file): 245 | return Path(markdown_file).read_text() 246 | 247 | 248 | 249 | 250 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /awsvision/app.py: -------------------------------------------------------------------------------- 1 | #--------------------------Import all pkgs and libraries------------ 2 | 3 | #Import all utils 4 | import os 5 | import sys 6 | import io 7 | import base64 8 | import uuid 9 | import re 10 | 11 | 12 | #import numpy for image computation 13 | import numpy as np 14 | 15 | #import Image from PIL for image loading 16 | from PIL import Image 17 | 18 | #AWS SDK for Python3 19 | import boto3 20 | #Import json for all json related stuffs 21 | import json 22 | 23 | #our main web framework "Streamlit" 24 | import streamlit as st 25 | 26 | #For streamlit designing and workaround 27 | from utility import ( 28 | img_to_bytes, 29 | read_markdown_file, 30 | ) 31 | 32 | #-----------------All Imports are Completed---------------------- 33 | 34 | #-----------Configuring AWS------------------------------------- 35 | 36 | DEFAULT_REGION = "us-east-2" 37 | AWS_ACCESS_KEY_ID = os.getenv("AWS_ACCESS_KEY_ID") 38 | AWS_SECRET_ACCESS_KEY = os.getenv("AWS_SECRET_ACCESS_KEY") 39 | AWS_DEFAULT_REGION = os.getenv("AWS_DEFAULT_REGION", DEFAULT_REGION) 40 | 41 | #----------Assigning AWS Service------------ 42 | client = boto3.client("rekognition",region_name=AWS_DEFAULT_REGION, 43 | aws_access_key_id=AWS_ACCESS_KEY_ID, 44 | aws_secret_access_key=AWS_SECRET_ACCESS_KEY) 45 | 46 | 47 | 48 | 49 | 50 | #Global variable 51 | OBJECT_DEMO_IMAGE = "objimg.jpeg" 52 | FACE_DEMO_IMAGE = "face.jpg" 53 | DEMO_IMAGE = "demo.jpg" 54 | PPE_DEMO_IMAGE = "ppe.jpg" 55 | NUDE_DEMO_IMAGE = "nudity.jpg" 56 | 57 | 58 | 59 | def local_css(file_name): 60 | with open(file_name) as f: 61 | st.markdown(f'', unsafe_allow_html=True) 62 | 63 | def remote_css(url): 64 | st.markdown(f'', unsafe_allow_html=True) 65 | 66 | local_css("style.css") 67 | remote_css('https://fonts.googleapis.com/icon?family=Material+Icons') 68 | 69 | 70 | 71 | 72 | #Download button function 73 | def download_button(object_to_download, download_filename, button_text): 74 | """ 75 | Generates a link to download the given object_to_download. 76 | Params: 77 | ------ 78 | object_to_download: The object to be downloaded. 79 | download_filename (str): filename and extension of file. e.g. my.json, 80 | some_txt_output.txt download_link_text (str): Text to display for download 81 | link. 82 | button_text (str): Text to display on download button (e.g. 'click here to download file') 83 | Returns: 84 | ------- 85 | (str): the anchor tag to download object_to_download 86 | Examples: 87 | -------- 88 | download_link(your_df, 'YOUR_DF.csv', 'Click to download data!') 89 | download_link(your_str, 'YOUR_STRING.txt', 'Click to download text!') 90 | """ 91 | object_to_download = json.dumps(object_to_download, ensure_ascii=True, indent=4) 92 | try: 93 | # some strings <-> bytes conversions necessary here 94 | b64 = base64.b64encode(object_to_download.encode()).decode() 95 | except AttributeError as e: 96 | b64 = base64.b64encode(object_to_download).decode() 97 | 98 | button_uuid = str(uuid.uuid4()).replace("-", "") 99 | button_id = re.sub("\d+", "", button_uuid) 100 | 101 | custom_css = f""" 102 | """ 125 | 126 | dl_link = ( 127 | custom_css 128 | + f'{button_text}

' 129 | ) 130 | 131 | return dl_link 132 | 133 | 134 | 135 | 136 | #function to convert an image to bytes array 137 | def pil_image_to_byte_array(image): 138 | imgByteArr = io.BytesIO() 139 | image.save(imgByteArr, "PNG") 140 | return imgByteArr.getvalue() 141 | 142 | 143 | #Function to perform the analysis 144 | @st.cache 145 | def process_image(image_bytes): 146 | response = client.detect_text(Image={"Bytes": image_bytes}) 147 | return response 148 | 149 | def object_detection(obj_img): 150 | response = client.detect_labels(Image={"Bytes": obj_img}) 151 | return response 152 | 153 | def face_analysis(face_img): 154 | response = client.detect_faces(Image={"Bytes": face_img}, Attributes=["ALL"]) 155 | return response 156 | 157 | 158 | def ppe_detection(ppe_image): 159 | response = client.detect_protective_equipment(Image={"Bytes": ppe_image}, 160 | SummarizationAttributes={'MinConfidence':80, 'RequiredEquipmentTypes': 161 | ['FACE_COVER', 'HAND_COVER', 'HEAD_COVER']}) 162 | return response 163 | 164 | def nude_detection(nude_img): 165 | response = client.detect_moderation_labels(Image={"Bytes": nude_img}) 166 | return response 167 | 168 | 169 | #main function 170 | def main(): 171 | menu = ["Home","Object and Scene Detection", 172 | "Image Moderation", 173 | "Facial Analysis", 174 | "Text in Image", 175 | "PPE Detection", 176 | "About Me"] 177 | choice = st.sidebar.selectbox("Menu", menu) 178 | if choice == "Home": 179 | about_md = read_markdown_file("markdowns/welcome.md") 180 | st.markdown(about_md, unsafe_allow_html=True) 181 | elif choice == "Object and Scene Detection": 182 | st.title("Detect objects and scenes in Image 🖼") 183 | object_file_buffer = st.file_uploader("Upload the image 👇", type = ["png", "jpg", "jpeg"]) 184 | if object_file_buffer is not None: 185 | object_image_bytes = pil_image_to_byte_array(Image.open(object_file_buffer)) 186 | object_image_array = np.array(Image.open(object_file_buffer)) 187 | else: 188 | object_image_bytes = open(OBJECT_DEMO_IMAGE, "rb").read() 189 | object_image_array = np.array(Image.open(OBJECT_DEMO_IMAGE)) 190 | 191 | st.write("Below is a default Image. You can upload your own custom image.👆") 192 | st.write(" ") 193 | st.image(object_image_array, use_column_width=True) 194 | st.write(" ") 195 | if st.button("Detect Labels"): 196 | response = object_detection(object_image_bytes) 197 | st.write(response) 198 | st.write(" ") 199 | download_button_str = download_button(response, "Labels.json", f"Click here to download the results") 200 | st.markdown(download_button_str, unsafe_allow_html=True) 201 | 202 | 203 | elif choice == "Facial Analysis": 204 | st.title("Analyze human faces 👦👩 in Image") 205 | face_file_buffer = st.file_uploader("Upload Image 👇", type= ["png", "jpg", "jpeg"]) 206 | if face_file_buffer is not None: 207 | face_file_bytes = pil_image_to_byte_array(Image.open(face_file_buffer)) 208 | face_file_array = np.array(Image.open(face_file_buffer)) 209 | else: 210 | face_file_bytes = open(FACE_DEMO_IMAGE, "rb").read() 211 | face_file_array = np.array(Image.open(FACE_DEMO_IMAGE)) 212 | 213 | st.write("Below is a default Image. You can upload your own custom image. 👆") 214 | st.write(" ") 215 | st.image(face_file_array, use_column_width=True) 216 | st.write(" ") 217 | 218 | if st.button("Analyze Face"): 219 | response = face_analysis(face_file_bytes) 220 | st.write(response) 221 | st.write(" ") 222 | download_button_str = download_button(response, "FaceAnalysis.json", f"Click here to download the results") 223 | st.markdown(download_button_str, unsafe_allow_html=True) 224 | 225 | 226 | elif choice == "PPE Detection": 227 | st.title("Detect If Humans have wore PPE 😷👷🏽") 228 | ppe_file_buffer = st.file_uploader("Upload Image Below 👇", type= ["png", "jpg", "jpeg"]) 229 | if ppe_file_buffer is not None: 230 | ppe_file_bytes = pil_image_to_byte_array(Image.open(ppe_file_buffer)) 231 | ppe_file_array = np.array(Image.open(ppe_file_buffer)) 232 | else: 233 | ppe_file_bytes = open(PPE_DEMO_IMAGE, "rb").read() 234 | ppe_file_array = np.array(Image.open(PPE_DEMO_IMAGE)) 235 | 236 | st.write("Below is a default Image. You can upload your own custom image. 👆") 237 | st.write(" ") 238 | st.image(ppe_file_array, use_column_width=True) 239 | st.write(" ") 240 | 241 | if st.button("Detect PPE"): 242 | response = ppe_detection(ppe_file_bytes) 243 | st.write(response) 244 | st.write(" ") 245 | download_button_str = download_button(response, "PPEresult.json", f"Click here to download the results") 246 | st.markdown(download_button_str, unsafe_allow_html=True) 247 | 248 | elif choice == "Image Moderation": 249 | st.title("Find Explicit or Nude Contents 🔞❌ ") 250 | nude_file_buffer = st.file_uploader("Upload an Image below 👇", type= ["png", "jpg", "jpeg"]) 251 | if nude_file_buffer is not None: 252 | nude_file_bytes = pil_image_to_byte_array(Image.open(nude_file_buffer)) 253 | nude_file_array = np.array(Image.open(nude_file_buffer)) 254 | else: 255 | nude_file_bytes = open(NUDE_DEMO_IMAGE, "rb").read() 256 | nude_file_array = np.array(Image.open(NUDE_DEMO_IMAGE)) 257 | 258 | st.write("Below is a default Image. You can upload your own custom image. 👆") 259 | st.write(" ") 260 | st.image(nude_file_array, use_column_width=True) 261 | st.write(" ") 262 | 263 | if st.button("Detect Explicit & Nude Contents"): 264 | response = nude_detection(nude_file_bytes) 265 | st.write(response) 266 | st.write(" ") 267 | download_button_str = download_button(response, "moderation.json", f"Click here to download the results") 268 | st.markdown(download_button_str, unsafe_allow_html=True) 269 | 270 | 271 | elif choice == "Text in Image": 272 | st.title("Extract Texts in Image 🅰️ 🅱️ ....") 273 | st.write(" ") 274 | st.write(" ") 275 | img_file_buffer = st.file_uploader("Upload an image 👇", type=["png", "jpg", "jpeg"]) 276 | if img_file_buffer is not None: 277 | image_bytes = pil_image_to_byte_array(Image.open(img_file_buffer)) 278 | image_array = np.array(Image.open(img_file_buffer)) 279 | 280 | else: 281 | image_bytes = open(DEMO_IMAGE, "rb").read() 282 | image_array = np.array(Image.open(DEMO_IMAGE)) 283 | st.write("Below is a default Image. You can upload your own custom image.👆") 284 | st.write(" ") 285 | st.image(image_array, use_column_width=True) 286 | st.write(" ") 287 | if st.button("Extract Texts"): 288 | response = process_image(image_bytes) 289 | extracted_text = [t["DetectedText"] for t in response["TextDetections"]] 290 | st.header("Extracted text") 291 | st.write(extracted_text) 292 | download_button_str = download_button( 293 | extracted_text, "extracted_text.json", f"Click here to download Extracted Text") 294 | st.write(" ") 295 | st.markdown(download_button_str, unsafe_allow_html=True) 296 | st.header("Raw response") 297 | st.write(response) 298 | else: 299 | about_markdown = read_markdown_file("markdowns/newabout.md") 300 | st.markdown(about_markdown, unsafe_allow_html=True) 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 309 | #------------------------Ending the main function----------------- 310 | if __name__ == '__main__': 311 | main() 312 | 313 | #-----------------------App is completed--------------------------- --------------------------------------------------------------------------------