Spaces:
Runtime error
Runtime error
File size: 1,586 Bytes
50f4308 |
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 |
import gradio as gr
import random
endings = ['ый', 'ий', 'ая', 'яя', 'ое', 'ее', 'ые', 'ие', 'ому', 'ему', 'ой', 'ей', 'ых', 'их', 'ым', 'им', 'ого', 'его', 'ую', 'юю', 'ого', 'его']
def gen(text):
a = text
count = random.randint(5, 15)
_dataset = open("dataset.txt", "r").readlines()
_a = list(set(a))
__dataset = {el: {"content": i} for el, i in enumerate(_dataset)}
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() |