Spaces:
Sleeping
Sleeping
File size: 4,363 Bytes
85f4ee8 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
{
"cells": [
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"c:\\My Documents\\repos\\mouse-digit-recognition-gradio\\.venv\\lib\\site-packages\\tqdm\\auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n",
" from .autonotebook import tqdm as notebook_tqdm\n"
]
}
],
"source": [
"import huggingface_hub\n",
"from huggingface_hub import HfApi\n",
"from huggingface_hub import Repository\n",
"from PIL import Image\n",
"# from datasets import load_dataset\n",
"\n",
"DS_WRITE_TOKEN = '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'\n",
"DS_READ_TOKEN = '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'\n",
"DATASET_REPO_URL = 'https://huggingface.co/datasets/RomanShp/MNIST-ResNet-Demo-Data'\n",
"DATASET_REPO_ID = 'RomanShp/MNIST-ResNet-Demo-Data'\n",
"IMAGE_FILE_PATH = '../data/generated/0/img_0.png'"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'https://huggingface.co/datasets/RomanShp/MNIST-ResNet-Demo-Data/blob/main/test/subfolder/'"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"api = HfApi()\n",
"api.upload_file(path_or_fileobj=IMAGE_FILE_PATH,repo_id=DATASET_REPO_ID,repo_type='dataset',token=DS_WRITE_TOKEN,path_in_repo='test/subfolder/')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"\n",
"dataset = load_dataset(\"imagefolder\", data_dir=\"../data/generated/\")\n",
"dataset2 = load_dataset(\"imagefolder\", data_dir=\"../data/sessions/87a5b98a-6487-4014-a7c3-34ba72443bac/data_finetune\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"push1_res = dataset.push_to_hub(DATASET_REPO_ID,token=DS_WRITE_TOKEN,branch='dataset1')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"dataset2.push_to_hub(DATASET_REPO_ID,token=DS_WRITE_TOKEN)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"############################################################"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"from googleapiclient.discovery import build\n",
"import requests\n",
"import json"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# API key\n",
"API_KEY = 'YOUR_API_KEY'\n",
"\n",
"# Google Drive folder ID where you want to save the file\n",
"folder_id = 'YOUR_DRIVE_FOLDER_ID'\n",
"\n",
"# Path of the file you want to upload\n",
"file_path = '../data/generated/0/img_0.png'\n",
"\n",
"def upload_file(file_path, folder_id):\n",
" # Create the file metadata\n",
" file_metadata = {\n",
" 'name': file_path.split('/')[-1],\n",
" 'parents': [folder_id]\n",
" }\n",
"\n",
" # Upload the file\n",
" drive_service = build('drive', 'v3', developerKey=API_KEY)\n",
" media = drive_service.files().create(\n",
" body=file_metadata,\n",
" media_body=file_path\n",
" ).execute()\n",
"\n",
" print('File uploaded successfully. File ID: %s' % media['id'])\n",
"\n",
"# Usage\n",
"upload_file(file_path, folder_id)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3.9.13 ('.venv': venv)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.9"
},
"orig_nbformat": 4,
"vscode": {
"interpreter": {
"hash": "7b1f26db46c35107ed3b498802b8bb373e35937983f8b3b0cd60b73042c388bb"
}
}
},
"nbformat": 4,
"nbformat_minor": 2
}
|