Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
NIRS_Workflow
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
CEFE
PACE
NIRS_Workflow
Commits
1e94a59e
Commit
1e94a59e
authored
6 months ago
by
DIANE
Browse files
Options
Downloads
Patches
Plain Diff
input form enhancement and error management
parent
d8675d48
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/pages/4-inputs.py
+57
-65
57 additions, 65 deletions
src/pages/4-inputs.py
with
57 additions
and
65 deletions
src/pages/4-inputs.py
+
57
−
65
View file @
1e94a59e
...
@@ -17,62 +17,45 @@ pages_folder = Path("pages/")
...
@@ -17,62 +17,45 @@ pages_folder = Path("pages/")
if
'
form_submitted
'
not
in
st
.
session_state
:
if
'
form_submitted
'
not
in
st
.
session_state
:
st
.
session_state
[
'
form_submitted
'
]
=
False
st
.
session_state
[
'
form_submitted
'
]
=
False
# Page header
with
st
.
container
():
with
st
.
container
():
# Text input fields
# Text input fields
with
st
.
form
(
key
=
'
my_form
'
):
st
.
header
(
"
Complete and save the following form with the data context:
"
,
divider
=
"
blue
"
)
st
.
warning
(
'
Make sure that the form is well completed, because the reliability of the results depends mainly on it !
'
,
icon
=
"
⚠️
"
)
st
.
header
(
"
Complete and send the following form with the data context:
"
,
divider
=
"
blue
"
)
st
.
warning
(
'
Make sure that the form is well completed, because the reliability of the results depends mainly on it !
'
,
icon
=
"
⚠️
"
)
col1
,
col3
,
col2
=
st
.
columns
((
2
,
0.5
,
2
))
with
st
.
form
(
key
=
'
my_form
'
):
_
,
col1
,
col3
,
col2
=
st
.
columns
((
0.1
,
1.4
,
0.5
,
2
))
with
col1
:
with
col1
:
st
.
header
(
"
Groupe 2
"
,
divider
=
"
blue
"
)
############## Project information ###########
st
.
subheader
(
"
Project information
"
,
divider
=
"
blue
"
)
meta_project
=
st
.
text_input
(
'
Project name :
'
,
'
Life of Brian
'
)
meta_project
=
st
.
text_input
(
'
Project name :
'
)
meta_machine_ID
=
st
.
text_input
(
'
NIRS ID :
'
,
'
Life of Brian
'
)
meta_machine_ID
=
st
.
text_input
(
'
NIRS ID :
'
,)
meta_scan_place_options
=
[
"
Pace
"
,
"
Other
"
]
meta_scan_place_options
=
[
"
Pace
"
,
"
Other
"
]
meta_scan_place
=
st
.
radio
(
"
If relevant, sample species :
"
,
meta_scan_place_options
)
meta_scan_place
=
st
.
radio
(
"
Analysis Laboratory :
"
,
meta_scan_place_options
)
meta_sample_species
=
st
.
text_input
(
'
Samples species (If relevant, provide the sample species; otherwise insert No):
'
)
meta_sample_species
=
st
.
text_input
(
'
If relevant, sample species :
'
,
'
Life of Brian
'
)
with
col2
:
with
col2
:
st
.
header
(
"
Groupe 3
"
,
divider
=
"
blue
"
)
clo3
,
_
,
col4
,
_
=
st
.
columns
([
1
,
0.2
,
1
,
0.3
])
meta_sample_category_options
=
[
"
Soil
"
,
"
Plant
"
,
"
Animal
"
,
"
Other
"
]
with
clo3
:
meta_sample_category
=
st
.
radio
(
"
Sample category description :
"
,
meta_sample_category_options
)
############## The Nature of the Samples ###########
if
''
in
[
meta_project
,
meta_machine_ID
,
meta_sample_species
]:
disabled1
=
True
meta_sample_sub_category_options
=
[
"
Green leave
"
,
"
Leaf litter
"
,
"
Litter
"
,
"
Humus
"
,
"
Soil
"
,
"
Animal part
"
,
"
Animal Powder
"
,
"
Fungal sample
"
,
"
Other
"
]
else
:
disabled1
=
False
meta_sample_sub_category
=
st
.
radio
(
"
Sample category description :
"
,
meta_sample_sub_category_options
)
st
.
subheader
(
"
The Nature of the Samples
"
,
divider
=
"
blue
"
)
meta_sample_humidity_options
=
[
"
Dry
"
,
"
Fresh
"
,
"
Wet
"
]
meta_sample_category_options
=
[
"
Soil
"
,
"
Plant
"
,
"
Animal
"
,
"
Other
"
]
meta_sample_humidity
=
st
.
radio
(
"
Humidity state of the sample:
"
,
meta_sample_humidity_options
)
meta_sample_category
=
st
.
radio
(
"
Samples category :
"
,
[
""
]
+
meta_sample_category_options
)
meta_sample_sub_category_options
=
[
"
Green leaves
"
,
"
Leaf litter
"
,
"
Litter
"
,
"
Humus
"
,
"
Soil
"
,
"
Animal part
"
,
"
Animal Powder
"
,
"
Fungal sample
"
,
"
Other
"
]
meta_sample_pretreatment_options
=
[
"
Powder
"
,
"
Pastile
"
,
"
Liquid
"
]
meta_sample_sub_category
=
st
.
radio
(
"
Sample category description :
"
,
[
""
]
+
meta_sample_sub_category_options
)
meta_sample_pretreatment
=
st
.
radio
(
"
Type of sample pre-treatment :
"
,
meta_sample_pretreatment_options
)
with
col4
:
st
.
subheader
(
"
The Physical State of the Samples
"
,
divider
=
"
blue
"
)
meta_sample_humidity_options
=
[
"
Dry
"
,
"
Fresh
"
,
"
Wet
"
]
submitted
=
st
.
form_submit_button
(
label
=
'
Send
'
)
meta_sample_humidity
=
st
.
radio
(
"
Humidity state of the sample :
"
,
[
""
]
+
meta_sample_humidity_options
)
meta_sample_pretreatment_options
=
[
"
Powder
"
,
"
Pastile
"
,
"
Liquid
"
]
meta_sample_pretreatment
=
st
.
radio
(
"
Type of sample pre-treatment :
"
,
[
""
]
+
meta_sample_pretreatment_options
)
if
submitted
:
# Save the form data here
st
.
session_state
[
'
form_submitted
'
]
=
True
st
.
success
(
'
Form sent successfully!
'
,
icon
=
"
✅
"
)
# Création du dictionnaire avec les données du formulaire
# Création du dictionnaire avec les données du formulaire
form_data
=
{
form_data
=
{
"
meta_project
"
:
meta_project
,
"
meta_project
"
:
meta_project
,
...
@@ -85,22 +68,31 @@ with st.container():
...
@@ -85,22 +68,31 @@ with st.container():
"
meta_scan_place
"
:
meta_scan_place
"
meta_scan_place
"
:
meta_scan_place
}
}
# Enregistrement des données dans un fichier JSON
submitted
=
st
.
form_submit_button
(
label
=
'
Save
'
)
with
open
(
'
form_data.json
'
,
'
w
'
)
as
json_file
:
if
submitted
:
json
.
dump
(
form_data
,
json_file
)
if
''
not
in
form_data
.
values
():
# Save the form data here
with
st
.
container
():
st
.
session_state
[
'
form_submitted
'
]
=
True
if
st
.
session_state
[
'
interface
'
]
==
'
simple
'
:
st
.
success
(
'
Form was saved successfully!
'
,
icon
=
"
✅
"
)
header3
,
header4
=
st
.
columns
(
2
)
# Enregistrement des données dans un fichier JSON
if
header3
.
button
(
"
Samples Selection
"
):
with
open
(
'
form_data.json
'
,
'
w
'
)
as
json_file
:
st
.
switch_page
(
pages_folder
/
'
1-samples_selection.py
'
)
json
.
dump
(
form_data
,
json_file
)
if
header4
.
button
(
"
Model Creation
"
):
st
.
switch_page
(
pages_folder
/
'
2-model_creation.py
'
)
with
st
.
container
():
elif
st
.
session_state
[
'
interface
'
]
==
'
advanced
'
:
if
st
.
session_state
[
'
interface
'
]
==
'
simple
'
:
header3
,
header4
,
header5
=
st
.
columns
(
3
)
header3
,
header4
=
st
.
columns
(
2
)
if
header3
.
button
(
"
Samples Selection
"
):
if
header3
.
button
(
"
Samples Selection
"
):
st
.
switch_page
(
pages_folder
/
'
1-samples_selection.py
'
)
st
.
switch_page
(
pages_folder
/
'
1-samples_selection.py
'
)
if
header4
.
button
(
"
Model Creation
"
):
if
header4
.
button
(
"
Model Creation
"
):
st
.
switch_page
(
pages_folder
/
'
2-model_creation.py
'
)
st
.
switch_page
(
pages_folder
/
'
2-model_creation.py
'
)
if
header5
.
button
(
"
Prediction
"
):
elif
st
.
session_state
[
'
interface
'
]
==
'
advanced
'
:
st
.
switch_page
(
pages_folder
/
'
3-prediction.py
'
)
header3
,
header4
,
header5
=
st
.
columns
(
3
)
\ No newline at end of file
if
header3
.
button
(
"
Samples Selection
"
):
st
.
switch_page
(
pages_folder
/
'
1-samples_selection.py
'
)
if
header4
.
button
(
"
Model Creation
"
):
st
.
switch_page
(
pages_folder
/
'
2-model_creation.py
'
)
if
header5
.
button
(
"
Prediction
"
):
st
.
switch_page
(
pages_folder
/
'
3-prediction.py
'
)
else
:
st
.
error
(
'
Error: The form was not saved, please ensure the required fields are filled!
'
)
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment