pip64 commited on
Commit
50f4308
·
1 Parent(s): 51300dd

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +51 -0
app.py ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+
3
+ import random
4
+
5
+ endings = ['ый', 'ий', 'ая', 'яя', 'ое', 'ее', 'ые', 'ие', 'ому', 'ему', 'ой', 'ей', 'ых', 'их', 'ым', 'им', 'ого', 'его', 'ую', 'юю', 'ого', 'его']
6
+
7
+ def gen(text):
8
+ a = text
9
+ count = random.randint(5, 15)
10
+ _dataset = open("dataset.txt", "r").readlines()
11
+ _a = list(set(a))
12
+ __dataset = {el: {"content": i} for el, i in enumerate(_dataset)}
13
+ dataset = ' '.join([i['content'].replace('\n', '') for i in __dataset.values() if any(ii in i['content'] for ii in _a)])
14
+
15
+ if len(dataset.strip()) == 0:
16
+ return random.choice(_dataset).strip()
17
+
18
+ words = {}
19
+ text = dataset.split()
20
+ random.shuffle(text)
21
+
22
+ for el, i in enumerate(text):
23
+ words[el] = {
24
+ "word": i,
25
+ "vp": len(i) > 3 and (i[-3:] in endings or i[-2:] in endings)
26
+ }
27
+
28
+ result = ""
29
+ previous_value = None
30
+ _from = 0
31
+ _to = count
32
+
33
+ all_vp = all(i['vp'] for i in words.values())
34
+ all_not_vp = all(not i['vp'] for i in words.values())
35
+
36
+ if all_vp or all_not_vp:
37
+ result = ' '.join(i['word'] for i in words.values() if _from < _to)
38
+ else:
39
+ for i in words.values():
40
+ if _from == _to:
41
+ break
42
+ _from += 1
43
+ current_value = str(i['vp'])
44
+ if current_value != previous_value:
45
+ result += f"{i['word']} "
46
+ previous_value = current_value
47
+
48
+ return result.lower()
49
+
50
+ iface = gr.Interface(fn=gen, inputs="text", outputs="text")
51
+ iface.launch()