-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
58 lines (41 loc) · 1.55 KB
/
app.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
47
48
49
50
51
52
53
54
55
56
57
58
import openai
from flask import Flask, render_template, request
from dotenv import dotenv_values
import json
config = dotenv_values('.env');
openai.api_key = config["api_key"]
app = Flask(__name__,
template_folder='templates',
static_url_path='',
static_folder='static'
)
def get_colors(msg):
prompt = f"""
You are a color palette generating assistant that responds to text prompts for color palettes
Your should generate color palettes that fit the theme, mood, or instructions in the prompt.
The palettes should be between 2 and 8 colors.
Q: Convert the following verbal description of a color palette into a list of colors: The Mediterranean Sea
A: ["#006699", "#66CCCC", "#F0E68C", "#008000", "#F08080"]
Q: Convert the following verbal description of a color palette into a list of colors: sage, nature, earth
A: ["#EDF1D6", "#9DC08B", "#609966", "#40513B"]
Desired Format: a JSON array of hexadecimal color codes
Q: Convert the following verbal description of a color palette into a list of colors: {msg}
A:
"""
response = openai.Completion.create(
prompt=prompt,
model="text-davinci-003",
max_tokens=200,
)
colors = json.loads(response["choices"][0]["text"])
return colors
@app.route("/palette", methods=["POST"])
def prompt_to_palette():
query = request.form.get("query")
colors = get_colors(query)
return {"colors": colors}
@app.route("/")
def index():
return render_template("index.html")
if __name__ == "__main__":
app.run(debug=True)