Spaces:
Running
Running
Update main.py
Browse files
main.py
CHANGED
@@ -34,7 +34,8 @@ plant_disease_dict = {
|
|
34 |
"Corn": ['Corn___Cercospora_leaf_spot Gray_leaf_spot', 'Corn___Common_rust',
|
35 |
'Corn___Northern_Leaf_Blight', 'Corn___healthy']
|
36 |
}
|
37 |
-
|
|
|
38 |
# Custom Self-Attention Layer
|
39 |
@tf.keras.utils.register_keras_serializable()
|
40 |
class SelfAttention(Layer):
|
@@ -100,7 +101,10 @@ async def predict_plant_disease(plant_name: str, file: UploadFile = File(...)):
|
|
100 |
raise HTTPException(status_code=404, detail=f"Model file '{plant_name}_model.keras' not found")
|
101 |
|
102 |
# Save uploaded file temporarily
|
103 |
-
|
|
|
|
|
|
|
104 |
with open(temp_path, "wb") as buffer:
|
105 |
shutil.copyfileobj(file.file, buffer)
|
106 |
|
|
|
34 |
"Corn": ['Corn___Cercospora_leaf_spot Gray_leaf_spot', 'Corn___Common_rust',
|
35 |
'Corn___Northern_Leaf_Blight', 'Corn___healthy']
|
36 |
}
|
37 |
+
TMP_DIR = os.getenv("TMP_DIR", "/app/temp")
|
38 |
+
os.makedirs(TMP_DIR, exist_ok=True)
|
39 |
# Custom Self-Attention Layer
|
40 |
@tf.keras.utils.register_keras_serializable()
|
41 |
class SelfAttention(Layer):
|
|
|
101 |
raise HTTPException(status_code=404, detail=f"Model file '{plant_name}_model.keras' not found")
|
102 |
|
103 |
# Save uploaded file temporarily
|
104 |
+
|
105 |
+
|
106 |
+
# Define the temp file path
|
107 |
+
temp_path = os.path.join(TMP_DIR, file.filename)
|
108 |
with open(temp_path, "wb") as buffer:
|
109 |
shutil.copyfileobj(file.file, buffer)
|
110 |
|