Instructions to use Kushalguptaiitb/table_test with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Kushalguptaiitb/table_test with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("object-detection", model="Kushalguptaiitb/table_test")# pip install -U transformers accelerate # Load model directly from transformers import AutoImageProcessor, AutoModelForObjectDetection processor = AutoImageProcessor.from_pretrained("Kushalguptaiitb/table_test") model = AutoModelForObjectDetection.from_pretrained("Kushalguptaiitb/table_test", device_map="auto") - Notebooks
- Google Colab
- Kaggle
Delete test_azure_table.py
Browse files- test_azure_table.py +0 -92
test_azure_table.py
DELETED
|
@@ -1,92 +0,0 @@
|
|
| 1 |
-
import requests
|
| 2 |
-
import time
|
| 3 |
-
import json
|
| 4 |
-
import pandas as pd
|
| 5 |
-
|
| 6 |
-
# Replace with your values
|
| 7 |
-
endpoint = "https://tableextractwissen.cognitiveservices.azure.com/"
|
| 8 |
-
api_key = "8rSFH0fdGvVxNfULZFjY3yqw9Zqy3gzVA6iHyoaAG6JzvwTvbBZfJQQJ99BDACYeBjFXJ3w3AAALACOGaGjX"
|
| 9 |
-
|
| 10 |
-
# API endpoint for Layout Model v4.0
|
| 11 |
-
analyze_url = f"{endpoint}/formrecognizer/documentModels/prebuilt-layout:analyze?api-version=2023-07-31"
|
| 12 |
-
|
| 13 |
-
# Path to the PNG file
|
| 14 |
-
file_path = "/mnt/SharedDisk/kushal/Infinity_Extractor/test_img_01.png"
|
| 15 |
-
|
| 16 |
-
# Read image
|
| 17 |
-
with open(file_path, "rb") as f:
|
| 18 |
-
file_bytes = f.read()
|
| 19 |
-
|
| 20 |
-
# Request headers
|
| 21 |
-
headers = {
|
| 22 |
-
"Content-Type": "image/png",
|
| 23 |
-
"Ocp-Apim-Subscription-Key": api_key
|
| 24 |
-
}
|
| 25 |
-
|
| 26 |
-
# Submit document
|
| 27 |
-
response = requests.post(analyze_url, headers=headers, data=file_bytes)
|
| 28 |
-
if response.status_code != 202:
|
| 29 |
-
raise Exception(f"Error: {response.text}")
|
| 30 |
-
|
| 31 |
-
# Get polling URL
|
| 32 |
-
result_url = response.headers["Operation-Location"]
|
| 33 |
-
polling_headers = {
|
| 34 |
-
"Ocp-Apim-Subscription-Key": api_key
|
| 35 |
-
}
|
| 36 |
-
|
| 37 |
-
# Poll for result
|
| 38 |
-
while True:
|
| 39 |
-
result_response = requests.get(result_url, headers=polling_headers)
|
| 40 |
-
result = result_response.json()
|
| 41 |
-
status = result["status"]
|
| 42 |
-
if status == "succeeded":
|
| 43 |
-
break
|
| 44 |
-
elif status == "failed":
|
| 45 |
-
raise Exception("Analysis failed:\n", json.dumps(result, indent=2))
|
| 46 |
-
time.sleep(2)
|
| 47 |
-
|
| 48 |
-
# Extract tables
|
| 49 |
-
tables = result.get("analyzeResult", {}).get("tables", [])
|
| 50 |
-
final_dfs = []
|
| 51 |
-
|
| 52 |
-
for idx, table in enumerate(tables):
|
| 53 |
-
row_count = table["rowCount"]
|
| 54 |
-
col_count = table["columnCount"]
|
| 55 |
-
|
| 56 |
-
# Initialize blank grid
|
| 57 |
-
grid = [["" for _ in range(col_count)] for _ in range(row_count)]
|
| 58 |
-
|
| 59 |
-
# Sort cells by row and column index to avoid overwrite
|
| 60 |
-
sorted_cells = sorted(table["cells"], key=lambda x: (x["rowIndex"], x["columnIndex"]))
|
| 61 |
-
|
| 62 |
-
for cell in sorted_cells:
|
| 63 |
-
r = cell["rowIndex"]
|
| 64 |
-
c = cell["columnIndex"]
|
| 65 |
-
content = cell["content"]
|
| 66 |
-
row_span = cell.get("rowSpan", 1)
|
| 67 |
-
col_span = cell.get("columnSpan", 1)
|
| 68 |
-
|
| 69 |
-
for dr in range(row_span):
|
| 70 |
-
for dc in range(col_span):
|
| 71 |
-
rr = r + dr
|
| 72 |
-
cc = c + dc
|
| 73 |
-
if rr < row_count and cc < col_count:
|
| 74 |
-
grid[rr][cc] = content
|
| 75 |
-
|
| 76 |
-
# Convert to DataFrame
|
| 77 |
-
df = pd.DataFrame(grid)
|
| 78 |
-
final_dfs.append(df)
|
| 79 |
-
|
| 80 |
-
# Combine tables
|
| 81 |
-
if len(final_dfs) == 1:
|
| 82 |
-
final_df = final_dfs[0]
|
| 83 |
-
else:
|
| 84 |
-
final_df = pd.concat(final_dfs, keys=[f'Table_{i+1}' for i in range(len(final_dfs))])
|
| 85 |
-
|
| 86 |
-
# Output
|
| 87 |
-
print("\nFinal Extracted Table(s) with Spanning Support:\n")
|
| 88 |
-
print(final_df)
|
| 89 |
-
|
| 90 |
-
# Save to CSV
|
| 91 |
-
# final_df.to_csv("extracted_table_with_spans.csv", index=False)
|
| 92 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|