import gradio as gr import difflib,time,numpy # Dictionary dictionaryFile=open('words.txt','r') # Open words file dictionary=dictionaryFile.readlines() # Read words file into list dictionaryFile.close() def check3(inp, inp2): if len(inp) > len(inp2): longest = inp shortest = inp2 else: shortest = inp longest = inp2 ls = len(shortest) ll = len(longest) out = 0 for i in range(ls): if shortest[i] in longest: out += 1 if shortest[i] == longest[i]: out += 2 return out - ((out-ls)*0.5) - (ll-ls) * 0.5 class Neuron: def __init__(self, inp, output: str): self.output = output self.inp = inp def train(self, inpr): cid = random.randint(0, len(inpr)-1) c2id = random.randint(0, len(inpr[cid])-1) if inpr[cid][c2id] not in self.inp: self.inp.append(inpr[cid][c2id]) cid = random.randint(0, len(self.inp)-1) if not check(self.inp[cid], inpr): del self.inp[cid] def check(word, list2d): for i in list2d: if word in i: return True # Work def get_matches(text): # prepare text textR=str(text) textR=textR.split() # Split inputed text to list # Variables queue=len(textR) output=[] # try to correct it try: ##return(difflib.get_close_matches(text, dictionary)) #[0].replace("\n", "") for x in range(queue): output.append(difflib.get_close_matches(textR[x], dictionary)) return(output) except Exception as ex: # Print error if error return(ex) iface = gr.Interface(fn=get_matches, inputs="text", outputs="text") iface.launch()