# --- Part 2.1: Project Structure ---
p21 = """# Project Structure (Create these files manually)

PRAC_2/
│── config/
│   └── config.yaml
│
│── data/
│   ├── raw/
│   └── processed/
│
│── logs/
│
│── models/
│
│── src/
│   ├── data_ingestion.py
│   ├── train.py
│   ├── evaluate.py
│   └── logger.py
│
│── requirements.txt
│── README.md
"""

# --- Part 2.2: requirements.txt ---
p22 = """# File: requirements.txt

pandas
joblib
scikit-learn
pyyaml
"""

# --- Part 2.3: config/config.yaml ---
p23 = """# File: config/config.yaml

data:
  raw_path: "data/raw/diabetes.csv"
  processed_path: "data/processed/diabetes_processed.csv"

model:
  path: "models/linear_model.pkl"

logging:
  log_file: "logs/project.log"
"""

# --- Part 2.4: src/data_ingestion.py ---
p24 = """# File: src/data_ingestion.py

import pandas as pd
from sklearn.datasets import load_diabetes
import yaml
from logger import get_logger

def load_config():
    with open("config/config.yaml") as f:
        return yaml.safe_load()

def load_and_process_data():

    config = load_config()
    logger = get_logger(config["logging"]["log_file"])

    logger.info("Starting data ingestion")

    data = load_diabetes(as_frame=True)
    df = data.frame

    df.to_csv(config['data']['raw_path'], index=False)
    df.to_csv(config['data']['processed_path'], index=False)

if __name__ == '__main__':
    load_and_process_data()
"""

# --- Part 2.5: src/train.py ---
p25 = """# File: src/train.py

import pandas as pd
from sklearn.linear_model import LinearRegression
import joblib

def train_model():

    df = pd.read_csv("data/processed/diabetes_processed.csv")
    X = df.drop("target", axis=1)
    y = df['target']

    model = LinearRegression()
    model.fit(X, y)

    joblib.dump(model, "models/linear_model.pkl")

    print("Model training completed")

if __name__ == '__main__':
    train_model()
"""

# --- Part 2.6: src/evaluate.py ---
p26 = """# File: src/evaluate.py

import pandas as pd
import joblib
from sklearn.metrics import mean_squared_error

def evaluate_model():
    df = pd.read_csv("data/processed/diabetes_processed.csv")
    X = df.drop("target", axis=1)
    y = df["target"]

    model = joblib.load("models/linear_model.pkl")
    predictions = model.predict(X)

    mse = mean_squared_error(y, predictions)
    print("Model MSE: ", mse)

if __name__ == '__main__':
    evaluate_model()
"""

# --- Part 2.7: src/logger.py ---
p27 = """# File: src/logger.py

import logging
import os

def get_logger(log_file):
    os.makedirs(os.path.dirname(log_file), exist_ok=True)

    logging.basicConfig(
        filename=log_file,
        level=logging.INFO,
        format="%(asctime)s - %(levelname)s - %(message)s",
    )

    return logging.getLogger()
"""

# --- Part 2.8: README.md ---
p28 = """# File: README.md

# MLOPS PRACTICAL

This is MLOps practical demonstrating a basic ML pipeline.

# Steps
1. Data ingestion
2. Model training
3. Model evaluation

## How to run
python src/data_ingestion.py
python src/train.py
python src/evaluate.py
"""