initial commit
Browse files- main.py +51 -0
- requirements.txt +35 -0
main.py
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from spellchecker import SpellChecker
|
| 3 |
+
from itertools import permutations
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
def Anagram(words):
|
| 8 |
+
"""
|
| 9 |
+
A function that returns an anagram after filtering out the incorrect words.
|
| 10 |
+
It also returns the given word passed to the function whether anagaram is
|
| 11 |
+
generated or not.
|
| 12 |
+
"""
|
| 13 |
+
randomize = randomizer(words)
|
| 14 |
+
checker = spellChecker(words)
|
| 15 |
+
# Because set returns only unique words. We convert the 'randomize' variable
|
| 16 |
+
# to set so we can filter out the incorrect spellings from 'checker'
|
| 17 |
+
anagram = set(randomize) - checker
|
| 18 |
+
# we are now left with the correct word(s) as anagram
|
| 19 |
+
return anagram
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
def spellChecker(word):
|
| 23 |
+
"""
|
| 24 |
+
A function that scans a given word returned from the randomizer function for
|
| 25 |
+
incorrect spellings and returns the wrong spellings.
|
| 26 |
+
"""
|
| 27 |
+
checker = SpellChecker()
|
| 28 |
+
randomize = randomizer(word)
|
| 29 |
+
incorrect = checker.unknown(randomize)
|
| 30 |
+
return incorrect
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
def randomizer(word):
|
| 34 |
+
"""
|
| 35 |
+
A function to generate a combination of words from a given word passed to the function.
|
| 36 |
+
It returns all the combination of words generated.
|
| 37 |
+
"""
|
| 38 |
+
lists = []
|
| 39 |
+
texts = permutations(word)
|
| 40 |
+
#Permutation separated each word. Join them back together.
|
| 41 |
+
for text in texts:
|
| 42 |
+
lists.append(''.join(text))
|
| 43 |
+
return lists
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
app = gr.Interface(fn=Anagram, inputs='text', outputs='text')
|
| 48 |
+
|
| 49 |
+
#launching the app
|
| 50 |
+
app.launch()
|
| 51 |
+
|
requirements.txt
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio==3.15.0
|
| 2 |
+
aiohttp==3.8.3
|
| 3 |
+
aiosignal==1.3.1
|
| 4 |
+
frozenlist==1.3.3
|
| 5 |
+
async-timeout==4.0.2
|
| 6 |
+
attrs==19.3.0
|
| 7 |
+
charset-normalizer==2.1.1
|
| 8 |
+
multidict==6.0.4
|
| 9 |
+
yarl==1.8.2
|
| 10 |
+
idna==2.8
|
| 11 |
+
altair==4.2.0
|
| 12 |
+
numpy==1.22.4
|
| 13 |
+
pandas==1.4.2
|
| 14 |
+
pytz==2022.1
|
| 15 |
+
python-dateutil==2.8.2
|
| 16 |
+
six==1.14.0
|
| 17 |
+
jsonschema==3.2.0
|
| 18 |
+
fastapi==0.88.0
|
| 19 |
+
ffmpy==0.3.0
|
| 20 |
+
fsspec==2022.11.0
|
| 21 |
+
httpx==0.23.1
|
| 22 |
+
jinja2==3.1.2
|
| 23 |
+
markdown-it-py==2.1.0
|
| 24 |
+
markupsafe==2.1.1
|
| 25 |
+
matplotlib==3.6.2
|
| 26 |
+
orjson==3.8.3
|
| 27 |
+
pillow==9.3.0
|
| 28 |
+
pycryptodome==3.16.0
|
| 29 |
+
pydantic==1.10.3
|
| 30 |
+
pydub==0.25.1
|
| 31 |
+
python-multipart==0.0.5
|
| 32 |
+
pyyaml==5.3.1
|
| 33 |
+
requests==2.22.0
|
| 34 |
+
uvicorn==0.20.0
|
| 35 |
+
websockets==10.4
|