Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,6 +3,7 @@ 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
|
|
|
|
| 6 |
from sklearn.preprocessing import MinMaxScaler
|
| 7 |
import numpy as np
|
| 8 |
import tempfile
|
|
@@ -30,11 +31,12 @@ async def predict(model: UploadFile = File(...), data: str = None):
|
|
| 30 |
print(data)
|
| 31 |
# Process the data
|
| 32 |
predictions = model.predict(ds_normalized.reshape(1, 12, 1)).tolist()
|
| 33 |
-
predictions_rescaled = scaler.inverse_transform(
|
| 34 |
|
| 35 |
-
return {"predictions":
|
| 36 |
|
| 37 |
except Exception as e:
|
|
|
|
| 38 |
raise HTTPException(status_code=500, detail=str(e))
|
| 39 |
|
| 40 |
@app.post("/retrain")
|
|
@@ -74,6 +76,7 @@ async def retrain(model: UploadFile = File(...), data: str = None):
|
|
| 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:
|
| 79 |
# Clean up temporary files
|
|
|
|
| 3 |
from tensorflow.keras.models import load_model, Sequential
|
| 4 |
from tensorflow.keras.layers import Dense, LSTM
|
| 5 |
from tensorflow.keras.optimizers import Adam
|
| 6 |
+
import traceback
|
| 7 |
from sklearn.preprocessing import MinMaxScaler
|
| 8 |
import numpy as np
|
| 9 |
import tempfile
|
|
|
|
| 31 |
print(data)
|
| 32 |
# Process the data
|
| 33 |
predictions = model.predict(ds_normalized.reshape(1, 12, 1)).tolist()
|
| 34 |
+
predictions_rescaled = scaler.inverse_transform(predictions).flatten()
|
| 35 |
|
| 36 |
+
return {"predictions": predictions}
|
| 37 |
|
| 38 |
except Exception as e:
|
| 39 |
+
print(traceback.format_exc())
|
| 40 |
raise HTTPException(status_code=500, detail=str(e))
|
| 41 |
|
| 42 |
@app.post("/retrain")
|
|
|
|
| 76 |
headers={"Content-Disposition": "attachment; filename=updated_model.h5"}
|
| 77 |
)
|
| 78 |
except Exception as e:
|
| 79 |
+
print(traceback.format_exc())
|
| 80 |
raise HTTPException(status_code=500, detail=str(e))
|
| 81 |
finally:
|
| 82 |
# Clean up temporary files
|