-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
46 lines (35 loc) · 1.33 KB
/
main.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import feedparser
import openai
import ssl
import random
RSS_FEED_URL = "" # Replace with your RSS feed URL
openai.api_key = "" # Replace with your OpenAI API key
ssl._create_default_https_context = ssl._create_unverified_context
def get_headlines(feed_url):
headlines = []
feed = feedparser.parse(feed_url)
for entry in feed.entries:
headlines.append(entry.title)
return headlines
def rephrase_sentence(sentence):
response = openai.Completion.create(
engine="text-davinci-003",
prompt=f"Rephrase the following sentence, make it short and headline-style, DO NOT rephrase sentences which meaning you do not fully understand, DO NOT use dot at the end of the rewritten sentence and remove '(VIDEO)' and '(FOTO)' text: \"{sentence}\"\n\nRewritten sentence:",
max_tokens=50,
temperature=0.7,
n=1,
stop=None
)
return response.choices[0].text.strip()
def main():
headlines = get_headlines(RSS_FEED_URL)
rephrased_headlines = []
for headline in headlines:
rephrased_headline = rephrase_sentence(headline)
rephrased_headlines.append(rephrased_headline)
random.shuffle(rephrased_headlines)
for i in range(len(rephrased_headlines)):
print(f"Rephrased: {rephrased_headlines[i]}")
print()
if __name__ == "__main__":
main()