Spaces:
Build error
Build error
Commit
·
8743ab7
1
Parent(s):
c5b2fdd
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,7 +5,7 @@ Created on Fri Nov 25 21:37:33 2022
|
|
| 5 |
@author: Bharathraj C L
|
| 6 |
"""
|
| 7 |
|
| 8 |
-
|
| 9 |
import streamlit as st
|
| 10 |
import mmcv
|
| 11 |
import os
|
|
@@ -17,21 +17,35 @@ 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 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
@author: Bharathraj C L
|
| 6 |
"""
|
| 7 |
|
| 8 |
+
|
| 9 |
import streamlit as st
|
| 10 |
import mmcv
|
| 11 |
import os
|
|
|
|
| 17 |
|
| 18 |
st.title("Table Detection from Images")
|
| 19 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
+
@st.cache
|
| 22 |
+
def load_model():
|
| 23 |
+
# Make sure to pass `pretrained` as `True` to use the pretrained weights:
|
| 24 |
+
#new_model = tf.keras.models.load_model('mobilenetv2_100noise.h5')
|
| 25 |
+
config_file = 'cascade_mask_rcnn_hrnetv2p_w32_20e.py'
|
| 26 |
+
checkpoint_file = 'epoch_36.pth'
|
| 27 |
+
model = init_detector(config_file, checkpoint_file, device='cuda:0')
|
| 28 |
+
return new_model
|
| 29 |
+
|
| 30 |
+
def main():
|
| 31 |
+
uploaded_file = st.file_uploader("Choose an image...", type="jpg")
|
| 32 |
+
|
| 33 |
+
model = load_model()
|
| 34 |
+
if uploaded_file is not None:
|
| 35 |
+
image = Image.open(uploaded_file)
|
| 36 |
+
st.image(image, caption='Uploaded Image.', use_column_width=True)
|
| 37 |
+
directory = "tempDir"
|
| 38 |
+
path = os.path.join(os.getcwd(), directory)
|
| 39 |
+
p = Path(path)
|
| 40 |
+
if not p.exists():
|
| 41 |
+
os.mkdir(p)
|
| 42 |
+
with open(os.path.join(path, uploaded_file.name),"wb") as f:
|
| 43 |
+
f.write(uploaded_file.getbuffer())
|
| 44 |
+
file_loc = os.path.join(path, uploaded_file.name)
|
| 45 |
+
result = inference_detector(model, file_loc)
|
| 46 |
+
st.pyplot(show_result_pyplot(file_loc, result,('Bordered', 'cell', 'Borderless'), score_thr=0.85))
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
if __name__ == '__main__':
|
| 51 |
+
main()
|