File size: 767 Bytes
4a378c3
32eadcf
 
4a378c3
a27c32f
 
 
a9c82a0
32eadcf
a9c82a0
 
 
a27c32f
 
 
a9c82a0
 
 
 
 
4a378c3
32eadcf
 
627fa20
 
a9c82a0
627fa20
a27c32f
307abe8
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
import gradio as gr
import random
import markovify

with open(file_name, encoding="utf-8") as f:
    db = f.read()

def gen(text):
  text = text.lower()
  size = random.randint(1, 650)
  file_name = "./dataset.txt"
  with open(file_name, "a", encoding="utf-8") as f:
    v = f"{text}\n"
    f.write(v)
    db += v
  db = db.strip().lower()
  text_model = markovify.NewlineText(input_text=db, state_size=1, well_formed=False)
  symbolsplus = [".","~~","!","?"]
  sentence: str = text_model.make_short_sentence(size) or random.choice(
      db.splitlines())[:size] + random.choice(symbolsplus)

  return sentence

iface = gr.Interface(
    fn=gen,
    inputs="text",
    outputs="text",
    examples=[["Привет!"], ["Как дела?"], ["Как"]])
iface.launch()