import gradio as gr import random endings = ['ый', 'ий', 'ая', 'яя', 'ое', 'ее', 'ые', 'ие', 'ому', 'ему', 'ой', 'ей', 'ых', 'их', 'ым', 'им', 'ого', 'его', 'ую', 'юю', 'ого', 'его'] with open("dataset.txt", "r") as f: _dataset = f.readlines() __dataset = {el: {"content": i} for el, i in enumerate(_dataset)} def gen(text): a = text count = random.randint(5, 15) _a = list(set(a)) dataset = ' '.join([i['content'].replace('\n', '') for i in __dataset.values() if any(ii in i['content'] for ii in _a)]) if len(dataset.strip()) == 0: return random.choice(_dataset).strip() words = {} text = dataset.split() random.shuffle(text) for el, i in enumerate(text): words[el] = { "word": i, "vp": len(i) > 3 and (i[-3:] in endings or i[-2:] in endings) } result = "" previous_value = None _from = 0 _to = count all_vp = all(i['vp'] for i in words.values()) all_not_vp = all(not i['vp'] for i in words.values()) if all_vp or all_not_vp: result = ' '.join(i['word'] for i in words.values() if _from < _to) else: for i in words.values(): if _from == _to: break _from += 1 current_value = str(i['vp']) if current_value != previous_value: result += f"{i['word']} " previous_value = current_value return result.lower() iface = gr.Interface(fn=gen, inputs="text", outputs="text") iface.launch()