Update app.py
Browse files
app.py
CHANGED
|
@@ -12,20 +12,20 @@ class SoilInput(BaseModel):
|
|
| 12 |
|
| 13 |
@validator('cement_perecent')
|
| 14 |
def validate_cement(cls, v):
|
| 15 |
-
if not
|
| 16 |
-
raise ValueError("Procentul de ciment trebuie să fie între
|
| 17 |
return v
|
| 18 |
|
| 19 |
@validator('curing_period')
|
| 20 |
def validate_curing(cls, v):
|
| 21 |
if not 1 <= v <= 90:
|
| 22 |
-
raise ValueError("Perioada de maturare trebuie să fie între
|
| 23 |
return v
|
| 24 |
|
| 25 |
@validator('compaction_rate')
|
| 26 |
def validate_compaction(cls, v):
|
| 27 |
if not 0.5 <= v <= 1.5:
|
| 28 |
-
raise ValueError("Viteza de compactare trebuie să fie între 0.
|
| 29 |
return v
|
| 30 |
|
| 31 |
app = FastAPI()
|
|
@@ -41,7 +41,7 @@ except Exception as e:
|
|
| 41 |
@app.post("/predict")
|
| 42 |
async def predict(soil_data: SoilInput):
|
| 43 |
"""
|
| 44 |
-
Realizează predicții pentru UCS
|
| 45 |
"""
|
| 46 |
try:
|
| 47 |
# Construim DataFrame-ul pentru predicție
|
|
@@ -49,11 +49,11 @@ async def predict(soil_data: SoilInput):
|
|
| 49 |
input_df = pd.DataFrame([input_data])
|
| 50 |
|
| 51 |
# Ne asigurăm că ordinea coloanelor este corectă
|
| 52 |
-
|
| 53 |
-
|
| 54 |
|
| 55 |
expected_features = model.feature_names_in_ # Extrage ordinea corectă din model
|
| 56 |
-
|
| 57 |
|
| 58 |
# Facem predicția
|
| 59 |
prediction = model.predict(input_df)
|
|
@@ -67,9 +67,31 @@ async def predict(soil_data: SoilInput):
|
|
| 67 |
except Exception as e:
|
| 68 |
raise HTTPException(status_code=400, detail=str(e))
|
| 69 |
|
| 70 |
-
@app.get("/")
|
| 71 |
async def root():
|
| 72 |
"""
|
| 73 |
Endpoint pentru verificarea stării API-ului
|
| 74 |
"""
|
| 75 |
-
return {"status": "API is running", "model_loaded": model is not None}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
@validator('cement_perecent')
|
| 14 |
def validate_cement(cls, v):
|
| 15 |
+
if not 0 <= v <= 15:
|
| 16 |
+
raise ValueError("Procentul de ciment trebuie să fie între 0% și 15%")
|
| 17 |
return v
|
| 18 |
|
| 19 |
@validator('curing_period')
|
| 20 |
def validate_curing(cls, v):
|
| 21 |
if not 1 <= v <= 90:
|
| 22 |
+
raise ValueError("Perioada de maturare trebuie să fie între 1 și 90 zile")
|
| 23 |
return v
|
| 24 |
|
| 25 |
@validator('compaction_rate')
|
| 26 |
def validate_compaction(cls, v):
|
| 27 |
if not 0.5 <= v <= 1.5:
|
| 28 |
+
raise ValueError("Viteza de compactare trebuie să fie între 0.5 și 1.5 mm/min")
|
| 29 |
return v
|
| 30 |
|
| 31 |
app = FastAPI()
|
|
|
|
| 41 |
@app.post("/predict")
|
| 42 |
async def predict(soil_data: SoilInput):
|
| 43 |
"""
|
| 44 |
+
Realizează predicții pentru UCS
|
| 45 |
"""
|
| 46 |
try:
|
| 47 |
# Construim DataFrame-ul pentru predicție
|
|
|
|
| 49 |
input_df = pd.DataFrame([input_data])
|
| 50 |
|
| 51 |
# Ne asigurăm că ordinea coloanelor este corectă
|
| 52 |
+
feature_order = ['cement_perecent', 'curing_period', 'compaction_rate']
|
| 53 |
+
input_df = input_df[feature_order]
|
| 54 |
|
| 55 |
expected_features = model.feature_names_in_ # Extrage ordinea corectă din model
|
| 56 |
+
# input_df = input_df[expected_features] # Reordonează caracteristicile
|
| 57 |
|
| 58 |
# Facem predicția
|
| 59 |
prediction = model.predict(input_df)
|
|
|
|
| 67 |
except Exception as e:
|
| 68 |
raise HTTPException(status_code=400, detail=str(e))
|
| 69 |
|
| 70 |
+
@app.get("/status")
|
| 71 |
async def root():
|
| 72 |
"""
|
| 73 |
Endpoint pentru verificarea stării API-ului
|
| 74 |
"""
|
| 75 |
+
return {"status": "API is running", "model_loaded": model is not None}
|
| 76 |
+
|
| 77 |
+
@app.get("/model-info")
|
| 78 |
+
async def model_info():
|
| 79 |
+
"""
|
| 80 |
+
Endpoint pentru informații despre model
|
| 81 |
+
"""
|
| 82 |
+
return {
|
| 83 |
+
"model_type": "Random Forest Regressor",
|
| 84 |
+
"features": FEATURE_ORDER,
|
| 85 |
+
"target": "UCS (kPa)",
|
| 86 |
+
"valid_ranges": {
|
| 87 |
+
"cement_perecent": {"min": 0, "max": 10, "units": "%"},
|
| 88 |
+
"curing_period": {"min": 1, "max": 90, "units": "days"},
|
| 89 |
+
"compaction_rate": {"min": 0.5, "max": 1.5, "units": "mm/min"}
|
| 90 |
+
},
|
| 91 |
+
"model_parameters": {
|
| 92 |
+
"n_estimators": 205,
|
| 93 |
+
"max_depth": 11,
|
| 94 |
+
"min_samples_split": 6,
|
| 95 |
+
"min_samples_leaf": 2
|
| 96 |
+
}
|
| 97 |
+
}
|