File size: 1,277 Bytes
0e124f8
0392ee8
0e124f8
0392ee8
 
 
0e124f8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2e4e2fe
0e124f8
 
 
 
 
 
 
 
 
 
 
 
a09267a
adfc685
0e124f8
 
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
from openai import OpenAI
from dotenv import dotenv_values
import gradio

config = dotenv_values('.env')
client = OpenAI(api_key = config['API_KEY'])

def outputColor(keyword):
    content = f""" 
    Generate 2 to 6 colors for me in a python list of html color.
    #
    {keyword}
    #
    """
    res = client.chat.completions.create(
    model="gpt-4",
    messages=[
        {"role": "system", "content": 
         "You are a helpful assistant who gives me a python list of html color codes (2 to 6 colors) associated with the topic given by me. Just the list of html color codes, no other words please."},
        {"role": "user", "content": 'black'},
        {"role": "assistant", "content": "['#010101', '#4E4848', '#7F7B7B']"},
        {"role": "user", "content": content},
    ])

    color_list = eval(res.choices[0].message.content)
    html = ''
    for i in color_list:
        html += f"<div style = 'background-color:{i}'>{i}</div>"

    return html

import gradio as gr 
demo = gr.Interface(
    fn = outputColor,
    inputs = 'text',
    outputs = 'html',
    title = 'Association Color Generator',
    description = "Input a topic. I will generate 2 to 6 colors associated with that topic for you !",
    allow_flagging = 'never')

demo.launch(share = True)