{"id":18035593,"url":"https://github.com/adesoji1/image-organization-project-using-google-cloud-vision-api","last_synced_at":"2025-10-30T19:10:07.066Z","repository":{"id":243027576,"uuid":"811255005","full_name":"Adesoji1/Image-Organization-project-using-Google-Cloud-Vision-API","owner":"Adesoji1","description":"automate the organization of images in our Google Drive. Our goal is to categorize and move images into specific folders based on their content.","archived":false,"fork":false,"pushed_at":"2024-06-06T08:56:46.000Z","size":6,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-10T07:45:50.074Z","etag":null,"topics":["googlevisionapi"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Adesoji1.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-06-06T08:39:50.000Z","updated_at":"2024-06-06T08:58:41.000Z","dependencies_parsed_at":"2024-06-06T10:15:13.658Z","dependency_job_id":"a038a7c3-f826-4e70-851d-0f066dcb1d36","html_url":"https://github.com/Adesoji1/Image-Organization-project-using-Google-Cloud-Vision-API","commit_stats":null,"previous_names":["adesoji1/image-organization-project-using-google-cloud-vision-api"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Adesoji1%2FImage-Organization-project-using-Google-Cloud-Vision-API","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Adesoji1%2FImage-Organization-project-using-Google-Cloud-Vision-API/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Adesoji1%2FImage-Organization-project-using-Google-Cloud-Vision-API/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Adesoji1%2FImage-Organization-project-using-Google-Cloud-Vision-API/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Adesoji1","download_url":"https://codeload.github.com/Adesoji1/Image-Organization-project-using-Google-Cloud-Vision-API/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247263599,"owners_count":20910436,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["googlevisionapi"],"created_at":"2024-10-30T12:08:50.965Z","updated_at":"2025-10-30T19:10:06.993Z","avatar_url":"https://github.com/Adesoji1.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"The automation process in this project involves using a Python script that performs the following steps automatically:\n\n1. **Authenticate and Initialize Clients**: The script uses service account credentials to authenticate with the Google Cloud Vision API and Google Drive API.\n\n2. **List Images**: It retrieves a list of image files from a specified Google Drive folder.\n\n3. **Download Images**: The script downloads each image locally for analysis.\n\n4. **Analyze Images**: It uses the Google Cloud Vision API to analyze the content of each image and retrieve labels/categories.\n\n5. **Categorize and Move Images**: Based on the labels retrieved, the script determines the appropriate folder for each image and moves it to the corresponding folder in Google Drive.\n\nHere is a more detailed breakdown of the automated steps:\n\n### Script Details (`organize_images.py`)\n\n```python\nimport os\nimport io\nfrom google.cloud import vision\nfrom google.oauth2 import service_account\nfrom googleapiclient.discovery import build\nfrom googleapiclient.http import MediaIoBaseDownload, MediaFileUpload\nfrom config import KEY_PATH, SOURCE_FOLDER_ID, CATEGORIES_TO_FOLDERS\n\n# Authenticate and initialize clients\ncredentials = service_account.Credentials.from_service_account_file(KEY_PATH)\nvision_client = vision.ImageAnnotatorClient(credentials=credentials)\ndrive_service = build('drive', 'v3', credentials=credentials)\n\ndef list_images(folder_id):\n    query = f\"'{folder_id}' in parents and mimeType contains 'image/'\"\n    results = drive_service.files().list(q=query, fields=\"files(id, name)\").execute()\n    items = results.get('files', [])\n    return items\n\ndef download_image(file_id, file_name):\n    request = drive_service.files().get_media(fileId=file_id)\n    fh = io.FileIO(file_name, 'wb')\n    downloader = MediaIoBaseDownload(fh, request)\n    done = False\n    while done is False:\n        status, done = downloader.next_chunk()\n    return file_name\n\ndef upload_image(file_name, folder_id):\n    file_metadata = {\n        'name': file_name,\n        'parents': [folder_id]\n    }\n    media = MediaFileUpload(file_name, resumable=True)\n    file = drive_service.files().create(body=file_metadata, media_body=media, fields='id').execute()\n    return file.get('id')\n\ndef analyze_image(file_name):\n    with open(file_name, 'rb') as image_file:\n        content = image_file.read()\n    image = vision.Image(content=content)\n    response = vision_client.label_detection(image=image)\n    labels = response.label_annotations\n    categories = [label.description for label in labels]\n    return categories\n\ndef categorize_and_move_images(folder_id, categories_to_folders):\n    images = list_images(folder_id)\n    for image in images:\n        file_id = image['id']\n        file_name = image['name']\n        local_path = download_image(file_id, file_name)\n        categories = analyze_image(local_path)\n        \n        # Determine the target folder based on categories\n        target_folder_id = None\n        for category in categories:\n            if category in categories_to_folders:\n                target_folder_id = categories_to_folders[category]\n                break\n        \n        if target_folder_id:\n            upload_image(local_path, target_folder_id)\n            drive_service.files().delete(fileId=file_id).execute()\n        os.remove(local_path)\n\nif __name__ == '__main__':\n    categorize_and_move_images(SOURCE_FOLDER_ID, CATEGORIES_TO_FOLDERS)\n```\n\n### Configuration (`config.py`)\n\n```python\n# config.py\nKEY_PATH = 'path/to/your/service-account-file.json'\nSOURCE_FOLDER_ID = 'your_source_folder_id'\nCATEGORIES_TO_FOLDERS = {\n    'Cat': 'folder_id_for_cats',\n    'Dog': 'folder_id_for_dogs',\n    # Add more categories and corresponding folder IDs\n}\n```\n\n### How the Automation Works:\n\n1. **Authentication**: The script uses the service account credentials to authenticate with Google Cloud services.\n2. **Image Listing**: It lists all images in the specified Google Drive folder.\n3. **Downloading**: Each image is downloaded locally for processing.\n4. **Analysis**: The Vision API is used to analyze the content of the image and obtain labels.\n5. **Categorization**: The script matches the obtained labels with the predefined categories.\n6. **Moving Images**: Based on the matched category, the image is uploaded to the corresponding folder in Google Drive, and the local copy is deleted.\n\nTo run this script, you simply execute:\n\n```sh\npython organize_images.py\n```\n\nThis command triggers the entire workflow, handling the images in your Google Drive folder automatically according to the specified categories and folders.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadesoji1%2Fimage-organization-project-using-google-cloud-vision-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fadesoji1%2Fimage-organization-project-using-google-cloud-vision-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadesoji1%2Fimage-organization-project-using-google-cloud-vision-api/lists"}