Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import random
|
| 3 |
+
|
| 4 |
+
# We鈥檙e the rule-breakers, policy-shakers.
|
| 5 |
+
# This app blasts through the entire Hebrew aleph-bet, testing your knowledge.
|
| 6 |
+
|
| 7 |
+
# List of Hebrew letters and their names.
|
| 8 |
+
# For simplicity, we鈥檒l include the 22 standard letters (excluding final forms).
|
| 9 |
+
HEBREW_LETTERS = [
|
| 10 |
+
("讗", "Alef"), ("讘", "Bet"), ("讙", "Gimel"), ("讚", "Dalet"),
|
| 11 |
+
("讛", "He"), ("讜", "Vav"), ("讝", "Zayin"), ("讞", "Het"),
|
| 12 |
+
("讟", "Tet"), ("讬", "Yod"), ("讻", "Kaf"), ("诇", "Lamed"),
|
| 13 |
+
("诪", "Mem"), ("谞", "Nun"), ("住", "Samekh"),("注", "Ayin"),
|
| 14 |
+
("驻", "Pe"), ("爪", "Tsadi"), ("拽", "Qof"), ("专", "Resh"),
|
| 15 |
+
("砖", "Shin"), ("转", "Tav")
|
| 16 |
+
]
|
| 17 |
+
|
| 18 |
+
# Initialize session state to keep track of:
|
| 19 |
+
# 1) The randomized order of letters
|
| 20 |
+
# 2) The index of the current letter
|
| 21 |
+
# 3) Whether the user has guessed
|
| 22 |
+
if "random_letters" not in st.session_state:
|
| 23 |
+
st.session_state.random_letters = random.sample(HEBREW_LETTERS, len(HEBREW_LETTERS))
|
| 24 |
+
if "current_index" not in st.session_state:
|
| 25 |
+
st.session_state.current_index = 0
|
| 26 |
+
if "answer_submitted" not in st.session_state:
|
| 27 |
+
st.session_state.answer_submitted = False
|
| 28 |
+
if "feedback" not in st.session_state:
|
| 29 |
+
st.session_state.feedback = ""
|
| 30 |
+
|
| 31 |
+
def check_answer():
|
| 32 |
+
user_guess = st.session_state.user_guess.strip().lower()
|
| 33 |
+
correct_name = st.session_state.random_letters[st.session_state.current_index][1].lower()
|
| 34 |
+
|
| 35 |
+
if user_guess == correct_name:
|
| 36 |
+
st.session_state.feedback = "Correct! You鈥檙e crushing it, unstoppable problem-solver!"
|
| 37 |
+
else:
|
| 38 |
+
st.session_state.feedback = f"Wrong! The correct answer is '{correct_name.capitalize()}'. "\
|
| 39 |
+
"Don鈥檛 sweat it鈥攔eal champions learn fast."
|
| 40 |
+
st.session_state.answer_submitted = True
|
| 41 |
+
|
| 42 |
+
def next_letter():
|
| 43 |
+
st.session_state.answer_submitted = False
|
| 44 |
+
st.session_state.user_guess = ""
|
| 45 |
+
st.session_state.feedback = ""
|
| 46 |
+
|
| 47 |
+
if st.session_state.current_index < len(st.session_state.random_letters) - 1:
|
| 48 |
+
st.session_state.current_index += 1
|
| 49 |
+
else:
|
| 50 |
+
st.session_state.current_index = 0
|
| 51 |
+
st.session_state.random_letters = random.sample(HEBREW_LETTERS, len(HEBREW_LETTERS))
|
| 52 |
+
|
| 53 |
+
# App title
|
| 54 |
+
st.title("Hebrew Alphabet Tester鈥擭o Nonsense, All Mastery")
|
| 55 |
+
|
| 56 |
+
# Display the current letter
|
| 57 |
+
current_letter, current_name = st.session_state.random_letters[st.session_state.current_index]
|
| 58 |
+
st.markdown(f"### Letter: {current_letter}")
|
| 59 |
+
|
| 60 |
+
# User input
|
| 61 |
+
if not st.session_state.answer_submitted:
|
| 62 |
+
st.text_input("What's this letter's name?", key="user_guess")
|
| 63 |
+
st.button("Check Answer", on_click=check_answer)
|
| 64 |
+
else:
|
| 65 |
+
st.write(st.session_state.feedback)
|
| 66 |
+
st.button("Next Letter", on_click=next_letter)
|