File size: 3,148 Bytes
daa0387
 
75cc0d5
daa0387
191f65a
daa0387
 
 
 
 
c3916f9
daa0387
 
 
 
c3916f9
daa0387
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c3916f9
 
daa0387
 
 
c3916f9
daa0387
e64b32f
d67e7af
 
 
daa0387
8d4622a
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
import openai
import gradio as gr
import os

openai.api_key = os.environ['openai.api_key']

messages = [
    {"role": "system", "content": "You are a helpful and kind AI Assistant."},
]

def chatbot(role,language,vernacular,product_name,product_type,platform,placement,country,objective, hashtag,emoji,line_break,learn_model,remark):
    hashtag = "include" if hashtag else "exclude"
    emoji = "include" if emoji else "exclude"
    line_break = "include" if line_break else "exclude"
    learn_model = "learn from " + learn_model if learn_model else ""
    prompt = f"I want you to act as a {role},you are going to advertise a product in language {language},using language formality level of {vernacular} out of 5,product name is {product_name},type of product 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

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")
product_name = gr.Textbox(lines=1, label="Product Name")
product_type = gr.Textbox(lines=1, label="Product Type",placeholder="Body Shampoo")
platform = gr.Radio(["Facebook","Instagram"],label="Advertising Platform")
placement = gr.Dropdown(["Headline and Primary Text","Ads Image Text"], label="Copywriting Placement",allow_custom_value=True)
country = gr.Dropdown(["Malaysia","Singapore","Thailand","Vietnam"],label="Target Country", multiselect=True)
objective = gr.Radio(["Attention","Demand","USP","Urgency"],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="Learning Model", placeholder="Learn from this Example")
remark = gr.Textbox(lines=4, label="Additional Remark/Requirement")
outputs = gr.Textbox(label="Result").style(show_copy_button=True)

chat = gr.Interface(
    fn=chatbot,
    inputs=[role,language,vernacular,product_name,product_type,platform,placement,country,objective,hashtag,emoji,line_break,learn_model,remark],
    outputs=outputs,
    allow_flagging="never",
    title = "AdVentive: Your Personal AI Copy Solution (ECOM)",
    description = "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.",
    article = "version 1.0"
)
chat.launch()