Spaces:
Runtime error
Runtime error
Commit ·
925e616
1
Parent(s): 7ac7f02
fix: reshape
Browse files
app.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from huggingface_hub import from_pretrained_keras
|
| 3 |
-
from
|
| 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 (
|
| 12 |
-
img = img.resize((
|
| 13 |
-
img_array =
|
|
|
|
|
|
|
| 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 |
-
#
|
| 21 |
-
|
|
|
|
| 22 |
|
| 23 |
-
return f'Subject ID: {
|
| 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")
|