import openai import gradio as gr import os openai.api_key = os.environ['openai.api_key'] def adsbot(role,language,vernacular,sensational,product_name,product_type,platform,placement,country,objective, hashtag,emoji,line_break,learn_model,remark): messages = [ {"role": "system", "content": "You are a helpful and kind AI Assistant."}, ] hashtag = "include" if hashtag else "exclude" emoji = "include" if emoji else "exclude" line_break = "include" if line_break else "exclude" learn_model = "based on this story: " + learn_model if learn_model else "" prompt = f"I want you to act as a {role},you are going to advertise a brand in language {language},using language formality level of {vernacular} out of 5,sensational level of {sensational} out of 5,,brand name is {product_name},type of brand is {product_type},you are going to advertise this on {platform},I want you to generate {placement},your target country is {country},the objective is to create {objective},{hashtag} hashtag,{emoji} emoji,{line_break} line break,{learn_model},{remark}" messages.append({"role": "user", "content": prompt}) chat = openai.ChatCompletion.create( model="gpt-4", messages=messages ) reply = chat.choices[0].message.content messages.append({"role": "assistant", "content": reply}) return reply def storybot(role,language,vernacular,product_name,product_type,country,objective,learn_model,word_limit,remark): messages = [ {"role": "system", "content": "You are a helpful and kind AI Assistant."}, ] prompt = f"You act as a {role}, I'd like you to create a story involving an {product_type} with brand name {product_name}. I will provide a base story, and I need you to modify this story to promote {product_type}, weaving them together to generate a new and exciting narrative, in language {language} with language formality level of {vernacular} out of 5, target country is {country}, the objective is to create {objective}. Based on this story {learn_model}. Word limit maximum {word_limit}.{remark}" messages.append({"role": "user", "content": prompt}) chat = openai.ChatCompletion.create( model="gpt-4", messages=messages ) reply = chat.choices[0].message.content messages.append({"role": "assistant", "content": reply}) return reply with gr.Blocks() as chat: gr.Markdown( """ # AdVentive: Your AI Copy Solution This software application has been specifically developed for exclusive use within our organization. It is not intended for public or external distribution. Sharing or disseminating this app outside of our organization is strictly prohibited. """) with gr.Tab("Ads Generator"): with gr.Row(): with gr.Column(): role = gr.Textbox(lines=1, label="Role",placeholder="Copywriter") language = gr.Dropdown(["English","Chinese","Malay","Thai","Vietnamese"], label="Target Language",allow_custom_value=True) vernacular = gr.Slider(0, 5, step=1, label="Formality Level", info="0 denotes maximum informality, 5 denotes maximum formality") sensational = gr.Slider(0, 5, step=1, label="Sensational Level", info="0 denotes minimum sensational, 5 denotes maximum sensational") product_name = gr.Radio(["GOD55","Betsuper"],label="Brand Name") product_type = gr.Radio(["Online Casino"],label="Brand Type") platform = gr.Radio(["Facebook","Instagram"],label="Advertising Platform") placement = gr.Dropdown(["Headline and Primary Text","Ads Image Text - 1 line text"], label="Copywriting Placement",allow_custom_value=True) country = gr.Dropdown(["Malaysia","Singapore","Thailand","Vietnam"],label="Target Country", multiselect=True) objective = gr.Radio(["Brand Attention","Brand Demand","Brand USP","Story Related"],label="Ads Objective") hashtag = gr.Checkbox(value=True,label="Include Hashtag?") emoji = gr.Checkbox(value=True,label="Include Emoji?") line_break = gr.Checkbox(value=True,label="Allow Line Break?") learn_model=gr.Textbox(lines=4, label="Story Model", placeholder="Based on this story") remark = gr.Textbox(lines=4, label="Additional Remark/Requirement") with gr.Column(): ads_inputs = [role,language,vernacular,sensational,product_name,product_type,platform,placement,country,objective, hashtag,emoji,line_break,learn_model,remark] ads_outputs = gr.Textbox(label="Result",show_copy_button=True) ads_button = gr.Button("Generate Ads") with gr.Tab("Story Generator"): with gr.Row(): with gr.Column(): role = gr.Textbox(lines=1, label="Role",placeholder="News Reporter") language = gr.Dropdown(["English","Chinese","Malay","Thai","Vietnamese"], label="Target Language",allow_custom_value=True) vernacular = gr.Slider(0, 5, step=1, label="Formality Level", info="0 denotes maximum informality, 5 denotes maximum formality") product_name = gr.Radio(["GOD55","Betsuper"],label="Brand Name") product_type = gr.Radio(["Online Casino"],label="Brand Type") country = gr.Dropdown(["Malaysia","Singapore","Thailand","Vietnam"],label="Target Country", multiselect=True) objective = gr.Radio(["Brand Attention","Brand Demand","Brand USP"],label="Ads Objective") learn_model=gr.Textbox(lines=4, label="Story Model", placeholder="Based on this story") word_limit = gr.Slider(10, 3000, step=10, label="Word Limit", info="minimum 10 words, maximum 3000 words") remark = gr.Textbox(lines=4, label="Additional Remark/Requirement") with gr.Column(): story_inputs = [role,language,vernacular,product_name,product_type,country,objective,learn_model,word_limit,remark] story_outputs = gr.Textbox(label="Result",show_copy_button=True) story_button = gr.Button("Generate Story") ads_button.click(adsbot, ads_inputs, ads_outputs) story_button.click(storybot, story_inputs, story_outputs) gr.Markdown("version 1.1.1") chat.queue(concurrency_count=3) chat.launch()