Spaces:
Runtime error
Runtime error
Update main.py
Browse files
main.py
CHANGED
|
@@ -5,6 +5,7 @@ import uvicorn
|
|
| 5 |
import numpy as np
|
| 6 |
from projects.DL_CatDog.DL_CatDog import preprocess_image, read_image, model_DL_CatDog
|
| 7 |
from projects.ML_StudentPerformance.ML_StudentPerformace import predict_student_performance, create_custom_data, form1
|
|
|
|
| 8 |
|
| 9 |
app = FastAPI()
|
| 10 |
|
|
@@ -34,7 +35,7 @@ async def predict_DL_CatDog(file: UploadFile = File(...)):
|
|
| 34 |
except Exception as e:
|
| 35 |
return JSONResponse(content={"ok": -1, "message": f"Something went wrong! {str(e)}"}, status_code=500)
|
| 36 |
|
| 37 |
-
#
|
| 38 |
@app.post("/api/predict2")
|
| 39 |
async def predict_student_performance_api(request: form1):
|
| 40 |
print(request, end='\n\n\n\n')
|
|
@@ -55,6 +56,26 @@ async def predict_student_performance_api(request: form1):
|
|
| 55 |
except Exception as e:
|
| 56 |
return JSONResponse(content={"ok": -1, "message": f"Something went wrong! {str(e)}"}, status_code=500)
|
| 57 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
# Main function to run the FastAPI server
|
| 59 |
if __name__ == "__main__":
|
| 60 |
uvicorn.run(app, host="0.0.0.0", port=7860)
|
|
|
|
| 5 |
import numpy as np
|
| 6 |
from projects.DL_CatDog.DL_CatDog import preprocess_image, read_image, model_DL_CatDog
|
| 7 |
from projects.ML_StudentPerformance.ML_StudentPerformace import predict_student_performance, create_custom_data, form1
|
| 8 |
+
from projects.ML_DiabetesPrediction.ML_DiabetesPrediction import model_ML_DiabetesPrediction, form2
|
| 9 |
|
| 10 |
app = FastAPI()
|
| 11 |
|
|
|
|
| 35 |
except Exception as e:
|
| 36 |
return JSONResponse(content={"ok": -1, "message": f"Something went wrong! {str(e)}"}, status_code=500)
|
| 37 |
|
| 38 |
+
# Prediction route for ML_StudentPerformance
|
| 39 |
@app.post("/api/predict2")
|
| 40 |
async def predict_student_performance_api(request: form1):
|
| 41 |
print(request, end='\n\n\n\n')
|
|
|
|
| 56 |
except Exception as e:
|
| 57 |
return JSONResponse(content={"ok": -1, "message": f"Something went wrong! {str(e)}"}, status_code=500)
|
| 58 |
|
| 59 |
+
# Prediction route for ML_DiabetesPrediction
|
| 60 |
+
@app.post("/api/predict3")
|
| 61 |
+
async def predict_student_performance_api(req: form2):
|
| 62 |
+
try:
|
| 63 |
+
input_data = (req.Pregnancies, req.Glucose, req.BloodPressure, req.SkinThickness, req.Insulin, req.BMI, req.DiabetesPedigreeFunction, req.Age)
|
| 64 |
+
|
| 65 |
+
# changing the input_data to numpy array
|
| 66 |
+
input_data_as_numpy_array = np.asarray(input_data)
|
| 67 |
+
|
| 68 |
+
# reshape the array as we are predicting for one instance
|
| 69 |
+
input_data_reshaped = input_data_as_numpy_array.reshape(1,-1)
|
| 70 |
+
|
| 71 |
+
# Perform the prediction
|
| 72 |
+
prediction = model_ML_DiabetesPrediction.predict(input_data_reshaped)
|
| 73 |
+
|
| 74 |
+
return JSONResponse(content={"ok": 1, "prediction": prediction[0]})
|
| 75 |
+
except Exception as e:
|
| 76 |
+
return JSONResponse(content={"ok": -1, "message": f"Something went wrong! {str(e)}"}, status_code=500)
|
| 77 |
+
|
| 78 |
+
|
| 79 |
# Main function to run the FastAPI server
|
| 80 |
if __name__ == "__main__":
|
| 81 |
uvicorn.run(app, host="0.0.0.0", port=7860)
|