Find whats the name,id and classes inside the model
Browse files
app.py
CHANGED
@@ -20,22 +20,27 @@ def predict(image):
|
|
20 |
predicted_class_logits = outputs.logits[0].cpu().numpy() # Class logits for the first image
|
21 |
predicted_classes = predicted_class_logits.argmax(-1) # Get class predictions
|
22 |
class_names = model.config.id2label # Get the class name mapping
|
23 |
-
|
24 |
-
#
|
25 |
-
|
26 |
for idx, class_id in enumerate(predicted_classes):
|
27 |
class_name = class_names[class_id]
|
28 |
-
|
29 |
-
|
|
|
|
|
|
|
30 |
|
31 |
-
# Return the bounding boxes
|
32 |
-
return
|
33 |
|
34 |
# Set up the Gradio interface
|
35 |
interface = gr.Interface(
|
36 |
fn=predict, # The function that gets called when an image is uploaded
|
37 |
inputs=gr.Image(type="pil"), # Image input (as PIL image)
|
38 |
-
outputs="json", # Outputting a JSON with the
|
|
|
|
|
39 |
)
|
40 |
|
41 |
# Launch the Gradio app
|
|
|
20 |
predicted_class_logits = outputs.logits[0].cpu().numpy() # Class logits for the first image
|
21 |
predicted_classes = predicted_class_logits.argmax(-1) # Get class predictions
|
22 |
class_names = model.config.id2label # Get the class name mapping
|
23 |
+
|
24 |
+
# Collect the class IDs and labels along with the bounding boxes
|
25 |
+
result = []
|
26 |
for idx, class_id in enumerate(predicted_classes):
|
27 |
class_name = class_names[class_id]
|
28 |
+
result.append({
|
29 |
+
"class_id": int(class_id),
|
30 |
+
"class_name": class_name,
|
31 |
+
"bounding_box": predicted_boxes[idx].tolist() # Convert to list for JSON serialization
|
32 |
+
})
|
33 |
|
34 |
+
# Return the bounding boxes and classes
|
35 |
+
return result
|
36 |
|
37 |
# Set up the Gradio interface
|
38 |
interface = gr.Interface(
|
39 |
fn=predict, # The function that gets called when an image is uploaded
|
40 |
inputs=gr.Image(type="pil"), # Image input (as PIL image)
|
41 |
+
outputs="json", # Outputting a JSON with the class labels, IDs, and bounding boxes
|
42 |
+
title="Table Structure Recognition", # Add title for clarity
|
43 |
+
description="Upload an image and see the detected table columns and their corresponding class IDs.",
|
44 |
)
|
45 |
|
46 |
# Launch the Gradio app
|