sdafd commited on
Commit
bdc28b7
·
verified ·
1 Parent(s): d602a73

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -2
app.py CHANGED
@@ -1,4 +1,5 @@
1
  from fastapi import FastAPI, UploadFile, File, HTTPException
 
2
  from tensorflow.keras.models import load_model, Sequential
3
  from tensorflow.keras.layers import Dense, LSTM
4
  from tensorflow.keras.optimizers import Adam
@@ -65,8 +66,13 @@ async def retrain(model: UploadFile = File(...), data: str = None):
65
  updated_model_path = temp_model_path.replace(".h5", "_updated.h5")
66
  model.save(updated_model_path)
67
 
68
- return {"message": "Model retrained successfully.", "updated_model_path": updated_model_path}
69
-
 
 
 
 
 
70
  except Exception as e:
71
  raise HTTPException(status_code=500, detail=str(e))
72
  finally:
 
1
  from fastapi import FastAPI, UploadFile, File, HTTPException
2
+ from fastapi.responses import FileResponse
3
  from tensorflow.keras.models import load_model, Sequential
4
  from tensorflow.keras.layers import Dense, LSTM
5
  from tensorflow.keras.optimizers import Adam
 
66
  updated_model_path = temp_model_path.replace(".h5", "_updated.h5")
67
  model.save(updated_model_path)
68
 
69
+ # Return the path for downloading
70
+ return FileResponse(
71
+ path=updated_model_path,
72
+ filename="updated_model.h5",
73
+ media_type="application/octet-stream",
74
+ headers={"Content-Disposition": "attachment; filename=updated_model.h5"}
75
+ )
76
  except Exception as e:
77
  raise HTTPException(status_code=500, detail=str(e))
78
  finally: