revertall
Browse files
app.py
CHANGED
@@ -1,7 +1,10 @@
|
|
1 |
import gradio as gr
|
2 |
-
from
|
|
|
3 |
import torch
|
|
|
4 |
|
|
|
5 |
# Load the processor and model for table structure recognition
|
6 |
processor = AutoImageProcessor.from_pretrained("microsoft/table-transformer-structure-recognition")
|
7 |
model = AutoModelForObjectDetection.from_pretrained("microsoft/table-transformer-structure-recognition")
|
@@ -18,13 +21,8 @@ def predict(image):
|
|
18 |
# Extract bounding boxes and class labels
|
19 |
predicted_boxes = outputs.pred_boxes[0].cpu().numpy() # First image
|
20 |
predicted_classes = outputs.logits.argmax(-1).cpu().numpy() # Class predictions
|
21 |
-
|
22 |
-
|
23 |
-
print("Predicted Classes (IDs):", predicted_classes)
|
24 |
-
print("Bounding Boxes (x1, y1, x2, y2):", predicted_boxes)
|
25 |
-
|
26 |
-
# Return the bounding boxes and class IDs for display in JSON
|
27 |
-
return {"predicted_boxes": predicted_boxes.tolist(), "predicted_classes": predicted_classes.tolist()}
|
28 |
|
29 |
# Set up the Gradio interface
|
30 |
interface = gr.Interface(
|
|
|
1 |
import gradio as gr
|
2 |
+
from huggingface_hub import hf_hub_download
|
3 |
+
from PIL import Image
|
4 |
import torch
|
5 |
+
from transformers import AutoImageProcessor, AutoModelForObjectDetection
|
6 |
|
7 |
+
gr.load("models/microsoft/table-transformer-structure-recognition").launch()
|
8 |
# Load the processor and model for table structure recognition
|
9 |
processor = AutoImageProcessor.from_pretrained("microsoft/table-transformer-structure-recognition")
|
10 |
model = AutoModelForObjectDetection.from_pretrained("microsoft/table-transformer-structure-recognition")
|
|
|
21 |
# Extract bounding boxes and class labels
|
22 |
predicted_boxes = outputs.pred_boxes[0].cpu().numpy() # First image
|
23 |
predicted_classes = outputs.logits.argmax(-1).cpu().numpy() # Class predictions
|
24 |
+
# Return the bounding boxes for display
|
25 |
+
return {"boxes": predicted_boxes.tolist(), "classes": predicted_classes.tolist()}
|
|
|
|
|
|
|
|
|
|
|
26 |
|
27 |
# Set up the Gradio interface
|
28 |
interface = gr.Interface(
|