Spaces:
Sleeping
Sleeping
KAI MAURIN-JONES
commited on
Commit
•
a2d2a55
1
Parent(s):
bbf134c
added requirements
Browse files- app.py +7 -9
- app_OLD.py +91 -0
app.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
import streamlit as st
|
|
|
2 |
import random
|
3 |
from wordle_functions import *
|
4 |
import plotly.express as px
|
@@ -31,8 +32,9 @@ valid_guesses = True
|
|
31 |
### Generate Examples Button
|
32 |
st.write('Please enter a starting word and a target word, and click the "Abracadabra" button to have the puzzle solved.\n')
|
33 |
st.write('If you would like some examples of words you can use, click the button below.\n')
|
34 |
-
gen_egs = st.button('Show Me Words'
|
35 |
-
|
|
|
36 |
st.write(f"There are {len(official_words)} in the official Wordle word list. Here are {len(sugg_words)} of them.")
|
37 |
st.write(f"{sugg_words}\n")
|
38 |
|
@@ -51,8 +53,8 @@ if len(target_word) != 5:
|
|
51 |
st.write('Please double check and make sure there are exactly 5 letters in the target word.\n')
|
52 |
|
53 |
### Solving
|
54 |
-
solve_button = st.button('Abracadabra')
|
55 |
-
if
|
56 |
if valid_guesses == True: # ensure words are the correct lengths
|
57 |
# if (starting_word.isalpha() and target_word.isalpha()): # checking there's no punctuation
|
58 |
if not (starting_word.isalpha() and target_word.isalpha()): # if the passed words don't check every criteria
|
@@ -72,11 +74,7 @@ if solve_button: # button to make everything run
|
|
72 |
st.write("Curious about what the number beside each word means? Click the button below to find out!")
|
73 |
|
74 |
# show plot and info
|
75 |
-
|
76 |
-
|
77 |
-
# if button is clicked
|
78 |
-
if more_info_button:
|
79 |
-
|
80 |
# show plot of letters distribution
|
81 |
count_plot()
|
82 |
st.write(label = "This is a distribution of the frequencies of all letters in the Wordle word list I used in this app. The higher a given letter's count is, the more likely it is that that letter will be able to tell us something about the target word in a Wordle puzzle.\n")
|
|
|
1 |
import streamlit as st
|
2 |
+
from streamlit_extras.stateful_button import button
|
3 |
import random
|
4 |
from wordle_functions import *
|
5 |
import plotly.express as px
|
|
|
32 |
### Generate Examples Button
|
33 |
st.write('Please enter a starting word and a target word, and click the "Abracadabra" button to have the puzzle solved.\n')
|
34 |
st.write('If you would like some examples of words you can use, click the button below.\n')
|
35 |
+
# gen_egs = st.button('Show Me Words')
|
36 |
+
|
37 |
+
if button('Show Me Words', key = "button1"):
|
38 |
st.write(f"There are {len(official_words)} in the official Wordle word list. Here are {len(sugg_words)} of them.")
|
39 |
st.write(f"{sugg_words}\n")
|
40 |
|
|
|
53 |
st.write('Please double check and make sure there are exactly 5 letters in the target word.\n')
|
54 |
|
55 |
### Solving
|
56 |
+
# solve_button = st.button('Abracadabra')
|
57 |
+
if button('Abracadabra', key = "button2"): # button to make everything run
|
58 |
if valid_guesses == True: # ensure words are the correct lengths
|
59 |
# if (starting_word.isalpha() and target_word.isalpha()): # checking there's no punctuation
|
60 |
if not (starting_word.isalpha() and target_word.isalpha()): # if the passed words don't check every criteria
|
|
|
74 |
st.write("Curious about what the number beside each word means? Click the button below to find out!")
|
75 |
|
76 |
# show plot and info
|
77 |
+
if button(label = "More info", key = "button3")
|
|
|
|
|
|
|
|
|
78 |
# show plot of letters distribution
|
79 |
count_plot()
|
80 |
st.write(label = "This is a distribution of the frequencies of all letters in the Wordle word list I used in this app. The higher a given letter's count is, the more likely it is that that letter will be able to tell us something about the target word in a Wordle puzzle.\n")
|
app_OLD.py
ADDED
@@ -0,0 +1,91 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from streamlit_extras.stateful_button import button
|
3 |
+
import random
|
4 |
+
from wordle_functions import *
|
5 |
+
import plotly.express as px
|
6 |
+
from plots import *
|
7 |
+
|
8 |
+
### Page header
|
9 |
+
st.title("Wordle Wizard 🧙")
|
10 |
+
|
11 |
+
|
12 |
+
### Loading in official word list
|
13 |
+
official_words = []
|
14 |
+
with open("data/official_words_processed.txt", "r", encoding = "utf-8") as f:
|
15 |
+
for word in f.read().split("\n"):
|
16 |
+
if len(word) == 5:
|
17 |
+
official_words.append(word)
|
18 |
+
f.close() # closes connection to file
|
19 |
+
|
20 |
+
|
21 |
+
### Examples of words to use
|
22 |
+
sugg_words = []
|
23 |
+
for i in range(0, 20):
|
24 |
+
ran_int = random.randint(0, len(official_words) - 1)
|
25 |
+
word = official_words[ran_int]
|
26 |
+
sugg_words.append(word)
|
27 |
+
|
28 |
+
|
29 |
+
### for guess length validation of both guesses
|
30 |
+
valid_guesses = True
|
31 |
+
|
32 |
+
### Generate Examples Button
|
33 |
+
st.write('Please enter a starting word and a target word, and click the "Abracadabra" button to have the puzzle solved.\n')
|
34 |
+
st.write('If you would like some examples of words you can use, click the button below.\n')
|
35 |
+
gen_egs = st.button('Show Me Words', key = str)
|
36 |
+
if gen_egs:
|
37 |
+
st.write(f"There are {len(official_words)} in the official Wordle word list. Here are {len(sugg_words)} of them.")
|
38 |
+
st.write(f"{sugg_words}\n")
|
39 |
+
|
40 |
+
# user starting word
|
41 |
+
starting_word = st.text_input("Enter starting word here")
|
42 |
+
starting_word = starting_word.strip().replace(" ", "").lower()
|
43 |
+
if len(starting_word) != 5:
|
44 |
+
valid_guesses = False
|
45 |
+
st.write('Please double check and make sure there are exactly 5 letters in the starting word.\n')
|
46 |
+
|
47 |
+
# user target word
|
48 |
+
target_word = st.text_input("Enter target word here")
|
49 |
+
target_word = target_word.strip().replace(" ", "").lower()
|
50 |
+
if len(target_word) != 5:
|
51 |
+
valid_guesses = False
|
52 |
+
st.write('Please double check and make sure there are exactly 5 letters in the target word.\n')
|
53 |
+
|
54 |
+
### Solving
|
55 |
+
solve_button = st.button('Abracadabra')
|
56 |
+
if solve_button: # button to make everything run
|
57 |
+
if valid_guesses == True: # ensure words are the correct lengths
|
58 |
+
# if (starting_word.isalpha() and target_word.isalpha()): # checking there's no punctuation
|
59 |
+
if not (starting_word.isalpha() and target_word.isalpha()): # if the passed words don't check every criteria
|
60 |
+
st.write("Please check again that the starting word and target word only contain letter and are both 5 letters in length. Once they are, click the 'Abracadabra' button once more.")
|
61 |
+
|
62 |
+
else: # if all is right in the wordle wizard world
|
63 |
+
# if either of them aren't in the list, temporarily add them to the list. This doesn't impact things much and will save a ton of error headaches
|
64 |
+
if starting_word not in official_words:
|
65 |
+
official_words.append(starting_word)
|
66 |
+
if target_word not in official_words:
|
67 |
+
official_words.append(target_word)
|
68 |
+
|
69 |
+
# puzzle solution
|
70 |
+
wordle_wizard(word_list = official_words, max_guesses = 6, guess = starting_word, target = target_word, random_guess = False, random_target = False, verbose = True, drama = 0, return_stats = False, record = False)
|
71 |
+
|
72 |
+
# post-solution prompt
|
73 |
+
st.write("Curious about what the number beside each word means? Click the button below to find out!")
|
74 |
+
|
75 |
+
# show plot and info
|
76 |
+
more_info_button = st.button(label = "More info")
|
77 |
+
|
78 |
+
# if button is clicked
|
79 |
+
if more_info_button:
|
80 |
+
|
81 |
+
# show plot of letters distribution
|
82 |
+
count_plot()
|
83 |
+
st.write(label = "This is a distribution of the frequencies of all letters in the Wordle word list I used in this app. The higher a given letter's count is, the more likely it is that that letter will be able to tell us something about the target word in a Wordle puzzle.\n")
|
84 |
+
st.write(label = "The rating of each word corresponds to approximately the percentage of all words of the ~2300 words of the list used for this game in which the given word's letters appear. This means that, for a word with a rating of 30, its letters show up in a total of 30\% of the words of the entire word list. Since we cannot possibly have all 26 letters of the English alphabet in one 5-letter word, this rating can only really be used to compare one word to another. Using more highly-rated words should generally result in getting to the target word in fewer guesses than using lower-rated words.\n")
|
85 |
+
|
86 |
+
# show plot of best and worst words
|
87 |
+
words_plot()
|
88 |
+
st.write(label = "By this same rating system, here are the top 5 words, the middle 5 words, and the worst 5 words of the entire Wordle word list.\n\n")
|
89 |
+
st.write(label = "If you're interested in learning more about the theory of how Wordle Wizard actually works, check out this blog post (https://medium.com/@kmaurinjones/how-i-beat-wordle-once-and-for-all-322c8641a70d), that describes everything mentioned here (and more!) in greater detail.\n")
|
90 |
+
|
91 |
+
st.write("\nThanks for checking out Wordle Wizard! If you have any feedback or requests for additions to this app, shoot me an email at kmaurinjones@gmail.com.")
|