MorganBrizon commited on
Commit
4db6683
·
verified ·
1 Parent(s): 8ee418c

Delete app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -43
app.py DELETED
@@ -1,43 +0,0 @@
1
- import os
2
- import tempfile
3
- from fastapi import FastAPI, UploadFile, File, HTTPException
4
- from fastapi.responses import JSONResponse
5
- import tensorflow as tf
6
- from prediction import predict_eeg_recording
7
-
8
- app = FastAPI(title="EEG Epilepsy Prediction API")
9
- model = tf.keras.models.load_model('model1_2dcnn.h5')
10
-
11
- # ✅ Ajout du endpoint GET /
12
- @app.get("/")
13
- async def root():
14
- return {"message": "Bienvenue sur l'API EEG Epilepsy. Utilisez POST /predict pour soumettre un fichier EDF."}
15
-
16
- @app.post("/predict")
17
- async def predict_endpoint(file: UploadFile = File(...)):
18
- try:
19
- suffix = os.path.splitext(file.filename)[1]
20
- with tempfile.NamedTemporaryFile(delete=False, suffix=suffix) as tmp:
21
- tmp.write(await file.read())
22
- tmp_path = tmp.name
23
- except Exception:
24
- raise HTTPException(status_code=500, detail="Erreur lors de la sauvegarde temporaire")
25
-
26
- try:
27
- label, mean_prob, segment_probs = predict_eeg_recording(tmp_path, model, threshold=0.5)
28
- except Exception as e:
29
- os.remove(tmp_path)
30
- raise HTTPException(status_code=400, detail=f"Erreur prédiction : {e}")
31
-
32
- os.remove(tmp_path)
33
-
34
- response = {
35
- "prediction": "epilepsy" if label == 1 else "no epilepsy",
36
- "mean_probability": float(mean_prob),
37
- "segment_probabilities": [float(p) for p in segment_probs]
38
- }
39
- return JSONResponse(content=response)
40
-
41
- if __name__ == "__main__":
42
- import uvicorn
43
- uvicorn.run("app:app", host="0.0.0.0", port=7860, reload=True)