Skip to content

Commit

Permalink
download_model.py updated
Browse files Browse the repository at this point in the history
  • Loading branch information
Not-Sahil-Raja committed Nov 16, 2024
1 parent e642754 commit 1322bf4
Show file tree
Hide file tree
Showing 3 changed files with 143 additions and 12 deletions.
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ COPY . /app
RUN pip install --no-cache-dir -r requirements.txt

# Create a directory to store the model
RUN mkdir -p /app/model
RUN mkdir -p model

# Download the model and unzip it
RUN python download_model.py

# Expose the port the app runs on
Expand Down
24 changes: 13 additions & 11 deletions download_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,22 @@
import zipfile


# downloading the model from google drive
def download_model_from_gdrive(drive_url, output_path):
gdown.download(drive_url, output_path, quiet=False)
# downloading the model from google drive and unzipping it
def download_model_from_gdrive(drive_url, zip_download_dir, unzip_dir):
model_drive_id = drive_url.split("/")[-2]
prefix = "https://drive.google.com/uc?/export=download&id="
gdown.download(prefix + model_drive_id, zip_download_dir)

print(f"Model downloaded at {drive_url} into file {zip_download_dir}")

with zipfile.ZipFile(zip_download_dir, "r") as zip_ref:
zip_ref.extractall(unzip_dir)


DRIVE_URL = (
"https://drive.google.com/file/d/1aSBsINRxalELJPE0KJMlZ9Qh6uXqBfqy/view?usp=sharing"
)
OUTPUT_PATH = "model/model_v1.zip"
download_model_from_gdrive(DRIVE_URL, OUTPUT_PATH)

# extract the zip file

with zipfile.ZipFile("model/model_v1.zip", "r") as zip_ref:
zip_ref.extractall("model")
OUTPUT_PATH = "model/model.zip"
UNZIP_DIR = "model/"

print("Model downloaded and extracted successfully")
download_model_from_gdrive(DRIVE_URL, OUTPUT_PATH, UNZIP_DIR)
127 changes: 127 additions & 0 deletions research/download_mode.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"import gdown\n",
"import zipfile"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'d:\\\\coding\\\\MLProject\\\\KindneyDiseaseClassification'"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import os\n",
"os.chdir(\"../\")\n",
"%pwd"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"model_drive_url = \"https://drive.google.com/file/d/1aSBsINRxalELJPE0KJMlZ9Qh6uXqBfqy/view?usp=sharing\"\n",
"model_drive_id = model_drive_url.split(\"/\")[-2]"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"zip_download_dir = \"model/model.zip\"\n",
"prefix = \"https://drive.google.com/uc?/export=download&id=\""
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Downloading...\n",
"From (original): https://drive.google.com/uc?/export=download&id=1aSBsINRxalELJPE0KJMlZ9Qh6uXqBfqy\n",
"From (redirected): https://drive.google.com/uc?%2Fexport=download&id=1aSBsINRxalELJPE0KJMlZ9Qh6uXqBfqy&confirm=t&uuid=022e4cfe-a1a2-4a2d-a2bb-a2849c19231c\n",
"To: d:\\coding\\MLProject\\KindneyDiseaseClassification\\model\\model.zip\n",
"100%|██████████| 180M/180M [00:17<00:00, 10.2MB/s] \n"
]
},
{
"data": {
"text/plain": [
"'model/model.zip'"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"gdown.download(prefix + model_drive_id, zip_download_dir)"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
"unzip_dir = \"model/Testing\"\n",
"\n",
"with zipfile.ZipFile(zip_download_dir, \"r\") as zip_ref:\n",
" zip_ref.extractall(unzip_dir) "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "kidney_CNN_1",
"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.12"
}
},
"nbformat": 4,
"nbformat_minor": 2
}

0 comments on commit 1322bf4

Please sign in to comment.