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