make me an app to become type shit
To upload files, please first save the app
import streamlit as st
import random
import time
st.title("⌨️ Typing Speed Test")
# List of sample texts
SAMPLE_TEXTS = [
"The quick brown fox jumps over the lazy dog.",
"Pack my box with five dozen liquor jugs.",
"How vexingly quick daft zebras jump!",
"The five boxing wizards jump quickly.",
"Sphinx of black quartz, judge my vow.",
"Two driven jocks help fax my big quiz.",
]
# Initialize session state variables
if 'start_time' not in st.session_state:
st.session_state.start_time = None
if 'text_to_type' not in st.session_state:
st.session_state.text_to_type = random.choice(SAMPLE_TEXTS)
if 'completed' not in st.session_state:
st.session_state.completed = False
# Display the text to type
st.subheader("Type this text:")
st.write(st.session_state.text_to_type)
# Create the text input
user_text = st.text_input("Start typing here:", key="typing_input")
# Start timer on first keystroke
if user_text and not st.session_state.start_time:
st.session_state.start_time = time.time()
# Check if the text matches and calculate stats
if user_text:
if user_text == st.session_state.text_to_type:
if not st.session_state.completed:
end_time = time.time()
time_taken = end_time - st.session_state.start_time
words = len(st.session_state.text_to_type.split())
wpm = (words / time_taken) * 60
st.success("🎉 Well done!")
st.write(f"Time: {time_taken:.2f} seconds")
st.write(f"Speed: {wpm:.2f} WPM")
if wpm > 50:
st.snow()
st.session_state.completed = True
if st.button("Try another text"):
st.session_state.text_to_type = random.choice(SAMPLE_TEXTS)
st.session_state.start_time = None
st.session_state.completed = False
st.rerun()
else:
# Show real-time feedback
correct_chars = sum(1 for x, y in zip(user_text, st.session_state.text_to_type) if x == y)
total_chars = len(st.session_state.text_to_type)
accuracy = (correct_chars / len(user_text) * 100) if len(user_text) > 0 else 0
st.write(f"Accuracy: {accuracy:.1f}%")
# Add some instructions
with st.expander("How to use"):
st.write("""
1. The text you need to type will appear above
2. Start typing in the text box
3. Your typing speed (WPM) and accuracy will be calculated
4. Get over 50 WPM for a special effect! 🎉
5. Click 'Try another text' to practice with a different phrase
""")
Hi! I can help you with any questions about Streamlit and Python. What would you like to know?