-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAutomatic captcha.py
More file actions
31 lines (31 loc) · 1.2 KB
/
Automatic captcha.py
File metadata and controls
31 lines (31 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import streamlit as st
from captcha.image import ImageCaptcha
import random
import string
st.set_page_config(page_title="Streamlit CAPTCHA", page_icon="🤖")
def generate_random_text(length=5):
return ''.join(random.choices(string.ascii_uppercase + string.digits, k=length))
if 'captcha_text' not in st.session_state:
st.session_state.captcha_text = generate_random_text()
def refresh_captcha():
st.session_state.captcha_text = generate_random_text()
st.title("🤖 Secure Form Access")
st.write("Please verify that you are human.")
image_gen = ImageCaptcha(width=300, height=100)
data = image_gen.generate(st.session_state.captcha_text)
st.image(data, caption="Solve the CAPTCHA")
user_input = st.text_input("Enter the characters you see above:").strip().upper()
col1, col2 = st.columns([1, 4])
with col1:
if st.button("Submit"):
if user_input == st.session_state.captcha_text:
st.success("✅ Success! You are human.")
st.balloons()
else:
st.error("❌ Incorrect. Try again.")
with col2:
if st.button("Refresh CAPTCHA"):
refresh_captcha()
st.rerun()
# For debugging (remove this in a real app!)
#to run streamlit run "Automatic captcha.py"