├── README.md
├── app.py
├── blog.py
├── config.py
└── index.html
/README.md:
--------------------------------------------------------------------------------
1 | # AI Blog Content Generator
2 |
3 | Created an AI Blog Topic Ideas and Content Generator using OPENAI's GPT-3 and Flask for Python Web App
4 |
5 | Screenshot:
6 |
7 | 
8 |
9 | Screenshots with Generated Content:
10 |
11 | 
12 |
13 |
14 | 
15 |
16 |
17 | 
18 |
--------------------------------------------------------------------------------
/app.py:
--------------------------------------------------------------------------------
1 | from flask import Flask, render_template, request
2 | import config
3 | import blog
4 |
5 |
6 | def page_not_found(e):
7 | return render_template('404.html'), 404
8 |
9 |
10 | app = Flask(__name__)
11 | app.config.from_object(config.config['development'])
12 |
13 | app.register_error_handler(404, page_not_found)
14 |
15 |
16 | @app.route('/', methods=["GET", "POST"])
17 | def index():
18 |
19 | if request.method == 'POST':
20 | if 'form1' in request.form:
21 | prompt = request.form['blogTopic']
22 | blogT = blog.generateBlogTopics(prompt)
23 | blogTopicIdeas = blogT.replace('\n', '
')
24 |
25 | if 'form2' in request.form:
26 | prompt = request.form['blogSection']
27 | blogT = blog.generateBlogSections(prompt)
28 | blogSectionIdeas = blogT.replace('\n', '
')
29 |
30 | if 'form3' in request.form:
31 | prompt = request.form['blogExpander']
32 | blogT = blog.blogSectionExpander(prompt)
33 | blogExpanded = blogT.replace('\n', '
')
34 |
35 |
36 | return render_template('index.html', **locals())
37 |
38 |
39 | if __name__ == '__main__':
40 | app.run(host='0.0.0.0', port='8888', debug=True)
--------------------------------------------------------------------------------
/blog.py:
--------------------------------------------------------------------------------
1 | import os
2 | import openai
3 | import config
4 | openai.api_key = config.OPENAI_API_KEY
5 |
6 | def generateBlogTopics(prompt1):
7 | response = openai.Completion.create(
8 | engine="davinci-instruct-beta-v3",
9 | prompt="Generate blog topics on: {}. \n \n 1. ".format(prompt1),
10 | temperature=0.7,
11 | max_tokens=100,
12 | top_p=1,
13 | frequency_penalty=0,
14 | presence_penalty=0
15 | )
16 |
17 | return response['choices'][0]['text']
18 |
19 | def generateBlogSections(prompt1):
20 | response = openai.Completion.create(
21 | engine="davinci-instruct-beta-v3",
22 | prompt="Expand the blog title in to high level blog sections: {} \n\n- Introduction: ".format(prompt1),
23 | temperature=0.6,
24 | max_tokens=100,
25 | top_p=1,
26 | frequency_penalty=0,
27 | presence_penalty=0
28 | )
29 |
30 | return response['choices'][0]['text']
31 |
32 |
33 | def blogSectionExpander(prompt1):
34 | response = openai.Completion.create(
35 | engine="davinci-instruct-beta-v3",
36 | prompt="Expand the blog section in to a detailed professional , witty and clever explanation.\n\n {}".format(prompt1),
37 | temperature=0.7,
38 | max_tokens=200,
39 | top_p=1,
40 | frequency_penalty=0,
41 | presence_penalty=0
42 | )
43 |
44 | return response['choices'][0]['text']
--------------------------------------------------------------------------------
/config.py:
--------------------------------------------------------------------------------
1 | OPENAI_API_KEY = ''
2 |
3 | class Config(object):
4 | DEBUG = True
5 | TESTING =False
6 |
7 | class DevelopmentConfig(Config):
8 | SECRET_KEY = "this-is-my-api"
9 |
10 | config = {
11 | 'development': DevelopmentConfig,
12 | 'testing': DevelopmentConfig,
13 | 'production': DevelopmentConfig
14 |
15 |
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
This AI Blog Content Generator will allow you to enter a blog topic and keywords --- and get in return a full blog that you can use anywhere. The tool intiially provides a list of topic ideas to choose from, once you select a topic, you can go ahead and generate a full content AI blog.
21 | 22 |