Spaces:
Runtime error
Runtime error
File size: 1,751 Bytes
e77905c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# %%
import inspect
import random
import gradio as gr
import pandas as pd
url = "https://raw.githubusercontent.com/dwyl/english-words/master/words.txt"
df = pd.read_table(url, header=None)
words = df[0].astype(str).tolist()
words = [x.lower() for x in words if len(x) == 5 and x.isalpha()]
def filter_one_word(
w,
no="",
yes="",
no1="",
no2="",
no3="",
no4="",
no5="",
yes1="",
yes2="",
yes3="",
yes4="",
yes5="",
):
for c in w:
if c in no:
return False
for c in yes:
if c not in w:
return False
nos = [no1, no2, no3, no4, no5]
for c, n in zip(w, nos):
if c in n:
return False
yeses = [yes1, yes2, yes3, yes4, yes5]
for c, n in zip(w, yeses):
if n and c != n:
return False
return True
def process_args(chars):
cs = set([c for c in chars.lower() if c.isalpha()])
return "".join(list(cs))
def main(
no="",
yes="",
no1="",
no2="",
no3="",
no4="",
no5="",
yes1="",
yes2="",
yes3="",
yes4="",
yes5="",
):
no, yes, no1, no2, no3, no4, no5, yes1, yes2, yes3, yes4, yes5 = map(
process_args, [no, yes, no1, no2, no3, no4, no5, yes1, yes2, yes3, yes4, yes5]
)
candidates = [
w
for w in words
if filter_one_word(
w, no, yes, no1, no2, no3, no4, no5, yes1, yes2, yes3, yes4, yes5
)
]
return str(len(candidates)), "\n".join(
random.sample(candidates, (min(10, len(candidates))))
)
args = inspect.getfullargspec(main)
iface = gr.Interface(
fn=main,
inputs=[gr.inputs.Textbox(label=n) for n in args.args],
outputs=["text", "text"],
).launch()
|