aegishield commited on
Commit
c0ed005
·
1 Parent(s): 60556a5
Files changed (1) hide show
  1. app.py +5 -4
app.py CHANGED
@@ -23,7 +23,7 @@ def show_fingername(fingernum):
23
  else: fingername += "thumb"
24
  return fingername
25
 
26
- def predict_image(img):
27
  # Ensure the image is a PIL Image
28
  if not isinstance(img, Image.Image):
29
  img = Image.fromarray(img)
@@ -44,15 +44,16 @@ def predict_image(img):
44
  y_SubjectID_pred = idpred.predict(img_array)
45
  y_fingerNum_pred = fingpred.predict(img_array)
46
 
 
 
47
  # Extract prediction and confidence
48
  subject_id = np.argmax(y_SubjectID_pred, axis=1)[0] + 1
49
  finger_num = np.argmax(y_fingerNum_pred, axis=1)[0]
50
  subject_confidence = np.max(y_SubjectID_pred) * 100
51
  finger_confidence = np.max(y_fingerNum_pred) * 100
52
 
53
- output_message = f"Predicted Subject ID: {subject_id} (Confidence: {subject_confidence:.2f}%)\nPredicted Finger Type: {finger_num} (Confidence: {finger_confidence:.2f}%)"
54
-
55
- return output_message
56
 
57
  # Create Gradio interface
58
  iface = gr.Interface(fn=predict_image, inputs="image", outputs=["text", "text"])
 
23
  else: fingername += "thumb"
24
  return fingername
25
 
26
+ def predict_image(img, image_file):
27
  # Ensure the image is a PIL Image
28
  if not isinstance(img, Image.Image):
29
  img = Image.fromarray(img)
 
44
  y_SubjectID_pred = idpred.predict(img_array)
45
  y_fingerNum_pred = fingpred.predict(img_array)
46
 
47
+ image_name = image_file.name if image_file is not None else "No file name"
48
+
49
  # Extract prediction and confidence
50
  subject_id = np.argmax(y_SubjectID_pred, axis=1)[0] + 1
51
  finger_num = np.argmax(y_fingerNum_pred, axis=1)[0]
52
  subject_confidence = np.max(y_SubjectID_pred) * 100
53
  finger_confidence = np.max(y_fingerNum_pred) * 100
54
 
55
+ return (f'Filename: {image_name} , Predicted Subject ID: {subject_id + 1} (Confidence: {subject_confidence:.2f}%)',
56
+ f'Predicted Finger Number: {show_fingername(finger_num)} (Confidence: {finger_confidence:.2f}%)')
 
57
 
58
  # Create Gradio interface
59
  iface = gr.Interface(fn=predict_image, inputs="image", outputs=["text", "text"])