Jeevant10 commited on
Commit
fd05733
·
1 Parent(s): 65db57d

running it on newer techs

Browse files
app.py CHANGED
@@ -1,15 +1,12 @@
1
  from fastapi import FastAPI
2
  import uvicorn
 
3
  import sys
4
- import os
5
- from fastapi.templating import Jinja2Templates
6
  from starlette.responses import RedirectResponse
7
  from fastapi.responses import Response
8
  from textSummarizer.pipeline.prediction import PredictionPipeline
9
 
10
- txt:str = "What is Text Summarization?"
11
-
12
- app = FastAPI()
13
 
14
  @app.get("/", tags=["authentication"] )
15
  async def index():
@@ -19,10 +16,17 @@ async def index():
19
  @app.get("/train")
20
  async def training():
21
  try:
22
- os.system("python main.py")
 
 
 
 
 
23
  return Response("Training completed successfully!")
 
 
24
  except Exception as e:
25
- return Response(f"Error Occurred! {e}")
26
 
27
 
28
  @app.post("/predict")
 
1
  from fastapi import FastAPI
2
  import uvicorn
3
+ import subprocess
4
  import sys
 
 
5
  from starlette.responses import RedirectResponse
6
  from fastapi.responses import Response
7
  from textSummarizer.pipeline.prediction import PredictionPipeline
8
 
9
+ app = FastAPI(title="AI Text Summarizer", version="1.0.0")
 
 
10
 
11
  @app.get("/", tags=["authentication"] )
12
  async def index():
 
16
  @app.get("/train")
17
  async def training():
18
  try:
19
+ result = subprocess.run(
20
+ [sys.executable, "main.py"],
21
+ capture_output=True, text=True, timeout=7200
22
+ )
23
+ if result.returncode != 0:
24
+ return Response(f"Training failed!\n{result.stderr}", status_code=500)
25
  return Response("Training completed successfully!")
26
+ except subprocess.TimeoutExpired:
27
+ return Response("Training timed out!", status_code=504)
28
  except Exception as e:
29
+ return Response(f"Error Occurred! {e}", status_code=500)
30
 
31
 
32
  @app.post("/predict")
config/config.yaml CHANGED
@@ -1,4 +1,4 @@
1
- artifacts_root: artifacts_root
2
 
3
 
4
  data_ingestion:
@@ -12,18 +12,26 @@ data_validation:
12
  root_dir: artifacts/data_validation
13
  STATUS_FILE: artifacts/data_validation/status.txt
14
  ALL_REQUIRED_FILES: ["train" , "test" , "validation"]
 
15
 
16
 
17
  data_transformation:
18
  root_dir: artifacts/data_transformation
19
  data_path: artifacts/data_ingestion/samsum_dataset
20
  tokenizer_name: google/pegasus-cnn_dailymail
 
 
 
21
 
22
 
23
  model_trainer:
24
  root_dir: artifacts/model_trainer
25
  data_path: artifacts/data_transformation/samsum_dataset
26
  model_ckpt: google/pegasus-cnn_dailymail
 
 
 
 
27
 
28
 
29
  model_evaluation:
 
1
+ artifacts_root: artifacts
2
 
3
 
4
  data_ingestion:
 
12
  root_dir: artifacts/data_validation
13
  STATUS_FILE: artifacts/data_validation/status.txt
14
  ALL_REQUIRED_FILES: ["train" , "test" , "validation"]
15
+ data_dir: artifacts/data_ingestion/samsum_dataset
16
 
17
 
18
  data_transformation:
19
  root_dir: artifacts/data_transformation
20
  data_path: artifacts/data_ingestion/samsum_dataset
21
  tokenizer_name: google/pegasus-cnn_dailymail
22
+ # Dev quick-run tokenizer override (use same model as trainer to avoid token mismatch)
23
+ dev_run: true
24
+ dev_model: t5-small
25
 
26
 
27
  model_trainer:
28
  root_dir: artifacts/model_trainer
29
  data_path: artifacts/data_transformation/samsum_dataset
30
  model_ckpt: google/pegasus-cnn_dailymail
31
+ # Development quick-train options
32
+ dev_run: true
33
+ dev_model: t5-small
34
+ dev_subset: 64
35
 
36
 
37
  model_evaluation:
params.yaml CHANGED
@@ -4,7 +4,7 @@ TrainingArguments:
4
  per_device_train_batch_size: 1
5
  weight_decay: 0.01
6
  logging_steps: 10
7
- evaluation_strategy: steps
8
  eval_steps: 500
9
  save_steps: 1e6
10
  gradient_accumulation_steps: 16
 
4
  per_device_train_batch_size: 1
5
  weight_decay: 0.01
6
  logging_steps: 10
7
+ eval_strategy: steps
8
  eval_steps: 500
9
  save_steps: 1e6
10
  gradient_accumulation_steps: 16
requirements.txt CHANGED
@@ -1,21 +1,26 @@
1
- transformers
2
- transformers[sentencepiece]
3
- dataset
4
- sacrebleu
5
- py7zr
6
- pandas
7
- nltk
8
- tqdm
9
- PyYAML
10
- matplotlib
11
- torch
12
- notebook
13
- boto3
14
- mypy-boto3-s3
 
 
 
 
 
15
  python-box==6.0.2
16
- ensure==1.0.2
17
- fastapi==0.78.0
18
- uvicorn==0.18.3
19
- Jinja2==3.1.2
20
- rouge-score
21
  -e .
 
1
+ transformers>=5.0.0
2
+ transformers[torch]>=5.0.0
3
+ sentencepiece>=0.1.98
4
+ datasets>=2.5.0
5
+ evaluate>=0.4.0
6
+ rouge-score>=0.1.2
7
+ sacrebleu>=2.0.0
8
+ py7zr>=0.19.0
9
+ pandas>=1.5.0
10
+ nltk>=3.8.0
11
+ tqdm>=4.60.0
12
+ PyYAML>=6.0
13
+ matplotlib>=3.6.0
14
+ # NOTE: pin `torch` per target machine; this is a minimum
15
+ torch>=2.0.0
16
+ accelerate>=0.26.0
17
+ notebook>=6.4.0
18
+ boto3>=1.26.0
19
+ mypy-boto3-s3>=1.25.0
20
  python-box==6.0.2
21
+ fastapi>=0.95.0
22
+ uvicorn>=0.22.0
23
+ Jinja2>=3.1.2
24
+ python-multipart>=0.0.6
25
+ # Editable install of local package
26
  -e .
research/01_data_ingestion.ipynb CHANGED
@@ -195,7 +195,7 @@
195
  ],
196
  "metadata": {
197
  "kernelspec": {
198
- "display_name": "textSummarizer",
199
  "language": "python",
200
  "name": "python3"
201
  },
@@ -209,7 +209,7 @@
209
  "name": "python",
210
  "nbconvert_exporter": "python",
211
  "pygments_lexer": "ipython3",
212
- "version": "3.11.13"
213
  }
214
  },
215
  "nbformat": 4,
 
195
  ],
196
  "metadata": {
197
  "kernelspec": {
198
+ "display_name": "model",
199
  "language": "python",
200
  "name": "python3"
201
  },
 
209
  "name": "python",
210
  "nbconvert_exporter": "python",
211
  "pygments_lexer": "ipython3",
212
+ "version": "3.13.5"
213
  }
214
  },
215
  "nbformat": 4,
setup.py CHANGED
@@ -1,8 +1,8 @@
1
  import setuptools
2
 
3
- with open("README.md" , "r" , encoding="utf-8") as f:
4
  long_description = f.read()
5
-
6
  __version__ = "0.0.0"
7
 
8
  REPO_NAME = "AI_Summarizer"
@@ -17,11 +17,18 @@ setuptools.setup(
17
  author_email=AUTHOR_EMAIL,
18
  description="A Small python package for Text NLP App",
19
  long_description=long_description,
20
- long_description_content="text/markdown",
21
  url=f"https://github.com/{AUTHOR_USER_NAME}/{REPO_NAME}",
22
  project_urls={
23
  "Bug Tracker": f"https://github.com/{AUTHOR_USER_NAME}/{REPO_NAME}/issues",
24
  },
25
  package_dir={"": "src"},
26
- packages=setuptools.find_packages(where="src")
 
 
 
 
 
 
 
27
  )
 
1
  import setuptools
2
 
3
+ with open("README.md", "r", encoding="utf-8") as f:
4
  long_description = f.read()
5
+
6
  __version__ = "0.0.0"
7
 
8
  REPO_NAME = "AI_Summarizer"
 
17
  author_email=AUTHOR_EMAIL,
18
  description="A Small python package for Text NLP App",
19
  long_description=long_description,
20
+ long_description_content_type="text/markdown",
21
  url=f"https://github.com/{AUTHOR_USER_NAME}/{REPO_NAME}",
22
  project_urls={
23
  "Bug Tracker": f"https://github.com/{AUTHOR_USER_NAME}/{REPO_NAME}/issues",
24
  },
25
  package_dir={"": "src"},
26
+ packages=setuptools.find_packages(where="src"),
27
+ python_requires=">=3.11, <3.14",
28
+ classifiers=[
29
+ "Programming Language :: Python :: 3",
30
+ "Programming Language :: Python :: 3 :: Only",
31
+ "License :: OSI Approved :: MIT License",
32
+ "Operating System :: OS Independent",
33
+ ],
34
  )
src/textSummarizer/components/data_transformation.py CHANGED
@@ -7,7 +7,12 @@ from textSummarizer.entity import DataTransformationConfig
7
  class DataTransformation:
8
  def __init__(self, config: DataTransformationConfig):
9
  self.config = config
10
- self.tokenizer = AutoTokenizer.from_pretrained(self.config.tokenizer_name)
 
 
 
 
 
11
 
12
  def convert_examples_to_features(self, example_batch):
13
  input_encodings = self.tokenizer(
@@ -31,6 +36,13 @@ class DataTransformation:
31
  dataset_samsum = load_from_disk(str(self.config.data_path))
32
  logger.info("Tokenizing dataset...")
33
  dataset_samsum_pt = dataset_samsum.map(self.convert_examples_to_features, batched=True)
 
 
 
 
 
 
 
34
  save_path = self.config.root_dir / "samsum_dataset"
35
  os.makedirs(save_path, exist_ok=True)
36
  logger.info(f"Saving processed dataset to {save_path}")
 
7
  class DataTransformation:
8
  def __init__(self, config: DataTransformationConfig):
9
  self.config = config
10
+ # choose tokenizer checkpoint: prefer dev_model when dev_run is enabled
11
+ tokenizer_checkpoint = self.config.tokenizer_name
12
+ if getattr(self.config, 'dev_run', False) and getattr(self.config, 'dev_model', None):
13
+ tokenizer_checkpoint = self.config.dev_model
14
+
15
+ self.tokenizer = AutoTokenizer.from_pretrained(tokenizer_checkpoint)
16
 
17
  def convert_examples_to_features(self, example_batch):
18
  input_encodings = self.tokenizer(
 
36
  dataset_samsum = load_from_disk(str(self.config.data_path))
37
  logger.info("Tokenizing dataset...")
38
  dataset_samsum_pt = dataset_samsum.map(self.convert_examples_to_features, batched=True)
39
+
40
+ # ensure labels are correctly formatted for seq2seq Trainer
41
+ def rename_for_trainer(batch):
42
+ # already returns 'labels' in convert_examples_to_features; keep
43
+ return batch
44
+
45
+ dataset_samsum_pt = dataset_samsum_pt.map(rename_for_trainer, batched=True)
46
  save_path = self.config.root_dir / "samsum_dataset"
47
  os.makedirs(save_path, exist_ok=True)
48
  logger.info(f"Saving processed dataset to {save_path}")
src/textSummarizer/components/data_validation.py CHANGED
@@ -9,7 +9,7 @@ class DataValidation:
9
  def validate_all_files_exists(self) -> bool:
10
  try:
11
  # Use config for dataset directory
12
- dataset_dir = self.config.root_dir
13
  all_files = set(os.listdir(dataset_dir))
14
 
15
  required_files = set(self.config.ALL_REQUIRED_FILES)
 
9
  def validate_all_files_exists(self) -> bool:
10
  try:
11
  # Use config for dataset directory
12
+ dataset_dir = self.config.data_dir
13
  all_files = set(os.listdir(dataset_dir))
14
 
15
  required_files = set(self.config.ALL_REQUIRED_FILES)
src/textSummarizer/components/model_trainer.py CHANGED
@@ -13,43 +13,45 @@ class ModelTrainer:
13
 
14
  def train(self):
15
  device = "cuda" if torch.cuda.is_available() else "cpu"
16
- tokenizer = AutoTokenizer.from_pretrained(self.config.model_ckpt)
17
- model_pegasus = AutoModelForSeq2SeqLM.from_pretrained(self.config.model_ckpt, use_safetensors=True).to(device)
 
 
 
 
 
18
  seq2seq_data_collator = DataCollatorForSeq2Seq(tokenizer, model=model_pegasus)
19
 
20
- dataset_samsum_pt = load_from_disk(self.config.data_path)
21
-
22
- # trainer_args = TrainingArguments(
23
- # output_dir=self.config.root_dir,
24
- # num_train_epochs=self.config.num_train_epochs,
25
- # warmup_steps=self.config.warmup_steps,
26
- # per_device_train_batch_size=self.config.per_device_train_batch_size,
27
- # per_device_eval_batch_size=self.config.per_device_train_batch_size,
28
- # weight_decay=self.config.weight_decay,
29
- # logging_steps=self.config.logging_steps,
30
- # evaluation_strategy=self.config.evaluation_strategy,
31
- # eval_steps=self.config.eval_steps,
32
- # save_steps=1e6,
33
- # gradient_accumulation_steps=self.config.gradient_accumulation_steps
34
- # )
35
-
36
 
37
  trainer_args = TrainingArguments(
38
  output_dir=self.config.root_dir,
39
- num_train_epochs=1,
40
- warmup_steps=500,
41
- per_device_train_batch_size=1,
42
- per_device_eval_batch_size=1,
43
- weight_decay=0.01,
44
- logging_steps=10
 
 
 
 
45
  )
46
 
47
 
48
 
49
  trainer = Trainer(model=model_pegasus, args=trainer_args,
50
- tokenizer=tokenizer, data_collator=seq2seq_data_collator,
51
- train_dataset=dataset_samsum_pt["test"],
52
- eval_dataset=dataset_samsum_pt["validation"])
53
 
54
  trainer.train()
55
 
 
13
 
14
  def train(self):
15
  device = "cuda" if torch.cuda.is_available() else "cpu"
16
+ # allow dev-run override for a small quick model
17
+ model_checkpoint = self.config.model_ckpt
18
+ if getattr(self.config, 'dev_run', False) and getattr(self.config, 'dev_model', None):
19
+ model_checkpoint = self.config.dev_model
20
+
21
+ tokenizer = AutoTokenizer.from_pretrained(model_checkpoint)
22
+ model_pegasus = AutoModelForSeq2SeqLM.from_pretrained(model_checkpoint).to(device)
23
  seq2seq_data_collator = DataCollatorForSeq2Seq(tokenizer, model=model_pegasus)
24
 
25
+ dataset_samsum_pt = load_from_disk(str(self.config.data_path))
26
+
27
+ # If dev_run is enabled, take small subsets to speed up training
28
+ if getattr(self.config, 'dev_run', False) and getattr(self.config, 'dev_subset', 0) > 0:
29
+ subset = int(self.config.dev_subset)
30
+ for split in ["test", "validation"]:
31
+ if split in dataset_samsum_pt:
32
+ n = min(subset, len(dataset_samsum_pt[split]))
33
+ dataset_samsum_pt[split] = dataset_samsum_pt[split].select(range(n))
 
 
 
 
 
 
 
34
 
35
  trainer_args = TrainingArguments(
36
  output_dir=self.config.root_dir,
37
+ num_train_epochs=self.config.num_train_epochs,
38
+ warmup_steps=self.config.warmup_steps,
39
+ per_device_train_batch_size=self.config.per_device_train_batch_size,
40
+ per_device_eval_batch_size=self.config.per_device_train_batch_size,
41
+ weight_decay=self.config.weight_decay,
42
+ logging_steps=self.config.logging_steps,
43
+ eval_strategy=self.config.eval_strategy,
44
+ eval_steps=self.config.eval_steps,
45
+ save_steps=1e6,
46
+ gradient_accumulation_steps=self.config.gradient_accumulation_steps,
47
  )
48
 
49
 
50
 
51
  trainer = Trainer(model=model_pegasus, args=trainer_args,
52
+ processing_class=tokenizer, data_collator=seq2seq_data_collator,
53
+ train_dataset=dataset_samsum_pt["test"],
54
+ eval_dataset=dataset_samsum_pt["validation"])
55
 
56
  trainer.train()
57
 
src/textSummarizer/config/configuration.py CHANGED
@@ -40,9 +40,10 @@ class ConfigurationManager:
40
  create_directories([config.root_dir])
41
 
42
  data_validation_config = DataValidationConfig(
43
- root_dir=config.root_dir,
44
  STATUS_FILE=config.STATUS_FILE,
45
  ALL_REQUIRED_FILES=config.ALL_REQUIRED_FILES,
 
46
  )
47
 
48
  return data_validation_config
@@ -57,6 +58,8 @@ class ConfigurationManager:
57
  root_dir=Path(config.root_dir),
58
  data_path=Path(config.data_path),
59
  tokenizer_name=config.tokenizer_name, # if this is a path, use Path(); if just a model name, keep as str
 
 
60
  )
61
 
62
  return data_transformation_config
@@ -77,11 +80,33 @@ class ConfigurationManager:
77
  per_device_train_batch_size=params.per_device_train_batch_size,
78
  weight_decay=params.weight_decay,
79
  logging_steps=params.logging_steps,
80
- evaluation_strategy=params.evaluation_strategy,
81
- eval_steps=params.evaluation_strategy,
82
  save_steps=params.save_steps,
83
  gradient_accumulation_steps=params.gradient_accumulation_steps
84
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
85
 
86
  return model_trainer_config
87
 
 
40
  create_directories([config.root_dir])
41
 
42
  data_validation_config = DataValidationConfig(
43
+ root_dir=Path(config.root_dir),
44
  STATUS_FILE=config.STATUS_FILE,
45
  ALL_REQUIRED_FILES=config.ALL_REQUIRED_FILES,
46
+ data_dir=Path(config.data_dir),
47
  )
48
 
49
  return data_validation_config
 
58
  root_dir=Path(config.root_dir),
59
  data_path=Path(config.data_path),
60
  tokenizer_name=config.tokenizer_name, # if this is a path, use Path(); if just a model name, keep as str
61
+ dev_run=getattr(config, 'dev_run', False),
62
+ dev_model=getattr(config, 'dev_model', None),
63
  )
64
 
65
  return data_transformation_config
 
80
  per_device_train_batch_size=params.per_device_train_batch_size,
81
  weight_decay=params.weight_decay,
82
  logging_steps=params.logging_steps,
83
+ eval_strategy=params.eval_strategy,
84
+ eval_steps=params.eval_steps,
85
  save_steps=params.save_steps,
86
  gradient_accumulation_steps=params.gradient_accumulation_steps
87
  )
88
+
89
+ # Optional dev quick-train settings (not all configs will have these)
90
+ try:
91
+ model_trainer_config = ModelTrainerConfig(
92
+ root_dir=Path(config.root_dir),
93
+ data_path=Path(config.data_path),
94
+ model_ckpt=config.model_ckpt,
95
+ num_train_epochs=params.num_train_epochs,
96
+ warmup_steps=params.warmup_steps,
97
+ per_device_train_batch_size=params.per_device_train_batch_size,
98
+ weight_decay=params.weight_decay,
99
+ logging_steps=params.logging_steps,
100
+ eval_strategy=params.eval_strategy,
101
+ eval_steps=params.eval_steps,
102
+ save_steps=params.save_steps,
103
+ gradient_accumulation_steps=params.gradient_accumulation_steps,
104
+ dev_run=getattr(config, 'dev_run', False),
105
+ dev_model=getattr(config, 'dev_model', None),
106
+ dev_subset=int(getattr(config, 'dev_subset', 0))
107
+ )
108
+ except Exception:
109
+ pass
110
 
111
  return model_trainer_config
112
 
src/textSummarizer/entity/__init__.py CHANGED
@@ -14,13 +14,17 @@ class DataValidationConfig:
14
  root_dir : Path
15
  STATUS_FILE : str
16
  ALL_REQUIRED_FILES : list
 
17
 
18
 
19
  @dataclass(frozen=True)
20
  class DataTransformationConfig:
21
  root_dir: Path
22
  data_path: Path
23
- tokenizer_name: Path
 
 
 
24
 
25
 
26
 
@@ -34,10 +38,14 @@ class ModelTrainerConfig:
34
  per_device_train_batch_size: int
35
  weight_decay: float
36
  logging_steps: int
37
- evaluation_strategy: str
38
  eval_steps: int
39
  save_steps: float
40
  gradient_accumulation_steps: int
 
 
 
 
41
 
42
 
43
  @dataclass(frozen=True)
 
14
  root_dir : Path
15
  STATUS_FILE : str
16
  ALL_REQUIRED_FILES : list
17
+ data_dir : Path
18
 
19
 
20
  @dataclass(frozen=True)
21
  class DataTransformationConfig:
22
  root_dir: Path
23
  data_path: Path
24
+ tokenizer_name: str
25
+ # dev quick-run options
26
+ dev_run: bool = False
27
+ dev_model: str | None = None
28
 
29
 
30
 
 
38
  per_device_train_batch_size: int
39
  weight_decay: float
40
  logging_steps: int
41
+ eval_strategy: str
42
  eval_steps: int
43
  save_steps: float
44
  gradient_accumulation_steps: int
45
+ # dev / quick-train options
46
+ dev_run: bool = False
47
+ dev_model: str | None = None
48
+ dev_subset: int = 0
49
 
50
 
51
  @dataclass(frozen=True)
src/textSummarizer/utils/common.py CHANGED
@@ -2,12 +2,10 @@ import os
2
  from box.exceptions import BoxValueError
3
  import yaml
4
  from textSummarizer.logging import logger
5
- from ensure import ensure_annotations
6
  from box import ConfigBox
7
  from pathlib import Path
8
  from typing import Any
9
 
10
- @ensure_annotations
11
  def read_yaml(path_to_yaml: Path) -> ConfigBox:
12
  """_summary_
13
  Read YAML file and convert it into a ConfigBox object.
@@ -36,8 +34,7 @@ def read_yaml(path_to_yaml: Path) -> ConfigBox:
36
  raise e
37
 
38
 
39
- @ensure_annotations
40
- def create_directories(path_to_directories: list, verbose=True):
41
  """
42
  create list of directories
43
 
@@ -50,8 +47,7 @@ def create_directories(path_to_directories: list, verbose=True):
50
  if verbose:
51
  logger.info(f"created directory at path : {path}")
52
 
53
- @ensure_annotations
54
- def get_size(path: Path) ->str:
55
  """get size of file in kbs
56
 
57
  Args:
 
2
  from box.exceptions import BoxValueError
3
  import yaml
4
  from textSummarizer.logging import logger
 
5
  from box import ConfigBox
6
  from pathlib import Path
7
  from typing import Any
8
 
 
9
  def read_yaml(path_to_yaml: Path) -> ConfigBox:
10
  """_summary_
11
  Read YAML file and convert it into a ConfigBox object.
 
34
  raise e
35
 
36
 
37
+ def create_directories(path_to_directories: list, verbose: bool = True) -> None:
 
38
  """
39
  create list of directories
40
 
 
47
  if verbose:
48
  logger.info(f"created directory at path : {path}")
49
 
50
+ def get_size(path: Path) -> str:
 
51
  """get size of file in kbs
52
 
53
  Args:
template.py CHANGED
@@ -1,10 +1,9 @@
1
- import os
2
  from pathlib import Path
3
  import logging
4
 
5
- logging.basicConfig(level=logging.INFO, format='[%(asctime)s]:(message)s:')
6
 
7
- project_name = "testSummarizer"
8
 
9
  list_of_files = [
10
  ".github/workflows/.gitkeep",
@@ -25,22 +24,20 @@ list_of_files = [
25
  "Dockerfile",
26
  "requirements.txt",
27
  "setup.py",
28
- "research/trails.ipynb"
29
-
30
  ]
31
 
32
  for filepath in list_of_files:
33
- filepath = Path(filepath)
34
- filedir, filename = os.path.split(filepath)
35
-
36
- if filedir != "":
37
- os.makedirs(filedir, exist_ok=True)
38
- logging.info(f"Creating directry:{filepath} for the file {filepath}")
39
-
40
- if (not os.path.exists(filepath)) or (os.path.getsize(filepath) == 0):
41
- with open(filepath, 'w') as f:
42
- pass
43
- logging.info(f"Creating empty file: {filepath}")
44
-
45
- else :
46
- logging.info(f"{filename} is already exists.")
 
 
1
  from pathlib import Path
2
  import logging
3
 
4
+ logging.basicConfig(level=logging.INFO, format="[%(asctime)s]: %(message)s")
5
 
6
+ project_name = "textSummarizer"
7
 
8
  list_of_files = [
9
  ".github/workflows/.gitkeep",
 
24
  "Dockerfile",
25
  "requirements.txt",
26
  "setup.py",
27
+ "research/trails.ipynb",
 
28
  ]
29
 
30
  for filepath in list_of_files:
31
+ fp = Path(filepath)
32
+ filedir = fp.parent
33
+ filename = fp.name
34
+
35
+ if filedir and str(filedir) != ".":
36
+ filedir.mkdir(parents=True, exist_ok=True)
37
+ logging.info(f"Creating directory: {filedir} for the file {filename}")
38
+
39
+ if not fp.exists() or fp.stat().st_size == 0:
40
+ fp.touch(exist_ok=True)
41
+ logging.info(f"Created empty file: {fp}")
42
+ else:
43
+ logging.info(f"{filename} already exists.")