Spaces:
Build error
Build error
Commit
·
3f569a6
1
Parent(s):
f03a6d7
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,3 +6,32 @@ Created on Fri Nov 25 21:37:33 2022
|
|
| 6 |
"""
|
| 7 |
|
| 8 |
import deepdoctection
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
"""
|
| 7 |
|
| 8 |
import deepdoctection
|
| 9 |
+
import streamlit as st
|
| 10 |
+
import mmcv
|
| 11 |
+
import os
|
| 12 |
+
import numpy as np
|
| 13 |
+
from PIL import Image
|
| 14 |
+
from mmdet.apis import init_detector, inference_detector, show_result_pyplot
|
| 15 |
+
from pathlib import Path
|
| 16 |
+
st.set_option('deprecation.showPyplotGlobalUse', False)
|
| 17 |
+
|
| 18 |
+
st.title("Table Detection from Images")
|
| 19 |
+
|
| 20 |
+
config_file = 'cascade_mask_rcnn_hrnetv2p_w32_20e.py'
|
| 21 |
+
checkpoint_file = 'epoch_36.pth'
|
| 22 |
+
model = init_detector(config_file, checkpoint_file, device='cuda:0')
|
| 23 |
+
uploaded_file = st.file_uploader("Choose an image...", type="jpg")
|
| 24 |
+
if uploaded_file is not None:
|
| 25 |
+
image = Image.open(uploaded_file)
|
| 26 |
+
st.image(image, caption='Uploaded Image.', use_column_width=True)
|
| 27 |
+
directory = "tempDir"
|
| 28 |
+
path = os.path.join(os.getcwd(), directory)
|
| 29 |
+
p = Path(path)
|
| 30 |
+
if not p.exists():
|
| 31 |
+
os.mkdir(p)
|
| 32 |
+
with open(os.path.join(path, uploaded_file.name),"wb") as f:
|
| 33 |
+
f.write(uploaded_file.getbuffer())
|
| 34 |
+
file_loc = os.path.join(path, uploaded_file.name)
|
| 35 |
+
result = inference_detector(model, file_loc)
|
| 36 |
+
st.pyplot(show_result_pyplot(file_loc, result,('Bordered', 'cell', 'Borderless'), score_thr=0.85))
|
| 37 |
+
|