Skip to content

Commit

Permalink
pipeline updated
Browse files Browse the repository at this point in the history
  • Loading branch information
malleswarigelli committed Apr 8, 2024
1 parent 5dcc19a commit e3dc432
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 54 deletions.
3 changes: 2 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ demo.py
README.md
LICENSE
us_visa.egg.info
notebook
notebook
credentials.txt
2 changes: 1 addition & 1 deletion .github/workflows/aws.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,4 @@ jobs:

- name: Run Docker Image to serve users
run: |
docker run -d -e AWS_ACCESS_KEY_ID="${{ secrets.AWS_ACCESS_KEY_ID }}" -e AWS_SECRET_ACCESS_KEY="${{ secrets.AWS_SECRET_ACCESS_KEY }}" -e AWS_DEFAULT_REGION="${{ secrets.AWS_DEFAULT_REGION }}" -e MONGODB_URL="${{ secrets.MONGODB_URL }}" -p 8080:8080 "${{ steps.login-ecr.outputs.registry }}"/"${{ secrets.ECR_REPO }}":latest
docker run -d -e AWS_ACCESS_KEY_ID="${{ secrets.AWS_ACCESS_KEY_ID }}" -e AWS_SECRET_ACCESS_KEY="${{ secrets.AWS_SECRET_ACCESS_KEY }}" -e AWS_DEFAULT_REGION="${{ secrets.AWS_DEFAULT_REGION }}" -e MONGODB_URL="${{ secrets.MONGODB_URL }}" -p 1111:1111 "${{ steps.login-ecr.outputs.registry }}"/"${{ secrets.ECR_REPO }}":latest
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -159,4 +159,5 @@ cython_debug/
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

artifact/*
artifact/*
credentials.txt
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ os.getenv(MONGODB_URL_KEY)

```run this command in gitbash to set MONGODB_URL
export MONGODB_URL= "mongodb+srv://username:password@cluster0.ppivwau.mongodb.net/?retryWrites=true&w=majority&appName=Cluster0"
export MONGODB_URL="mongodb+srv://username:password@cluster0.ppivwau.mongodb.net/?retryWrites=true&w=majority&appName=Cluster0"
export AWS_ACCESS_KEY_ID=<AWS_ACCESS_KEY_ID>
export AWS_SECRET_ACCESS_KEY=<AWS_SECRET_ACCESS_KEY>
Expand Down Expand Up @@ -93,7 +93,7 @@ export AWS_SECRET_ACCESS_KEY=<AWS_SECRET_ACCESS_KEY>
2. AmazonEC2FullAccess

## 3. Create ECR repo to store/save docker image
- Save the URI: 136566696263.dkr.ecr.us-east-1.amazonaws.com/mlproject
- Save the URI: 637423357032.dkr.ecr.us-east-1.amazonaws.com/usvisa_ecr

## 4. Create EC2 machine (Ubuntu)

Expand Down
4 changes: 2 additions & 2 deletions US_Visa/constant/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@
MODEL EVALUATION related constant start with MODEL_EVALUATION var name
"""
MODEL_EVALUATION_CHANGED_THRESHOLD_SCORE: float = 0.02
MODEL_BUCKET_NAME = "usvisamodel2024"
MODEL_BUCKET_NAME = "usvisamodel24"
MODEL_PUSHER_S3_KEY = "model-registry"


APP_HOST = "0.0.0.0"
APP_PORT = 8080
APP_PORT = 1111
31 changes: 15 additions & 16 deletions US_Visa/pipeline/prediction_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,7 @@ def __init__(self,


except Exception as e:
raise USvisaException(e, sys) from e

def get_usvisa_input_data_frame(self)-> DataFrame:
"""
This function returns a DataFrame from USvisaData class input
"""
try:

usvisa_input_dict = self.get_usvisa_data_as_dict()
return DataFrame(usvisa_input_dict)

except Exception as e:
raise USvisaException(e, sys) from e

raise USvisaException(e, sys) from e

def get_usvisa_data_as_dict(self):
"""
Expand Down Expand Up @@ -85,6 +72,18 @@ def get_usvisa_data_as_dict(self):

except Exception as e:
raise USvisaException(e, sys) from e

def get_usvisa_input_data_frame(self)-> DataFrame:
"""
This function converts dictionary from get_usvisa_data_as_dict into a pandas dataframe
"""
try:

usvisa_input_dict = self.get_usvisa_data_as_dict()
return DataFrame(usvisa_input_dict)

except Exception as e:
raise USvisaException(e, sys) from e

class USvisaClassifier:
def __init__(self,prediction_pipeline_config: USvisaPredictorConfig = USvisaPredictorConfig(),) -> None:
Expand All @@ -97,7 +96,7 @@ def __init__(self,prediction_pipeline_config: USvisaPredictorConfig = USvisaPred
except Exception as e:
raise USvisaException(e, sys)

def predict(self, dataframe) -> str:
def predict(self, df:DataFrame) -> str:
"""
This is the method of USvisaClassifier
Returns: Prediction in string format
Expand All @@ -108,7 +107,7 @@ def predict(self, dataframe) -> str:
bucket_name=self.prediction_pipeline_config.model_bucket_name,
model_path=self.prediction_pipeline_config.model_file_path,
)
result = model.predict(dataframe)
result = model.predict(df)

return result

Expand Down
2 changes: 1 addition & 1 deletion app.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ async def predictRouteClient(request: Request):

model_predictor = USvisaClassifier()

value = model_predictor.predict(dataframe=usvisa_df)[0]
value = model_predictor.predict(df=usvisa_df)[0]

status = None
if value == 1:
Expand Down
69 changes: 39 additions & 30 deletions notebook/mongoDB_demo.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
},
{
"cell_type": "code",
"execution_count": 19,
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -41,7 +41,7 @@
},
{
"cell_type": "code",
"execution_count": 20,
"execution_count": 2,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -182,7 +182,7 @@
"4 149907.3900 Year Y Certified "
]
},
"execution_count": 20,
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -194,7 +194,7 @@
},
{
"cell_type": "code",
"execution_count": 21,
"execution_count": 3,
"metadata": {},
"outputs": [
{
Expand All @@ -203,7 +203,7 @@
"(25480, 12)"
]
},
"execution_count": 21,
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -214,7 +214,7 @@
},
{
"cell_type": "code",
"execution_count": 22,
"execution_count": 4,
"metadata": {},
"outputs": [
{
Expand All @@ -227,7 +227,7 @@
" dtype='object')"
]
},
"execution_count": 22,
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -238,7 +238,7 @@
},
{
"cell_type": "code",
"execution_count": 23,
"execution_count": 5,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -12247,7 +12247,7 @@
" ...]"
]
},
"execution_count": 23,
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -12259,7 +12259,7 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 13,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -12270,7 +12270,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 14,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -12279,7 +12279,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 15,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -12291,16 +12291,16 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 16,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<pymongo.cursor.Cursor at 0x16679617c40>"
"<pymongo.cursor.Cursor at 0x20c2006aac0>"
]
},
"execution_count": 4,
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -12312,7 +12312,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 17,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -37809,7 +37809,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 18,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -37819,7 +37819,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 19,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -37973,7 +37973,7 @@
"4 Certified "
]
},
"execution_count": 8,
"execution_count": 19,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -37984,19 +37984,11 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 20,
"metadata": {},
"outputs": [],
"source": [
"## If you are getting timeout issue\n",
"\n",
"import certifi\n",
"client = pymongo.MongoClient(CONNECTION_URL, tlsCAFile=certifi.where())\n",
"# TO CREATE THE DATABASE\n",
"data_base = client[DB_NAME]\n",
"collection = data_base[COLLECTION_NAME]\n",
"# TO INSERT DATA INTO THE COLLECTION\n",
"#rec = collection.insert_many(data)\n"
"\n"
]
},
{
Expand Down Expand Up @@ -38241,14 +38233,31 @@
"print(from_root)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"## If you are getting timeout issue\n",
"\n",
"import certifi\n",
"client = pymongo.MongoClient(CONNECTION_URL, tlsCAFile=certifi.where())\n",
"# TO CREATE THE DATABASE\n",
"data_base = client[DB_NAME]\n",
"collection = data_base[COLLECTION_NAME]\n",
"# TO INSERT DATA INTO THE COLLECTION\n",
"rec = collection.insert_many(data)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# run this command in gitbash to set MONGODB_URL while running app.py or demo.py file \n",
"# export MONGODB_URL= \"mongodb+srv://username:password@cluster0.ppivwau.mongodb.net/?retryWrites=true&w=majority&appName=Cluster0\""
"# export MONGODB_URL=\"mongodb+srv://username:password@cluster0.ppivwau.mongodb.net/?retryWrites=true&w=majority&appName=Cluster0\""
]
}
],
Expand Down

0 comments on commit e3dc432

Please sign in to comment.