Spaces:
Runtime error
Runtime error
Download app.py from deterjack/ecom-copy-generator: direct link, hf CLI and curl.
- Browser
- Download file 3.15 kB
-
https://huggingface.co/spaces/deterjack/ecom-copy-generator/resolve/main/app.py
- Command line
-
hf download hf://spaces/deterjack/ecom-copy-generator/app.py
-
curl -L -o app.py https://huggingface.co/spaces/deterjack/ecom-copy-generator/resolve/main/app.py
3.15 kB
| 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() | |