aegishield commited on
Commit
925e616
·
1 Parent(s): 7ac7f02

fix: reshape

Browse files
Files changed (1) hide show
  1. app.py +10 -7
app.py CHANGED
@@ -1,6 +1,6 @@
1
  import gradio as gr
2
  from huggingface_hub import from_pretrained_keras
3
- from tensorflow.keras.preprocessing import image
4
  import numpy as np
5
 
6
  # Load models
@@ -8,19 +8,22 @@ idpred = from_pretrained_keras("aegishield/idpred")
8
  fingpred = from_pretrained_keras("aegishield/fingpred")
9
 
10
  def predict_image(img):
11
- # Preprocess the image (example, adjust based on your model's needs)
12
- img = img.resize((224, 224)) # Adjust the size according to your model input
13
- img_array = image.img_to_array(img)
 
 
14
  img_array = np.expand_dims(img_array, axis=0) # Add batch dimension
15
 
16
  # Predictions
17
  y_SubjectID_pred = idpred.predict(img_array)
18
  y_fingerNum_pred = fingpred.predict(img_array)
19
 
20
- # Process predictions to readable format if necessary
21
- # For example, if your predictions are one-hot encoded, convert them to labels
 
22
 
23
- return f'Subject ID: {y_SubjectID_pred[0]}, Finger Number: {y_fingerNum_pred[0]}'
24
 
25
  # Create Gradio interface
26
  iface = gr.Interface(fn=predict_image, inputs="image", outputs="text")
 
1
  import gradio as gr
2
  from huggingface_hub import from_pretrained_keras
3
+ from PIL import Image
4
  import numpy as np
5
 
6
  # Load models
 
8
  fingpred = from_pretrained_keras("aegishield/fingpred")
9
 
10
  def predict_image(img):
11
+ # Preprocess the image (resize to 96x96 as per your model's requirement)
12
+ img = img.resize((96, 96))
13
+ img_array = np.array(img)
14
+
15
+ # Ensure the image array is in the correct shape expected by your models
16
  img_array = np.expand_dims(img_array, axis=0) # Add batch dimension
17
 
18
  # Predictions
19
  y_SubjectID_pred = idpred.predict(img_array)
20
  y_fingerNum_pred = fingpred.predict(img_array)
21
 
22
+ # Format the output
23
+ subject_id = np.argmax(y_SubjectID_pred, axis=1)[0] # Adjust if necessary
24
+ finger_num = np.argmax(y_fingerNum_pred, axis=1)[0] # Adjust if necessary
25
 
26
+ return f'Subject ID: {subject_id}, Finger Number: {finger_num}'
27
 
28
  # Create Gradio interface
29
  iface = gr.Interface(fn=predict_image, inputs="image", outputs="text")