Keemoz0 commited on
Commit
cc7610a
·
1 Parent(s): 34b6cd1

Find whats the name,id and classes inside the model

Browse files
Files changed (1) hide show
  1. app.py +13 -8
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
- # Filter predictions to only include columns based on class name
25
- column_boxes = []
26
  for idx, class_id in enumerate(predicted_classes):
27
  class_name = class_names[class_id]
28
- if "table column" in class_name.lower(): # Check if the class name contains 'column'
29
- column_boxes.append(predicted_boxes[idx])
 
 
 
30
 
31
- # Return the bounding boxes for columns
32
- return {"boxes": column_boxes, "classes": ["table column"] * len(column_boxes)}
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 boxes and classes
 
 
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