Delete app/main.py
Browse files- app/main.py +0 -40
app/main.py
DELETED
|
@@ -1,40 +0,0 @@
|
|
| 1 |
-
|
| 2 |
-
from fastapi import FastAPI, HTTPException, File, UploadFile
|
| 3 |
-
from fastapi.responses import FileResponse
|
| 4 |
-
from app.services.preprocessing import data_quality, standardize_data_types, handle_missing_data, handle_outliers, generate_final_report, save_cleaned_data
|
| 5 |
-
import pandas as pd
|
| 6 |
-
import io
|
| 7 |
-
import os
|
| 8 |
-
|
| 9 |
-
app = FastAPI(title="Data Preprocessing")
|
| 10 |
-
os.makedirs("output", exist_ok=True)
|
| 11 |
-
|
| 12 |
-
@app.get("/")
|
| 13 |
-
async def root():
|
| 14 |
-
return {"message": "Welcome to the Data Preprocessing API!"}
|
| 15 |
-
|
| 16 |
-
@app.post("/preprocess_data/")
|
| 17 |
-
async def upload_csv(upload_file: UploadFile = File(...)):
|
| 18 |
-
try:
|
| 19 |
-
if not upload_file.filename.endswith('.csv'):
|
| 20 |
-
raise HTTPException(status_code=400, detail="File must be in CSV format!")
|
| 21 |
-
content = await upload_file.read()
|
| 22 |
-
df = pd.read_csv(io.BytesIO(content), encoding_errors="replace")
|
| 23 |
-
if df.empty:
|
| 24 |
-
raise HTTPException(status_code=400, detail="File is empty, upload the correct file")
|
| 25 |
-
|
| 26 |
-
data_quality(df)
|
| 27 |
-
df = standardize_data_types(df)
|
| 28 |
-
df = handle_missing_data(df)
|
| 29 |
-
df = handle_outliers(df)
|
| 30 |
-
|
| 31 |
-
REPORT_PATH = "output/preprocessing_report.txt"
|
| 32 |
-
generate_final_report(df, REPORT_PATH)
|
| 33 |
-
|
| 34 |
-
CLEANED_DATA_PATH = "output/cleaned_dataset.csv"
|
| 35 |
-
save_cleaned_data(df, CLEANED_DATA_PATH)
|
| 36 |
-
|
| 37 |
-
return FileResponse(CLEANED_DATA_PATH, media_type="text/csv", filename="cleaned_dataset.csv")
|
| 38 |
-
|
| 39 |
-
except Exception as e:
|
| 40 |
-
raise HTTPException(status_code=400, detail=f"Error processing file: {str(e)}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|