Spaces:
Runtime error
Runtime error
File size: 1,682 Bytes
50f4308 cb2cacc 50f4308 1a3efe4 92e03e1 1a3efe4 cb2cacc 50f4308 cb2cacc 50f4308 7a62329 82f181f 50f4308 82f181f b5af34a 82f181f 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 52 53 54 55 56 |
import gradio as gr
import random
endings = ['ый', 'ий', 'ая', 'яя', 'ое', 'ее', 'ые', 'ие', 'ому', 'ему', 'ой', 'ей', 'ых', 'их', 'ым', 'им', 'ого', 'его', 'ую', 'юю', 'ого', 'его']
def gen(text):
a = text
count = random.randint(5, 15)
_dataset = open("dataset.txt", "r").readlines()
_a = a.split()
__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 = False if str(words).count("'vp': True") == 0 else True
all_not_vp = False if str(words).count("'vp': False") == 0 else True
if all_vp or all_not_vp:
for i in words.values():
if _from == 3:
break
_from += 1
result += f"{i['word']} "
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() |