MuhammmadRizwanRizwan commited on
Commit
a10b03b
·
verified ·
1 Parent(s): bd891ff

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -5
app.py CHANGED
@@ -517,7 +517,7 @@ def load_models():
517
 
518
  model_name, model_quality = load_models()
519
 
520
- # Setup Detectron2 configuration for watermelon and banana
521
  @st.cache_resource
522
  def load_detectron_model(model_type):
523
  cfg = get_cfg()
@@ -526,7 +526,7 @@ def load_detectron_model(model_type):
526
  cfg.MODEL.WEIGHTS = "Watermelon_model.pth"
527
  elif model_type == "tomato":
528
  cfg.merge_from_file("tomato.yaml")
529
- cfg.MODEL.WEIGHTS = "tomato_model.pth"
530
  cfg.MODEL.ROI_HEADS.SCORE_THRESH_TEST = 0.5
531
  cfg.MODEL.DEVICE = 'cpu' # Use CPU for inference
532
  predictor = DefaultPredictor(cfg)
@@ -551,7 +551,7 @@ if uploaded_file is not None:
551
 
552
  # Predict fruit name
553
  pred_name = model_name.predict(img_array)
554
- predicted_name = 'Banana' # Example: Modify based on the actual model's output
555
 
556
  # Predict fruit quality
557
  pred_quality = model_quality.predict(img_array)
@@ -577,8 +577,8 @@ if uploaded_file is not None:
577
  # Load the image again for the mask detection (Detectron2 requires the original image)
578
  im = cv2.imdecode(np.fromstring(uploaded_file.read(), np.uint8), 1)
579
 
580
- # Check if the predicted fruit is Banana or Watermelon and load the correct model
581
- if predicted_name == "tomato":
582
  predictor, cfg = load_detectron_model("tomato")
583
  elif predicted_name == "Watermelon":
584
  predictor, cfg = load_detectron_model("watermelon")
@@ -596,3 +596,4 @@ if uploaded_file is not None:
596
  except Exception as e:
597
  st.error(f"An error occurred during processing: {str(e)}")
598
 
 
 
517
 
518
  model_name, model_quality = load_models()
519
 
520
+ # Setup Detectron2 configuration for watermelon and tomato
521
  @st.cache_resource
522
  def load_detectron_model(model_type):
523
  cfg = get_cfg()
 
526
  cfg.MODEL.WEIGHTS = "Watermelon_model.pth"
527
  elif model_type == "tomato":
528
  cfg.merge_from_file("tomato.yaml")
529
+ cfg.MODEL.WEIGHTS = "Tomato_model.pth"
530
  cfg.MODEL.ROI_HEADS.SCORE_THRESH_TEST = 0.5
531
  cfg.MODEL.DEVICE = 'cpu' # Use CPU for inference
532
  predictor = DefaultPredictor(cfg)
 
551
 
552
  # Predict fruit name
553
  pred_name = model_name.predict(img_array)
554
+ predicted_name = 'Tomato' # Example: Modify based on the actual model's output
555
 
556
  # Predict fruit quality
557
  pred_quality = model_quality.predict(img_array)
 
577
  # Load the image again for the mask detection (Detectron2 requires the original image)
578
  im = cv2.imdecode(np.fromstring(uploaded_file.read(), np.uint8), 1)
579
 
580
+ # Check if the predicted fruit is Tomato or Watermelon and load the correct model
581
+ if predicted_name == "Tomato":
582
  predictor, cfg = load_detectron_model("tomato")
583
  elif predicted_name == "Watermelon":
584
  predictor, cfg = load_detectron_model("watermelon")
 
596
  except Exception as e:
597
  st.error(f"An error occurred during processing: {str(e)}")
598
 
599
+