Spaces:
Runtime error
Runtime error
pip64 commited on
Commit ·
a9c82a0
1
Parent(s): 5e0f491
examples
Browse files
app.py
CHANGED
|
@@ -2,26 +2,25 @@ import gradio as gr
|
|
| 2 |
import random
|
| 3 |
import markovify
|
| 4 |
|
| 5 |
-
def gen(text
|
| 6 |
text = text.lower()
|
| 7 |
-
size =
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
db.splitlines())[:size] + random.choice(symbolsplus)
|
| 19 |
|
| 20 |
return sentence
|
| 21 |
|
| 22 |
iface = gr.Interface(
|
| 23 |
fn=gen,
|
| 24 |
-
inputs=
|
| 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()
|