Spaces:
Running
Running
Update main.py
Browse files
main.py
CHANGED
@@ -81,8 +81,8 @@ def preprocess_image(image_data, img_size=224):
|
|
81 |
def predict_image(image_data):
|
82 |
preprocessed_image = preprocess_image(image_data)
|
83 |
predictions = model.predict(preprocessed_image)
|
84 |
-
class_idx = np.argmax(predictions, axis=1)[0]
|
85 |
-
confidence = predictions[0][class_idx]
|
86 |
class_label = class_labels.get(class_idx, "Unknown")
|
87 |
if class_label is None:
|
88 |
return {
|
@@ -113,4 +113,4 @@ async def api_predict_image(file: UploadFile = File(...)):
|
|
113 |
|
114 |
# Run the FastAPI app
|
115 |
if __name__ == "__main__":
|
116 |
-
uvicorn.run(app, host="0.0.0.0", port=7860)
|
|
|
81 |
def predict_image(image_data):
|
82 |
preprocessed_image = preprocess_image(image_data)
|
83 |
predictions = model.predict(preprocessed_image)
|
84 |
+
class_idx = int(np.argmax(predictions, axis=1)[0]) # Convert to int for JSON serialization
|
85 |
+
confidence = float(predictions[0][class_idx]) # Convert to float for JSON serialization
|
86 |
class_label = class_labels.get(class_idx, "Unknown")
|
87 |
if class_label is None:
|
88 |
return {
|
|
|
113 |
|
114 |
# Run the FastAPI app
|
115 |
if __name__ == "__main__":
|
116 |
+
uvicorn.run(app, host="0.0.0.0", port=7860)
|