File size: 5,422 Bytes
1c2c598 93dacff 7449e3e 93dacff 7449e3e 93dacff 7449e3e 93dacff 7449e3e 93dacff 1c2c598 0d9b9d4 1c2c598 7449e3e c759db1 7449e3e 1c2c598 7449e3e 1c2c598 93dacff |
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 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
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() |