aryan365 commited on
Commit
67a9d76
·
verified ·
1 Parent(s): 4b3f689

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -9
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
- if ocr_result.strip(): # If text is detected
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)
 
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)