methestrikerx100 commited on
Commit
c094b98
·
verified ·
1 Parent(s): a63c3be

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -6
app.py CHANGED
@@ -13,7 +13,7 @@ mineral_classification_model = tf.keras.models.load_model(mineral_classification
13
  # Load the mineral detection model
14
  mineral_detection_model = tf.keras.models.load_model("mineral_detection_model_Final_4_18_2024.h5")
15
 
16
- # Define the class labels
17
  class_labels = ['biotite', 'granite', 'olivine', 'plagioclase', 'staurolite']
18
  mineral_facts = {
19
  'biotite': "Hardness: 2.5-3\nMagnetism: None\nDensity: 2.7-3.3 g/cm³\nColors: Black, brown, green\nDescription: A phyllosilicate mineral of the mica group with a distinctive platy structure.",
@@ -23,7 +23,7 @@ mineral_facts = {
23
  'staurolite': "Hardness: 7-7.5\nMagnetism: None\nDensity: 3.6-3.8 g/cm³\nColors: Brown, reddish-brown, black\nDescription: A nesosilicate mineral with a distinctive cruciform twinning habit, commonly found in metamorphic rocks."
24
  }
25
 
26
- # Function to preprocess the image for mineral detection
27
  def preprocess_image_detection(img_array):
28
  if img_array is None:
29
  return None
@@ -33,16 +33,17 @@ def preprocess_image_detection(img_array):
33
  img_array = np.expand_dims(img_array, axis=0) # Add batch dimension
34
  return img_array
35
 
36
- # Function to preprocess the image for classification
37
  def preprocess_image_classification(img_array):
38
  if img_array is None:
39
  return None
40
  img = (img_array * 255).astype(np.uint8) # Convert back to uint8
41
  img_array = cv2.resize(img, (224, 224)) # Resize to 224x224
42
- # img_array is expected to be uint8 and with batch dimension
 
43
  return img_array
44
 
45
- # Define the function to detect if the input is a mineral
46
  def detect_mineral(image):
47
  if image is not None:
48
  image = Image.fromarray(np.array(image).astype(np.uint8), 'RGB')
@@ -57,7 +58,7 @@ def detect_mineral(image):
57
  else:
58
  return "No image provided."
59
 
60
- # Define the function to make predictions for mineral classification
61
  def classify_image(image):
62
  # Check if the input is a mineral
63
  is_mineral = detect_mineral(image)
 
13
  # Load the mineral detection model
14
  mineral_detection_model = tf.keras.models.load_model("mineral_detection_model_Final_4_18_2024.h5")
15
 
16
+ # the class labels
17
  class_labels = ['biotite', 'granite', 'olivine', 'plagioclase', 'staurolite']
18
  mineral_facts = {
19
  'biotite': "Hardness: 2.5-3\nMagnetism: None\nDensity: 2.7-3.3 g/cm³\nColors: Black, brown, green\nDescription: A phyllosilicate mineral of the mica group with a distinctive platy structure.",
 
23
  'staurolite': "Hardness: 7-7.5\nMagnetism: None\nDensity: 3.6-3.8 g/cm³\nColors: Brown, reddish-brown, black\nDescription: A nesosilicate mineral with a distinctive cruciform twinning habit, commonly found in metamorphic rocks."
24
  }
25
 
26
+ # function to preprocess the image for mineral detection
27
  def preprocess_image_detection(img_array):
28
  if img_array is None:
29
  return None
 
33
  img_array = np.expand_dims(img_array, axis=0) # Add batch dimension
34
  return img_array
35
 
36
+ # function to preprocess the image for classification
37
  def preprocess_image_classification(img_array):
38
  if img_array is None:
39
  return None
40
  img = (img_array * 255).astype(np.uint8) # Convert back to uint8
41
  img_array = cv2.resize(img, (224, 224)) # Resize to 224x224
42
+ img_array = img_array.astype(np.uint8)
43
+ img_array = np.expand_dims(img_array, axis=0) # Add batch dimension
44
  return img_array
45
 
46
+ # function to detect if the input is a mineral
47
  def detect_mineral(image):
48
  if image is not None:
49
  image = Image.fromarray(np.array(image).astype(np.uint8), 'RGB')
 
58
  else:
59
  return "No image provided."
60
 
61
+ # function to make predictions for mineral classification
62
  def classify_image(image):
63
  # Check if the input is a mineral
64
  is_mineral = detect_mineral(image)