-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
32 lines (26 loc) · 769 Bytes
/
app.py
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
30
31
32
from flask import Flask
from histogram import histogram
from sample_by_frequency import sample_by_frequency
from MarkovChain import MarkovChain
app = Flask(__name__)
@app.route('/')
def generate_words():
my_file = open("./frost.txt", "r")
lines = my_file.readlines()
words_list = []
for line in lines:
words = line.split()
for word in words:
words_list.append(word)
# myhistogram = histogram()
markovchain = MarkovChain(words_list)
# sentence = ""
# num_words = 10
# for i in range(num_words):
# word = sample_by_frequency(myhistogram)
# print(word)
# sentence += " " + word
return markovchain.walk(10)
if __name__ == '__main__':
app.run()
#./venv/bin/python3 app.py