up 1
Browse files- .gitignore +60 -0
- README.md +0 -1
- app.py +0 -6
- views/__init__.py +1 -0
- views/__pycache__/__init__.cpython-311.pyc +0 -0
- views/__pycache__/dashboard_view.cpython-311.pyc +0 -0
- views/__pycache__/sidebar.cpython-311.pyc +0 -0
- views/__pycache__/utils.cpython-311.pyc +0 -0
- views/assets/drilldocs_logo.jpeg +0 -0
- views/dashboard_view.py +124 -0
- views/sidebar.py +53 -0
- views/utils.py +18 -0
.gitignore
ADDED
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
.DS_Store
|
3 |
+
app.py
|
4 |
+
background_remover/remove_bg.py
|
5 |
+
db/.DS_Store
|
6 |
+
db/data.json
|
7 |
+
db/graphs/psd1.png
|
8 |
+
db/pdf_reports/CSD Aker BP - 4-2-2024 - AkerBPSample1.pdf
|
9 |
+
db/pdf_reports/CSD Aker BP - 4-2-2024 - AkerBPSample2.pdf
|
10 |
+
db/pdf_reports/CSD Aker BP - 4-2-2024 - AkerBPSample5.pdf
|
11 |
+
db/pdf_reports/Report 01:10:2023.pdf
|
12 |
+
db/pdf_reports/report 28:09:2023.pdf
|
13 |
+
db/reports/CSD REPSOL CRANCK - 1-7-2024 - 3950-3.csv
|
14 |
+
db/reports/CSD REPSOL CRANCK - 1-7-2024 - 4250-4.csv
|
15 |
+
db/reports/CSD REPSOL CRANCK - 1-7-2024 - 4550-5.csv
|
16 |
+
db/reports/CSD REPSOL CRANCK - 1-7-2024 - 4850-6.csv
|
17 |
+
db/reports/CSD REPSOL CRANCK - 1-7-2024 - 5150-7.csv
|
18 |
+
db/reports/CSD REPSOL CRANCK - 1-7-2024 - 5250-8.csv
|
19 |
+
db/reports/CSD REPSOL CRANCK - 1-7-2024 - 5350-9.csv
|
20 |
+
db/reports/CSD REPSOL CRANCK - 1-7-2024 - 5420-10.csv
|
21 |
+
db/reports/CSD REPSOL CRANCK - 1-7-2024 - 5450-11.csv
|
22 |
+
db/reports/CSD REPSOL CRANCK - 1-7-2024 - 5550-12.csv
|
23 |
+
db/reports/CSD REPSOL CRANCK - 1-7-2024 - 5650-13.csv
|
24 |
+
db/reports/CSD REPSOL CRANCK - 1-7-2024 - 5750-14.csv
|
25 |
+
db/reports/CSD REPSOL CRANCK - 1-7-2024 - 5950-15.csv
|
26 |
+
db/reports/CSD REPSOL CRANCK - 1-7-2024 - 6050-16.csv
|
27 |
+
functions/__init__.py
|
28 |
+
functions/__pycache__/__init__.cpython-311.pyc
|
29 |
+
functions/__pycache__/rtmp.cpython-311.pyc
|
30 |
+
functions/__pycache__/utils.cpython-311.pyc
|
31 |
+
functions/rtmp.py
|
32 |
+
functions/utils.py
|
33 |
+
main.py
|
34 |
+
model/.DS_Store
|
35 |
+
model/__init__.py
|
36 |
+
model/__pycache__/__init__.cpython-311.pyc
|
37 |
+
model/__pycache__/background_remover.cpython-311.pyc
|
38 |
+
model/__pycache__/grain_analysis.cpython-311.pyc
|
39 |
+
model/__pycache__/rock_image.cpython-311.pyc
|
40 |
+
model/__pycache__/segmentation_model.cpython-311.pyc
|
41 |
+
model/__pycache__/test_segmentation_model.cpython-311.pyc
|
42 |
+
model/background_remover.py
|
43 |
+
model/checkpoints/checkpoint
|
44 |
+
model/checkpoints/seg_model.data-00000-of-00001
|
45 |
+
model/checkpoints/seg_model.index
|
46 |
+
model/grain_analysis.py
|
47 |
+
model/image_quality_checker.py
|
48 |
+
model/rock_image.py
|
49 |
+
model/segmentation_model.py
|
50 |
+
model/test_segmentation_model.py
|
51 |
+
README.md
|
52 |
+
requirements.txt
|
53 |
+
roboflow/landingai_inference.py
|
54 |
+
roboflow/roboflow_inference.py
|
55 |
+
samples/.DS_Store
|
56 |
+
samples/A003_20201229_103823_image.png
|
57 |
+
samples/nobackground/XTO_2A_09-19-23_no_background.png
|
58 |
+
samples/original/XTO_2A_09-19-23.jpg
|
59 |
+
samples/samples.json
|
60 |
+
samples/segmented/XTO_2A_09-19-23_segmented.png
|
README.md
CHANGED
@@ -10,4 +10,3 @@ pinned: false
|
|
10 |
license: apache-2.0
|
11 |
---
|
12 |
|
13 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
10 |
license: apache-2.0
|
11 |
---
|
12 |
|
|
app.py
DELETED
@@ -1,6 +0,0 @@
|
|
1 |
-
import streamlit as st
|
2 |
-
|
3 |
-
x = st.slider('Select a value')
|
4 |
-
st.write(x, 'squared is', x * x)
|
5 |
-
|
6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
views/__init__.py
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
import streamlit as st
|
views/__pycache__/__init__.cpython-311.pyc
ADDED
Binary file (227 Bytes). View file
|
|
views/__pycache__/dashboard_view.cpython-311.pyc
ADDED
Binary file (9.74 kB). View file
|
|
views/__pycache__/sidebar.cpython-311.pyc
ADDED
Binary file (4.08 kB). View file
|
|
views/__pycache__/utils.cpython-311.pyc
ADDED
Binary file (925 Bytes). View file
|
|
views/assets/drilldocs_logo.jpeg
ADDED
![]() |
views/dashboard_view.py
ADDED
@@ -0,0 +1,124 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import json
|
2 |
+
from PIL import Image
|
3 |
+
import os
|
4 |
+
import streamlit as st
|
5 |
+
import pandas as pd
|
6 |
+
|
7 |
+
class DashboardView():
|
8 |
+
def __init__(self):
|
9 |
+
self.current_path = os.path.dirname(os.path.abspath(__file__))
|
10 |
+
self.samples_path = os.path.join(self.current_path, '../samples')
|
11 |
+
json_path = os.path.join(self.samples_path, 'samples.json')
|
12 |
+
self.samples = json.loads(open(json_path).read())
|
13 |
+
|
14 |
+
def main_view(self,ct):
|
15 |
+
ct.title("Rocks segmentation")
|
16 |
+
uploaded_file = ct.file_uploader("Choose a file", type=["jpeg", "png", "jpg"])
|
17 |
+
if uploaded_file is not None:
|
18 |
+
file_contents = uploaded_file.read()
|
19 |
+
#two columns
|
20 |
+
col1, col2 = ct.columns(2)
|
21 |
+
with col1:
|
22 |
+
with ct.expander("original image"):
|
23 |
+
ct.image(file_contents, use_column_width=True)
|
24 |
+
|
25 |
+
with col2:
|
26 |
+
with ct.expander("no background image"):
|
27 |
+
self.nobackground_image_view(ct,uploaded_file.name)
|
28 |
+
|
29 |
+
col3, col4 = ct.columns(2)
|
30 |
+
with col3:
|
31 |
+
with ct.expander("masked image"):
|
32 |
+
self.masked_image_view(ct,uploaded_file.name)
|
33 |
+
|
34 |
+
with col4:
|
35 |
+
with ct.expander("segmented image"):
|
36 |
+
self.segmented_image_view(ct,uploaded_file.name)
|
37 |
+
|
38 |
+
|
39 |
+
|
40 |
+
return uploaded_file
|
41 |
+
|
42 |
+
def nobackground_image_view(self,ct,image_path):
|
43 |
+
# get current path
|
44 |
+
try:
|
45 |
+
masked_image_path = os.path.join(self.samples_path, self.samples[image_path]['no_background_path'])
|
46 |
+
masked_image = Image.open(masked_image_path)
|
47 |
+
ct.image(masked_image, use_column_width=True)
|
48 |
+
except:
|
49 |
+
ct.error("An error has occured...")
|
50 |
+
|
51 |
+
def masked_image_view(self,ct,image_path):
|
52 |
+
# get current path
|
53 |
+
try:
|
54 |
+
masked_image_path = os.path.join(self.samples_path, self.samples[image_path]['masked_path'])
|
55 |
+
masked_image = Image.open(masked_image_path)
|
56 |
+
ct.image(masked_image, use_column_width=True)
|
57 |
+
except:
|
58 |
+
ct.error("An error has occured...")
|
59 |
+
|
60 |
+
def segmented_image_view(self,ct,image_path):
|
61 |
+
# get current path
|
62 |
+
try:
|
63 |
+
segmented_image_path = os.path.join(self.samples_path, self.samples[image_path]['segmentation_path'])
|
64 |
+
segmented_image = Image.open(segmented_image_path)
|
65 |
+
ct.image(segmented_image, use_column_width=True)
|
66 |
+
except:
|
67 |
+
ct.error("An error has occured...")
|
68 |
+
|
69 |
+
def save_image_tojson_view(self,ct, data):
|
70 |
+
# get current path
|
71 |
+
try:
|
72 |
+
data_path = os.path.join(self.current_path, '../db/data.json')
|
73 |
+
with open(data_path, 'w') as f:
|
74 |
+
json.dump(data, f)
|
75 |
+
ct.success("The image has been saved")
|
76 |
+
except:
|
77 |
+
ct.error("An error has occured...")
|
78 |
+
|
79 |
+
|
80 |
+
def load_data_from_folder(self, ct):
|
81 |
+
# get current path
|
82 |
+
try:
|
83 |
+
data_path = os.path.join(self.current_path, '../db/reports')
|
84 |
+
data = os.listdir(data_path)
|
85 |
+
report = ct.selectbox('π Select a report', data, key="csv_key")
|
86 |
+
report_path = os.path.join(data_path, report)
|
87 |
+
df = pd.read_csv(report_path)
|
88 |
+
ct.dataframe(df)
|
89 |
+
|
90 |
+
|
91 |
+
except:
|
92 |
+
ct.error("An error has occured...")
|
93 |
+
|
94 |
+
def load_reports_from_folder(self, ct):
|
95 |
+
# get current path
|
96 |
+
try:
|
97 |
+
reports_path = os.path.join(self.current_path, '../db/pdf_reports')
|
98 |
+
reports = os.listdir(reports_path)
|
99 |
+
print(reports)
|
100 |
+
report = st.selectbox('π Select a report', reports, key="pdf_key")
|
101 |
+
report_path = os.path.join(reports_path, report)
|
102 |
+
with open(report_path, 'rb') as f:
|
103 |
+
pdf_data = f.read()
|
104 |
+
|
105 |
+
# with st.expander("PDF Viewer"):
|
106 |
+
# with open(report_path, 'rb') as f:
|
107 |
+
# pdf_data = f.read()
|
108 |
+
# ct.write(f'<iframe src="data:application/pdf;base64,{pdf_data.encode("base64")}" width="700" height="1000" type="application/pdf"></iframe>', unsafe_allow_html=True)
|
109 |
+
ct.download_button(
|
110 |
+
label=f"Download {report}",
|
111 |
+
data=pdf_data,
|
112 |
+
file_name=report_path,
|
113 |
+
mime="application/pdf"
|
114 |
+
)
|
115 |
+
|
116 |
+
except Exception as e:
|
117 |
+
ct.write(e)
|
118 |
+
ct.error("An error has occurred...")
|
119 |
+
|
120 |
+
|
121 |
+
def display_psd_chart(self,ct):
|
122 |
+
charts_path = os.path.join(self.current_path, '../db/graphs')
|
123 |
+
chart = os.path.join(charts_path, 'psd1.png')
|
124 |
+
ct.image(chart, use_column_width=False, width=400)
|
views/sidebar.py
ADDED
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import streamlit as st
|
3 |
+
from views.utils import *
|
4 |
+
from PIL import Image
|
5 |
+
|
6 |
+
class Sidebar:
|
7 |
+
def __init__(self):
|
8 |
+
pass
|
9 |
+
|
10 |
+
def choose_folder_view(self,ct):
|
11 |
+
with ct:
|
12 |
+
|
13 |
+
#read image with pillow
|
14 |
+
current_dir = os.path.dirname(os.path.abspath(__file__))
|
15 |
+
image_path = os.path.join(current_dir, 'assets/drilldocs_logo.jpeg')
|
16 |
+
image = Image.open(image_path)
|
17 |
+
new_height = 200 # Desired height
|
18 |
+
aspect_ratio = image.width / image.height
|
19 |
+
new_width = int(new_height * aspect_ratio)
|
20 |
+
resized_image = image.resize((new_width, new_height))
|
21 |
+
ct.image(resized_image,use_column_width=False)
|
22 |
+
|
23 |
+
ct.header('βοΈ Parameters')
|
24 |
+
ct.subheader('Choose the folder to store the images')
|
25 |
+
|
26 |
+
def file_selector_view(self,ct):
|
27 |
+
folder_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '../..', 'uploads'))
|
28 |
+
folders = []
|
29 |
+
files = os.listdir(folder_path)
|
30 |
+
new_folder = 'β new client'
|
31 |
+
for folder in files:
|
32 |
+
flags =['.streamlit','__pycache__']
|
33 |
+
if os.path.isdir(folder) and folder not in flags:
|
34 |
+
folders.append(folder)
|
35 |
+
|
36 |
+
folders.append(new_folder)
|
37 |
+
selected_filename = ct.selectbox('π Select a folder for saving', folders, key="folder_selectbox")
|
38 |
+
if selected_filename==folders[-1]: #if we select "add new folder"
|
39 |
+
fn,fb=ct.columns(2)
|
40 |
+
folder_name = fn.text_input('Client name',placeholder="Client name", label_visibility='collapsed')
|
41 |
+
add_btn = fb.button('Add')
|
42 |
+
if add_btn:
|
43 |
+
try:
|
44 |
+
on_click_btn(folder_name=folder_name)
|
45 |
+
st.experimental_rerun()
|
46 |
+
except:
|
47 |
+
ct.error("Error with folder name ")
|
48 |
+
|
49 |
+
elif is_any_directory_not_empty(selected_filename):
|
50 |
+
ct.warning("This folder is not empty! it's content will be erased ")
|
51 |
+
|
52 |
+
return os.path.join(folder_path, selected_filename)
|
53 |
+
|
views/utils.py
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import streamlit as st
|
3 |
+
|
4 |
+
def on_click_btn(folder_name):
|
5 |
+
if not os.path.exists(folder_name):
|
6 |
+
os.makedirs(folder_name)
|
7 |
+
else:
|
8 |
+
st.error('Folder exists')
|
9 |
+
|
10 |
+
def is_any_directory_not_empty(directories):
|
11 |
+
"""Check if any of the specified directories is not empty."""
|
12 |
+
|
13 |
+
if os.listdir(directories):
|
14 |
+
# Found a non-empty directory
|
15 |
+
return True
|
16 |
+
# All directories are empty
|
17 |
+
return False
|
18 |
+
|