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"
{i}
" 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)