Skip to content

Commit

Permalink
Merge pull request OpenMS#24 from Arslan-Siraj/app_exe
Browse files Browse the repository at this point in the history
fixed local
  • Loading branch information
axelwalter authored Sep 6, 2023
2 parents 24162c8 + d6e0c85 commit 1d345cc
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 61 deletions.
122 changes: 62 additions & 60 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand All @@ -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")

3 changes: 2 additions & 1 deletion run_app.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 1d345cc

Please sign in to comment.