Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added requirements.txt + dotenv #2

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
OPENAI_API_KEY=YOUR_OPENAI_API_KEY
MODEL_NAME=gpt-4
MAX_TOKENS=4500
MAX_OUTLINE_TOKENS=1024
TEMPERATURE=0.2

STABILITY_AI_API_KEY=YOUR_STABILITY_AI_API_KEY

WP_URL=YOUR_WP_URL
WP_USERNAME=YOUR_WP_USERNAME
WP_PASSWORD=YOUR_WP_PASSWORD
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.env
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
This is an autoblogger that uses the ChatGPT API and Stable Diffusion API to create fully optimized blog posts and post them automatically to wordpress

## First step

- Install all Dependencies with pip install -r requirements.txt
- Get your stability API key (I am using [dreamstudio]([url](https://dreamstudio.com/api/)))
- Get your OpenAI API Key (GPT-4 is recommended, haven't tested with GPT3.5, 300-500 articles cost me about $50)
- Get your OpenAI API Key (GPT-4 is recommended, GPT3.5 works (but you need to lower the max_tokens), 300-500 articles cost me about $50)
- Create a WordPress App Password, get your user log-in, and your site's URL
- Rename the provided .env.example file to .env and replace the placeholder values with your actual details.
- A plan for your website, this way you can already internally link without worrying about doing it afterwards. If you keep a nice, uniform structure, you will be able to plan out all the content and post it all to your website without using any other internal link system.

[Example Website](https://giucas.com)
Expand Down
19 changes: 11 additions & 8 deletions createblogpost.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@
import base64
import time
from tqdm import tqdm
from dotenv import load_dotenv
load_dotenv()

openai.api_key = 'YOUR_OPEN_AI_KEY' # Add your OpenAI API Key
openai.api_key = os.getenv('OPENAI_API_KEY')
model_name = os.getenv('MODEL_NAME')

def generate_featured_image(text):
api_key = 'YOUR_STABILITY_API_KEY'
api_key = os.getenv('STABILITY_AI_API_KEY')
api_host = 'https://api.stability.ai'
engine_id = 'stable-diffusion-xl-beta-v2-2-2'
response = requests.post(
Expand Down Expand Up @@ -85,10 +88,10 @@ def generate_featured_image(text):
]

response_outline = openai.ChatCompletion.create(
model="gpt-4",
model=model_name,
messages=conversation_outline,
max_tokens=1024,
temperature=0.2
max_tokens = int(os.getenv('MAX_OUTLINE_TOKENS')),
temperature = float(os.getenv('TEMPERATURE'))
)

essay_outline = response_outline['choices'][0]['message']['content']
Expand All @@ -105,10 +108,10 @@ def generate_featured_image(text):
]

response = openai.ChatCompletion.create(
model="gpt-4",
model=model_name,
messages=conversation,
max_tokens=6400,
temperature=0.2
max_tokens = int(os.getenv('MAX_TOKENS')),
temperature = float(os.getenv('TEMPERATURE'))
)


Expand Down
19 changes: 11 additions & 8 deletions createpage.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@
import base64
import time
from tqdm import tqdm
from dotenv import load_dotenv
load_dotenv()

openai.api_key = 'your_open_ai_key' # Add your OpenAI API Key
openai.api_key = os.getenv('OPENAI_API_KEY')
model_name = os.getenv('MODEL_NAME')

def generate_featured_image(brand):
api_key = 'your_stability_key'
api_key = os.getenv('STABILITY_AI_API_KEY')
api_host = 'https://api.stability.ai'
engine_id = 'stable-diffusion-xl-beta-v2-2-2'
response = requests.post(
Expand Down Expand Up @@ -86,10 +89,10 @@ def generate_featured_image(brand):
]

response_outline = openai.ChatCompletion.create(
model="gpt-4",
model=model_name,
messages=conversation_outline,
max_tokens=1024,
temperature=0.2
max_tokens = int(os.getenv('MAX_OUTLINE_TOKENS')),
temperature = float(os.getenv('TEMPERATURE'))
)

essay_outline = response_outline['choices'][0]['message']['content']
Expand All @@ -106,10 +109,10 @@ def generate_featured_image(brand):
]

response = openai.ChatCompletion.create(
model="gpt-4",
model=model_name,
messages=conversation,
max_tokens=6400,
temperature=0.2
max_tokens = int(os.getenv('MAX_TOKENS')),
temperature = float(os.getenv('TEMPERATURE'))
)


Expand Down
7 changes: 7 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
openai
pandas
requests
tqdm
backoff
tenacity
python-dotenv
27 changes: 15 additions & 12 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
stop_after_attempt,
wait_random_exponential,
) # for exponential backoff
from dotenv import load_dotenv
load_dotenv()

@retry(wait=wait_random_exponential(multiplier=1, min=4, max=10), stop=stop_after_attempt(10))
def completion_with_backoff(**kwargs):
Expand All @@ -29,15 +31,16 @@ def completion_with_backoff(**kwargs):



openai.api_key = 'YOUR_OPEN_AI_KEY'
openai.api_key = os.getenv('OPENAI_API_KEY')
model_name = os.getenv('MODEL_NAME')

output_df = pd.DataFrame(columns=['URL Slug', 'Meta Title', 'Description', 'Blog Content', 'Featured Image'])
output_lock = threading.Lock()

# Retry on rate limit error with exponential backoff
@retry(wait=wait_random_exponential(multiplier=1, min=4, max=10), stop=stop_after_attempt(10))
def generate_featured_image(text, meta_title):
api_key = 'YOUR_STABILITY_API_KEY'
api_key = os.getenv('STABILITY_AI_API_KEY')
api_host = 'https://api.stability.ai'
engine_id = 'stable-diffusion-xl-1024-v1-0'
response = requests.post(
Expand Down Expand Up @@ -92,10 +95,10 @@ def generate_blog_post(row):
},
]
response_outline = completion_with_backoff(
model="gpt-4",
model=model_name,
messages=conversation_outline,
max_tokens=1024,
temperature=0.2
max_tokens = int(os.getenv('MAX_OUTLINE_TOKENS')),
temperature = float(os.getenv('TEMPERATURE'))
)
essay_outline = response_outline['choices'][0]['message']['content']

Expand All @@ -111,10 +114,10 @@ def generate_blog_post(row):
},
]
response = completion_with_backoff(
model="gpt-4",
model=model_name,
messages=conversation,
max_tokens=4500,
temperature=0.2
max_tokens = int(os.getenv('MAX_TOKENS')),
temperature = float(os.getenv('TEMPERATURE'))
)


Expand All @@ -132,12 +135,12 @@ def generate_blog_post(row):
tqdm.write(f"Saved blog post for URL Slug {url_slug} to output.csv")


# WordPress site URL
wp_url = 'YOUR_WP_URL'
# WordPress site URL
wp_url = os.getenv('WP_URL')

# WordPress username and password
username = 'your_wp_username'
password = 'your_wp_app_password'
username = os.getenv('WP_USERNAME')
password = os.getenv('WP_PASSWORD')

# Open the image file in binary mode
with open(result['Featured Image'], 'rb') as img:
Expand Down
10 changes: 6 additions & 4 deletions uploadblogpost.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@
import requests
import base64
import os
from dotenv import load_dotenv
load_dotenv()

# Load the CSV file into a pandas dataframe
df = pd.read_csv('output.csv')

# WordPress site URL
wp_url = 'YOUR_WEBSITE_URL'
# WordPress site URL
wp_url = os.getenv('WP_URL')

# WordPress username and password
username = 'YOUR_WORDPRESS_USERNAME'
password = 'YOUR_WP_APP_PASSWORD'
username = os.getenv('WP_USERNAME')
password = os.getenv('WP_PASSWORD')

# Iterate through each row in the CSV file
for index, row in df.iterrows():
Expand Down
9 changes: 6 additions & 3 deletions uploadpage.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,18 @@
import requests
import base64
import os
from dotenv import load_dotenv
load_dotenv()

# Load the CSV file into a pandas dataframe
df = pd.read_csv('output.csv')

wp_url = 'YOUR_WEBSITE_URL'
# WordPress site URL
wp_url = os.getenv('WP_URL')

# WordPress username and password
username = 'YOUR_WORDPRESS_USERNAME'
password = 'YOUR_WP_APP_PASSWORD'
username = os.getenv('WP_USERNAME')
password = os.getenv('WP_PASSWORD')

# Parent page ID
parent_page_id = 10
Expand Down