Update app.py
Browse files
app.py
CHANGED
|
@@ -49,18 +49,18 @@ def predict():
|
|
| 49 |
# Use OCR to detect text
|
| 50 |
ocr_result = pytesseract.image_to_string(image_rgb)
|
| 51 |
|
| 52 |
-
|
| 53 |
# Perform inference using the YOLO model
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
|
| 60 |
-
|
| 61 |
-
|
| 62 |
|
| 63 |
-
|
| 64 |
|
| 65 |
|
| 66 |
# Resize the image to the expected input size of the model (e.g., 225x225)
|
|
|
|
| 49 |
# Use OCR to detect text
|
| 50 |
ocr_result = pytesseract.image_to_string(image_rgb)
|
| 51 |
|
| 52 |
+
|
| 53 |
# Perform inference using the YOLO model
|
| 54 |
+
results = yolo_model(image) # Pass the image to the YOLO model
|
| 55 |
+
|
| 56 |
+
# Extract the detected classes
|
| 57 |
+
class_indices = results[0].boxes.cls.cpu().numpy().astype(int) # Get the class indices
|
| 58 |
+
unique_classes = np.unique(class_indices) # Get unique classes detected
|
| 59 |
|
| 60 |
+
# Map class indices to labels if needed
|
| 61 |
+
detected_classes = [str(cls) for cls in unique_classes] # Convert indices to strings
|
| 62 |
|
| 63 |
+
return jsonify({'predictions': detected_classes, 'detected_text': ocr_result.strip()})
|
| 64 |
|
| 65 |
|
| 66 |
# Resize the image to the expected input size of the model (e.g., 225x225)
|