pip64 commited on
Commit
a9c82a0
1 Parent(s): 5e0f491
Files changed (1) hide show
  1. app.py +13 -14
app.py CHANGED
@@ -2,26 +2,25 @@ import gradio as gr
2
  import random
3
  import markovify
4
 
5
- def gen(text, size):
6
  text = text.lower()
7
- size = int(size)
8
- if size.isnumeric():
9
- file_name = "./dataset.txt"
10
- with open(file_name, "a", encoding="utf-8") as f:
11
- f.write(f"{text}\n")
12
- with open(file_name, encoding="utf-8") as f:
13
- db = f.read()
14
- db = db.strip().lower()
15
- text_model = markovify.NewlineText(input_text=db, state_size=1, well_formed=False)
16
- symbolsplus = [".","~~","!","?"]
17
- sentence: str = text_model.make_short_sentence(size) or random.choice(
18
- db.splitlines())[:size] + random.choice(symbolsplus)
19
 
20
  return sentence
21
 
22
  iface = gr.Interface(
23
  fn=gen,
24
- inputs=["text", "size"],
25
  outputs="text",
26
  examples=[["Привет!"], ["Как дела?"]])
27
  iface.launch()
 
2
  import random
3
  import markovify
4
 
5
+ def gen(text):
6
  text = text.lower()
7
+ size = random.randint(1, 650)
8
+ file_name = "./dataset.txt"
9
+ with open(file_name, "a", encoding="utf-8") as f:
10
+ f.write(f"{text}\n")
11
+ with open(file_name, encoding="utf-8") as f:
12
+ db = f.read()
13
+ db = db.strip().lower()
14
+ text_model = markovify.NewlineText(input_text=db, state_size=1, well_formed=False)
15
+ symbolsplus = [".","~~","!","?"]
16
+ sentence: str = text_model.make_short_sentence(size) or random.choice(
17
+ db.splitlines())[:size] + random.choice(symbolsplus)
 
18
 
19
  return sentence
20
 
21
  iface = gr.Interface(
22
  fn=gen,
23
+ inputs="text",
24
  outputs="text",
25
  examples=[["Привет!"], ["Как дела?"]])
26
  iface.launch()