surbi karki commited on
Commit
de77399
·
verified ·
1 Parent(s): 65fa3ca

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -13
app.py CHANGED
@@ -3,7 +3,6 @@ from fastapi import FastAPI, HTTPException
3
  from pydantic import BaseModel
4
  import joblib
5
  import numpy as np
6
- import pandas as pd
7
 
8
  # Load the trained model and scaler
9
  try:
@@ -41,21 +40,15 @@ class PCOSPrediction(BaseModel):
41
  prediction: int
42
  probability: float
43
 
44
- # Feature names for the model
45
- feature_names = ['Follicle_No_R', 'Follicle_No_L', 'Skin_darkening', 'hair_growth',
46
- 'Weight_gain', 'Cycle_length', 'AMH', 'Fast_food', 'Cycle_R_I',
47
- 'FSH_LH', 'PRL', 'Pimples', 'Age', 'BMI']
48
-
49
  # Define the prediction endpoint
50
  @app.post("/predict/", response_model=PCOSPrediction)
51
  def predict(data: PCOSInput):
52
  try:
53
- # Convert input data to a DataFrame with feature names
54
- input_data = pd.DataFrame([[data.Follicle_No_R, data.Follicle_No_L, data.Skin_darkening,
55
- data.hair_growth, data.Weight_gain, data.Cycle_length, data.AMH,
56
- data.Fast_food, data.Cycle_R_I, data.FSH_LH, data.PRL, data.Pimples,
57
- data.Age, data.BMI]], columns=feature_names)
58
-
59
  # Scale the input data using the loaded scaler
60
  scaled_input = scaler.transform(input_data)
61
 
@@ -65,4 +58,4 @@ def predict(data: PCOSInput):
65
 
66
  return PCOSPrediction(prediction=int(prediction[0]), probability=probability)
67
  except Exception as e:
68
- raise HTTPException(status_code=500, detail=f"Prediction error: {e}")
 
3
  from pydantic import BaseModel
4
  import joblib
5
  import numpy as np
 
6
 
7
  # Load the trained model and scaler
8
  try:
 
40
  prediction: int
41
  probability: float
42
 
 
 
 
 
 
43
  # Define the prediction endpoint
44
  @app.post("/predict/", response_model=PCOSPrediction)
45
  def predict(data: PCOSInput):
46
  try:
47
+ # Convert input data to array
48
+ input_data = np.array([[data.Follicle_No_R, data.Follicle_No_L, data.Skin_darkening, data.hair_growth,
49
+ data.Weight_gain, data.Cycle_length, data.AMH, data.Fast_food, data.Cycle_R_I,
50
+ data.FSH_LH, data.PRL, data.Pimples, data.Age, data.BMI]])
51
+
 
52
  # Scale the input data using the loaded scaler
53
  scaled_input = scaler.transform(input_data)
54
 
 
58
 
59
  return PCOSPrediction(prediction=int(prediction[0]), probability=probability)
60
  except Exception as e:
61
+ raise HTTPException(status_code=500, detail=f"Prediction error: {e}")