diff --git a/README.md b/README.md index 7250eca..34b213e 100644 --- a/README.md +++ b/README.md @@ -15,21 +15,11 @@ # How to run? ### STEPS: -Clone the repository +### STEP 01- Clone the repository ```bash -https://github.com/entbappy/End-to-end-Text-Summarization +!git clone https://github.com/entbappy/End-to-end-Text-Summarization ``` -### STEP 01- Create a conda environment after opening the repository - -```bash -conda create -n summary python=3.8 -y -``` - -```bash -conda activate summary -``` - ### STEP 02- install the requirements ```bash @@ -48,12 +38,6 @@ open up you local host and port ``` -```bash -Author: Krish Naik -Data Scientist -Email: krishnaik06@gmail.com - -``` @@ -129,3 +113,39 @@ Email: krishnaik06@gmail.com AWS_ECR_LOGIN_URI = demo>> 566373416292.dkr.ecr.ap-south-1.amazonaws.com ECR_REPOSITORY_NAME = simple-app + +# How to run and train model in google colab for shorter run-time? +### STEPS: + +### STEP 01- Clone the repository + +```bash +! git clone https://github.com/Demogorgon24242/Text-SummarizationMLops.git +``` +### STEP 02- install the requirements +```bash +import os +os.chdir('/content/Text-Summarization-NLP-Project/') +!pip freeze > requirements.txt +!pip install . +!pip install fastapi nest-asyncio pyngrok uvicorn +! ngrok authtoken (Your token you get after registration on ngrok website) +``` +P.S. Here its a bit tedious, since I couldn't figure it out yet, it is required for all libraries in requirements.txt to be installed separately for each runtime. Hopefully I will try and fix it soon + +# Finally run the following command +```bash +! python3 app.py +``` +Now, +```bash +open up your displayed public url +``` + +```bash +Original Author: Krish Naik +Data Scientist +Email: krishnaik06@gmail.com + +Edits by : Demogorgon_24242 +``` diff --git a/app.py b/app.py index 7d6d1d4..a17da2e 100644 --- a/app.py +++ b/app.py @@ -6,12 +6,21 @@ from starlette.responses import RedirectResponse from fastapi.responses import Response from textSummarizer.pipeline.prediction import PredictionPipeline - - +import nest_asyncio +from pyngrok import ngrok +import uvicorn +from fastapi.middleware.cors import CORSMiddleware text:str = "What is Text Summarization?" app = FastAPI() +app.add_middleware( + CORSMiddleware, + allow_origins=['*'], + allow_credentials=True, + allow_methods=['*'], + allow_headers=['*'], +) @app.get("/", tags=["authentication"]) async def index(): return RedirectResponse(url="/docs") @@ -42,4 +51,7 @@ async def predict_route(text): if __name__=="__main__": - uvicorn.run(app, host="0.0.0.0", port=8080) + ngrok_tunnel = ngrok.connect(3000) + print('Public URL:', ngrok_tunnel.public_url) + nest_asyncio.apply() + uvicorn.run(app, port=3000) diff --git a/requirements.txt b/requirements.txt index 7da43fb..da13aa7 100644 --- a/requirements.txt +++ b/requirements.txt @@ -18,4 +18,5 @@ ensure==1.0.2 fastapi==0.78.0 uvicorn==0.18.3 Jinja2==3.1.2 +accelerate -U -e . diff --git a/src/textSummarizer/conponents/model_trainer.py b/src/textSummarizer/conponents/model_trainer.py index 0f703a9..af87444 100644 --- a/src/textSummarizer/conponents/model_trainer.py +++ b/src/textSummarizer/conponents/model_trainer.py @@ -16,7 +16,7 @@ def __init__(self, config: ModelTrainerConfig): def train(self): device = "cuda" if torch.cuda.is_available() else "cpu" tokenizer = AutoTokenizer.from_pretrained(self.config.model_ckpt) - model_pegasus = AutoModelForSeq2SeqLM.from_pretrained(self.config.model_ckpt).to(device) + model_pegasus = AutoModelForSeq2SeqLM.from_pretrained(self.config.model_ckpt,force_download=True, resume_download=False).to(device) seq2seq_data_collator = DataCollatorForSeq2Seq(tokenizer, model=model_pegasus) #loading data