Marketing / app.py
BtB-ExpC's picture
gpt-4-1106-preview
0d9b9d4
import openai
import random
import gradio as gr
import os
openai.api_key = os.environ["OpenAPI_Key"]
manual = r"""Tick the appropriate boxes and fill out at least the 'Topic' field. More is optional but recommended.
"""
# Tone of voice NL & EN
schrijfstijl_algemeen = r"""- informatief;
- vooruitstrevend;
- optimistisch;
- beknopt;
- toegankelijk.
"""
schrijfstijl_hero = r"""- zelfverzekerd;
- inspirerend;
- innovatief.
"""
# Define the messages for prompt_1
SystemPrompt_10 = f""""Je bent senior-tekstschrijver gespecialiseerd in websiteteksten. Voor e-learningbedrijf ExpertCollege schrijf je hoogwaardige marketingcopy in de volgende stijl:"""
UserPrompt_10 = r""""prompt"""
AssistantPrompt_10 = r""""prompt"""
UserPrompt_11 = r""""prompt"""
AssistantPrompt_11 = r""""prompt"""
UserPrompt_12 = r""""prompt"""
AssistantPrompt_12 = r""""prompt"""
UserPrompt_13 = r""""prompt"""
AssistantPrompt_13 = r""""prompt"""
UserPrompt_14 = r""""prompt"""
AssistantPrompt_14 = r""""prompt"""
# Define the messages for prompt_2
SystemPrompt_20 = r""""prompt"""
UserPrompt_20 = r""""prompt"""
AssistantPrompt_20 = r""""prompt"""
UserPrompt_21 = r""""prompt"""
AssistantPrompt_21 = r""""prompt"""
UserPrompt_22 = r""""prompt"""
AssistantPrompt_22 = r""""prompt"""
UserPrompt_23 = r""""prompt"""
AssistantPrompt_23 = r""""prompt"""
UserPrompt_24 = r""""prompt"""
AssistantPrompt_24 = r""""prompt"""
# Define the messages for prompt_3
SystemPrompt_30 = r""""prompt"""
UserPrompt_30 = r""""prompt"""
AssistantPrompt_30 = r""""prompt"""
UserPrompt_31 = r""""prompt"""
AssistantPrompt_31 = r""""prompt"""
UserPrompt_32 = r""""prompt"""
AssistantPrompt_32 = r""""prompt"""
UserPrompt_33 = r""""prompt"""
AssistantPrompt_33 = r""""prompt"""
UserPrompt_34 = r""""prompt"""
AssistantPrompt_34 = r""""prompt"""
# Define the messages for prompt_4
SystemPrompt_40 = r""""prompt"""
UserPrompt_40 = r""""prompt"""
AssistantPrompt_40 = r""""prompt"""
UserPrompt_41 = r""""prompt"""
AssistantPrompt_41 = r""""prompt"""
UserPrompt_42 = r""""prompt"""
AssistantPrompt_42 = r""""prompt"""
UserPrompt_43 = r""""prompt"""
AssistantPrompt_43 = r""""prompt"""
UserPrompt_44 = r""""prompt"""
AssistantPrompt_44 = r""""prompt"""
# Function to make API call
def api_call(messages, temperature=0.9, model="gpt-4-1106-preview"):
return openai.ChatCompletion.create(
messages=messages,
temperature=temperature,
model=model
).choices[0].message.content
# Function to be called by Gradio interface for website text
def marketing_inputs(selection, topic="", content="", special_instructions="", length="", language=[]):
if not topic:
return "Please enter a Topic"
if "English" in language:
return "Currently only Dutch functionality is available."
if selection == "Website text":
if topic and not content and not special_instructions:
# Code to execute when only topic_input is filled out
prompt_1 = [
{"role": "system", "content": SystemPrompt_10 + f"""\n{schrijfstijl_algemeen}"""},
{"role": "user", "content": f"""Schrijf een korte websitetekst over {topic}."""}
]
# elif topic_input and content and not special_instructions:
# # Code to execute when topic_input and content are filled out
# prompt_1 = [
# {"role": "system", "content": SystemPrompt_10 + f"""\n{schrijfstijl_algemeen}"""},
# {"role": "user", "content": f"""Schrijf een korte websitetekst over {topic_input}."""}
# elif topic_input and not content and special_instructions:
# # Code to execute when topic_input and special instructions are filled out
# prompt_1 = [
# {"role": "system", "content": SystemPrompt_10 + f"""\n{schrijfstijl_algemeen}"""},
# {"role": "user", "content": f"""Schrijf een korte websitetekst over {topic_input}. Especially make sure to:"""}
# elif topic_input and content and special_instructions:
# # Code to execute when topic_input, content, and special instructions are filled out
# prompt_1 = [
# {"role": "system", "content": SystemPrompt_10 + f"""\n{schrijfstijl_algemeen}"""},
# {"role": "user", "content": f"""Schrijf een korte websitetekst over {topic_input}."""}
websitetekst = api_call(prompt_1, 0.7)
return websitetekst
elif selection == "Socials: posts" or selection == "Socials: comments":
# Dummy return for Socials
return f"Functionality for {selection} is not implemented yet."
# Define the selection radio
selection_radio = gr.Radio(choices=["Website text", "Socials: posts", "Socials: comments"], label="Type")
# Define the input fields and checkboxes for Website texts
topic_input = gr.Textbox(label="Topic")
content = gr.Textbox(label="Content (text should contain info on...)")
special_instructions_input = gr.Textbox(label="Special instructions (optional)")
length_radio = gr.Radio(choices=["short", "medium", "long"], label="Length")
language_checkbox = gr.CheckboxGroup(choices=["Dutch", "English"], label="Language")
# Define the Interface
iface = gr.Interface(
fn=marketing_inputs,
inputs=[selection_radio, topic_input, content, special_instructions_input, length_radio, language_checkbox],
outputs=gr.Textbox(label="Output", show_copy_button=True)
)
iface.launch()