Create backupapp.py
Browse files- backupapp.py +35 -0
backupapp.py
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import itertools
|
3 |
+
from nltk.corpus import wordnet
|
4 |
+
|
5 |
+
def get_synonyms(word):
|
6 |
+
synonyms = set()
|
7 |
+
for syn in wordnet.synsets(word):
|
8 |
+
for lemma in syn.lemmas():
|
9 |
+
synonyms.add(lemma.name())
|
10 |
+
return list(synonyms)
|
11 |
+
|
12 |
+
def generate_words(letters, length=None):
|
13 |
+
permutations = set()
|
14 |
+
for i in range(1, len(letters) + 1):
|
15 |
+
for p in itertools.permutations(letters, i):
|
16 |
+
word = "".join(p)
|
17 |
+
if length is None or len(word) == length:
|
18 |
+
permutations.add(word)
|
19 |
+
return permutations
|
20 |
+
|
21 |
+
st.title("Scrabble Helper")
|
22 |
+
|
23 |
+
letters = st.text_input("Enter the letters you have:")
|
24 |
+
word_length = st.number_input("Enter the word length (optional):", min_value=0, value=0, step=1)
|
25 |
+
|
26 |
+
if letters:
|
27 |
+
st.header("Generated Words")
|
28 |
+
words = generate_words(letters, length=word_length if word_length > 0 else None)
|
29 |
+
st.write(words)
|
30 |
+
|
31 |
+
st.header("Thesaurus Lookup")
|
32 |
+
selected_word = st.selectbox("Select a word to look up synonyms:", [""] + sorted(words))
|
33 |
+
if selected_word:
|
34 |
+
synonyms = get_synonyms(selected_word)
|
35 |
+
st.write(synonyms)
|