Skip to content
Snippets Groups Projects
Commit 2618b264 authored by S Kopper's avatar S Kopper
Browse files

initial

parents
No related branches found
No related tags found
No related merge requests found
*.json
*.py[oc]
/secrets__.py
/venv
/cron.log
chain.py 0 → 100644
import markovify
import re
import spacy
SEPARATOR = r"\s*@@note@@\s*"
nlp = spacy.load("en_core_web_sm")
class Text(markovify.Text):
def word_split(self, sentence):
ret = []
for word in nlp(sentence):
if word.pos_ == 'PUNCT':
continue
ret.append("::".join((word.orth_, word.pos_)))
return ret
def word_join(self, words):
sentence = " ".join(word.split("::")[0] for word in words)
return sentence
def sentence_split(self, text):
return re.split(SEPARATOR, text)
import chain
import sys
import requests
import secrets__
model_f = open("model.json")
model = chain.Text.from_json(model_f.read())
generated = False
text = None
while not generated:
text = model.make_short_sentence(80, tries=900, min_words=3)
generated = text is not None
text = text.replace('@','@​').replace('#','#​')
print(text)
requests.post("https://brain.d.on-t.work/api/notes/create", json={
'i': secrets__.TOKEN,
'visibility': 'home',
'noExtractMentions': True,
'noExtractHashtags': True,
'text': text,
'cw': 'markov chain generated post'
})
import re
import json
import sys
print('[+] loading nlp enhanced markov chain')
import chain
MENTION = re.compile(r'@[a-zA-Z0-9.-_]+(@[a-zA-Z0-9.]+-_)?')
MFM_BEGIN = re.compile(r'\$\[[a-z0-9.,=]+')
MFM_END = re.compile(r'\]+')
HTML = re.compile(r'</?[a-z]+>')
SPACE = re.compile(r'[ \n]+')
CONTRACTION = re.compile(r"(\w+)'(\w+)")
print('[+] loading note json')
export_f = sys.argv[1]
export = open(export_f)
export_json = json.load(export)
corpus = []
for note in export_json:
if note.get('visibility') not in ['public', 'unlisted']:
continue
if note.get('localOnly'):
continue
if note.get('cw'):
continue
text = note.get('text')
if not text:
continue
text = text.lower()
text = re.sub(MENTION, '', text)
text = re.sub(MFM_BEGIN, '', text)
text = re.sub(MFM_END, '', text)
text = re.sub(HTML, '', text)
text = re.sub(SPACE, ' ', text)
text = re.sub(CONTRACTION, r'\1\2', text)
text = text.strip()
print(f" - {text}")
corpus.append(text)
print('[+] building markov chain')
model = chain.Text("@@note@@".join(corpus), well_formed=False)
model_json = model.compile().to_json()
print('[+] exporting')
export = open(export_f.replace('.json', '.model.json'), 'w')
export.write(model_json)
pip install -r requirements.txt
python -m spacy download en_core_web_sm
python import-misskey.py notes-XXXX-XX-XX-XX-XX-XX.json
echo "TOKEN=''" > secrets__.py
python generate.py
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment