Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -12,6 +12,7 @@ from fastapi.middleware.cors import CORSMiddleware
|
|
| 12 |
|
| 13 |
# Load your trained model
|
| 14 |
model = tf.keras.models.load_model('recyclebot.keras')
|
|
|
|
| 15 |
|
| 16 |
# Define class names for predictions (this should be the same as in your local code)
|
| 17 |
CLASSES = ['Glass', 'Metal', 'Paperboard', 'Plastic-Polystyrene', 'Plastic-Regular']
|
|
@@ -55,10 +56,15 @@ def preprocess_image(image_file):
|
|
| 55 |
async def predict(file: UploadFile = File(...)): #async def predict(request: Request, file: UploadFile = File(...)):
|
| 56 |
try:
|
| 57 |
img_array = preprocess_image(file.file) # Preprocess the image
|
| 58 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
|
|
|
|
| 60 |
# Get the index of the highest probability class (like np.argmax on local machine)
|
| 61 |
-
predicted_class_idx = np.argmax(
|
| 62 |
|
| 63 |
# Map the predicted index to the class name (like final_class = CLASSES[np.argmax(final_preds)])
|
| 64 |
predicted_class = CLASSES[predicted_class_idx] # Convert to class name
|
|
@@ -72,7 +78,7 @@ async def predict(file: UploadFile = File(...)): #async def predict(request: R
|
|
| 72 |
|
| 73 |
@app.get("/working")
|
| 74 |
async def working():
|
| 75 |
-
return JSONResponse(content={"
|
| 76 |
|
| 77 |
|
| 78 |
|
|
|
|
| 12 |
|
| 13 |
# Load your trained model
|
| 14 |
model = tf.keras.models.load_model('recyclebot.keras')
|
| 15 |
+
model2 = tf.keras.models.load_model('78-76.keras')
|
| 16 |
|
| 17 |
# Define class names for predictions (this should be the same as in your local code)
|
| 18 |
CLASSES = ['Glass', 'Metal', 'Paperboard', 'Plastic-Polystyrene', 'Plastic-Regular']
|
|
|
|
| 56 |
async def predict(file: UploadFile = File(...)): #async def predict(request: Request, file: UploadFile = File(...)):
|
| 57 |
try:
|
| 58 |
img_array = preprocess_image(file.file) # Preprocess the image
|
| 59 |
+
prediction1 = model.predict(img_array) # Get predictions
|
| 60 |
+
prediction1 = model2.predict(img_array) # Get predictions
|
| 61 |
+
|
| 62 |
+
weight_1 = 0.6
|
| 63 |
+
weight_2 = 0.4
|
| 64 |
|
| 65 |
+
final_preds = final_preds = (weight_1 * prediction1 + weight_2 * prediction2)
|
| 66 |
# Get the index of the highest probability class (like np.argmax on local machine)
|
| 67 |
+
predicted_class_idx = np.argmax(final_preds, axis=1)[0] # Get predicted class index
|
| 68 |
|
| 69 |
# Map the predicted index to the class name (like final_class = CLASSES[np.argmax(final_preds)])
|
| 70 |
predicted_class = CLASSES[predicted_class_idx] # Convert to class name
|
|
|
|
| 78 |
|
| 79 |
@app.get("/working")
|
| 80 |
async def working():
|
| 81 |
+
return JSONResponse(content={"Status": "Working"})
|
| 82 |
|
| 83 |
|
| 84 |
|