diff --git a/app.py b/app.py index bf326425..81e426e8 100644 --- a/app.py +++ b/app.py @@ -8,55 +8,7 @@ params = page_setup(page="main") - -# define the costant -length_captcha = 5 -width = 400 -height = 180 - -# define the function for the captcha control -def captcha_control(): - #control if the captcha is correct - if 'controllo' not in st.session_state or st.session_state['controllo'] == False: - st.title("Makesure you are not a robot🤖") - - # define the session state for control if the captcha is correct - st.session_state['controllo'] = False - col1, col2 = st.columns(2) - - # define the session state for the captcha text because it doesn't change during refreshes - if 'Captcha' not in st.session_state: - st.session_state['Captcha'] = ''.join(random.choices(string.ascii_uppercase + string.digits, k=length_captcha)) - - #setup the captcha widget - image = ImageCaptcha(width=width, height=height) - data = image.generate(st.session_state['Captcha']) - col1.image(data) - capta2_text = col2.text_area('Enter captcha text', height=20) - - - if st.button("Verify the code"): - capta2_text = capta2_text.replace(" ", "") - # if the captcha is correct, the controllo session state is set to True - if st.session_state['Captcha'].lower() == capta2_text.lower().strip(): - del st.session_state['Captcha'] - col1.empty() - col2.empty() - st.session_state['controllo'] = True - st.experimental_rerun() - else: - # if the captcha is wrong, the controllo session state is set to False and the captcha is regenerated - st.error("🚨 Captch is wrong") - del st.session_state['Captcha'] - del st.session_state['controllo'] - st.experimental_rerun() - else: - #wait for the button click - st.stop() - - - -def your_main(): +def main(): st.title("Template App") st.markdown("## A template for an OpenMS streamlit app.") if Path("OpenMS-App.zip").exists(): @@ -69,16 +21,66 @@ def your_main(): mime="archive/zip", ) save_params(params) - -# WORK LIKE MULTIPAGE APP -if 'controllo' not in st.session_state or st.session_state['controllo'] == False: - delete_page("app", "File_Upload") - delete_page("app", "View_Raw_Data") - delete_page("app", "Workflow") - captcha_control() + +## In local mode no captcha +if "local" in sys.argv: + main() + else: - your_main() - add_page("app", "File_Upload") - add_page("app", "View_Raw_Data") - add_page("app", "Workflow") + + length_captcha = 5 + width = 400 + height = 180 + + # define the function for the captcha control + def captcha_control(): + #control if the captcha is correct + if 'controllo' not in st.session_state or st.session_state['controllo'] == False: + st.title("Makesure you are not a robot🤖") + + # define the session state for control if the captcha is correct + st.session_state['controllo'] = False + col1, col2 = st.columns(2) + + # define the session state for the captcha text because it doesn't change during refreshes + if 'Captcha' not in st.session_state: + st.session_state['Captcha'] = ''.join(random.choices(string.ascii_uppercase + string.digits, k=length_captcha)) + + #setup the captcha widget + image = ImageCaptcha(width=width, height=height) + data = image.generate(st.session_state['Captcha']) + col1.image(data) + capta2_text = col2.text_area('Enter captcha text', height=20) + + + if st.button("Verify the code"): + capta2_text = capta2_text.replace(" ", "") + # if the captcha is correct, the controllo session state is set to True + if st.session_state['Captcha'].lower() == capta2_text.lower().strip(): + del st.session_state['Captcha'] + col1.empty() + col2.empty() + st.session_state['controllo'] = True + st.experimental_rerun() + else: + # if the captcha is wrong, the controllo session state is set to False and the captcha is regenerated + st.error("🚨 Captch is wrong") + del st.session_state['Captcha'] + del st.session_state['controllo'] + st.experimental_rerun() + else: + #wait for the button click + st.stop() + + # WORK LIKE MULTIPAGE APP + if 'controllo' not in st.session_state or st.session_state['controllo'] == False: + delete_page("app", "File_Upload") + delete_page("app", "View_Raw_Data") + delete_page("app", "Workflow") + captcha_control() + else: + main() + add_page("app", "File_Upload") + add_page("app", "View_Raw_Data") + add_page("app", "Workflow") diff --git a/run_app.py b/run_app.py index 900bc3b0..404702f3 100644 --- a/run_app.py +++ b/run_app.py @@ -1,5 +1,6 @@ from streamlit.web import cli if __name__=='__main__': - cli._main_run_clExplicit('app.py', 'streamlit run') + + cli._main_run_clExplicit(file = 'app.py', command_line = 'streamlit run', args=['local']) #run in local mode # we will create this function inside our streamlit framework