commit 06878c2999f0c1277f6213d2c4c3a107468beeff Author: SOULOFCINDER <841135647@qq.com> Date: Thu Mar 30 14:25:09 2023 +0800 inital diff --git a/table_transformer_detection/app.py b/table_transformer_detection/app.py new file mode 100644 index 0000000..b8138d2 --- /dev/null +++ b/table_transformer_detection/app.py @@ -0,0 +1,46 @@ +import gradio as gr +from transformers import AutoImageProcessor, TableTransformerForObjectDetection +import torch +from PIL import Image + +def inference(img): + pretrained_model_path = "table-transformer-detection" + + image = img.convert("RGB") + + image_processor = AutoImageProcessor.from_pretrained(pretrained_model_path) + model = TableTransformerForObjectDetection.from_pretrained(pretrained_model_path) + + inputs = image_processor(images=image, return_tensors="pt") + outputs = model(**inputs) + + # convert outputs (bounding boxes and class logits) to COCO API + target_sizes = torch.tensor([image.size[::-1]]) + results = image_processor.post_process_object_detection(outputs, threshold=0.9, target_sizes=target_sizes)[ + 0 + ] + + for score, label, box in zip(results["scores"], results["labels"], results["boxes"]): + box = [round(i, 2) for i in box.tolist()] + return ( + f"Detected {model.config.id2label[label.item()]} with confidence " + f"{round(score.item(), 3)} at location {box}" + ) + + +title = "object detection:table-transformer-detection" +description = "Gradio Demo for table-transformer-detection. To use it, simply upload your image, or click one of the examples to load them." +article = "

Github Repo Pytorch

visitor badge

" +examples=[['example_pdf.png']] + + +demo = gr.Interface( + fn=inference, + inputs=[gr.inputs.Image(type="pil")], + outputs=gr.outputs.Textbox(), + title=title, + description=description, + article=article, + examples=examples) + +demo.launch() \ No newline at end of file diff --git a/table_transformer_detection/example_pdf.png b/table_transformer_detection/example_pdf.png new file mode 100644 index 0000000..74e19fa Binary files /dev/null and b/table_transformer_detection/example_pdf.png differ diff --git a/table_transformer_detection/table-transformer-detection b/table_transformer_detection/table-transformer-detection new file mode 160000 index 0000000..ab363aa --- /dev/null +++ b/table_transformer_detection/table-transformer-detection @@ -0,0 +1 @@ +Subproject commit ab363aa6ce9eba6b79b6547bfb219bdcb2de80f8