Spaces:
Runtime error
Runtime error
pip64
commited on
Commit
·
4c682e0
1
Parent(s):
307abe8
examples
Browse files
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 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
|
|
|
|
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()
|