-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathre
43 lines (32 loc) · 1.35 KB
/
re
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
33
34
35
36
37
38
39
40
41
42
43
import pywikibot
from transformers import pipeline
def paraphrase_text(text):
# Initialize the paraphrase pipeline
paraphraser = pipeline("text2text-generation", model="tuner007/pegasus_paraphrase")
# Split text into manageable chunks
sentences = text.split('. ')
paraphrased_sentences = []
for sentence in sentences:
if sentence.strip():
paraphrase = paraphraser(sentence, max_length=60, num_return_sequences=1)
paraphrased_sentences.append(paraphrase[0]['generated_text'])
# Combine paraphrased sentences back into text
return '. '.join(paraphrased_sentences)
def rewrite_article(page_title):
# Site and page setup
site = pywikibot.Site('justawiki', 'justawiki')
page = pywikibot.Page(site, page_title)
try:
# Fetch the current content of the page
content = page.text
# Rewrite the content using paraphrasing
new_content = paraphrase_text(content)
# Save the changes to the page
page.text = new_content
page.save(f'Rewrote entire article: Paraphrased content to avoid copyright issues')
print(f'Successfully rewrote the article: {page_title}')
except pywikibot.exceptions.Error as e:
print(f'Error rewriting the article: {e}')
if __name__ == "__main__":
# Example usage
rewrite_article('Garth Williams')