Skip to content

Commit

Permalink
functioning front end
Browse files Browse the repository at this point in the history
We now have a properly functioning front end interface integrated and embedded with open.ai 0.27.0
  • Loading branch information
mcnamee98 committed Aug 16, 2023
1 parent 731818f commit b8abc54
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 11 deletions.
53 changes: 51 additions & 2 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 26 additions & 6 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,26 @@
@app.route("/", methods=("GET", "POST"))
def index():
if request.method == "POST":
animal = request.form["animal"]
response = openai.Completion.create(
model="text-davinci-003",
prompt=generate_prompt(animal),
temperature=0.6,

keywords = request.form["keywords"]
audience = request.form["audience"]
length = request.form['length']

completion = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=[
{"role": "system", "content": "You are a helpful writing assistant."
"You will be given a handful of keywords, a target audience, and an article length."
"Please write an article which is Search Engine Optimized."},

{"role": "user", "content": "Keywords:" + keywords +
"Target Audience" + audience +
"Article Length" + length}

]
)
return redirect(url_for("index", result=response.choices[0].text))

return redirect(url_for("index", result=completion.choices[0].message.content))

result = request.args.get("result")
return render_template("index.html", result=result)
Expand All @@ -33,3 +46,10 @@ def generate_prompt(animal):
Names:""".format(
animal.capitalize()
)

def gen_article(keywords, audience, length):
return """"You are a helpful writing assistant. You will be given a handful of keywords,
a target audience, and an article length. Please write the article to be Search Engine Optimized."
""".format(
audience.capitalize()
)
10 changes: 7 additions & 3 deletions templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@

<body>
<img src="{{ url_for('static', filename='dog.png') }}" class="icon" />
<h3>Name my pet</h3>
<h3>Write My SEO Optimized Article</h3>
<form action="/" method="post">
<input type="text" name="animal" placeholder="Enter an animal" required />
<input type="submit" value="Generate names" />

<input type="text" name="keywords" placeholder="Enter one or more keywords" required />
<input type="text" name="audience" placeholder="Enter a target audience" required />
<input type="text" name="length" placeholder="Enter an article length" required />

<input type="submit" value="Generate Article" />
</form>
{% if result %}
<div class="result">{{ result }}</div>
Expand Down

0 comments on commit b8abc54

Please sign in to comment.