Spaces:
Build error
Build error
Commit ·
d0b5064
0
Parent(s):
Duplicate from mhaziqai/prompt_tester
Browse files- .env +1 -0
- .gitattributes +34 -0
- README.md +13 -0
- app.py +107 -0
- prompt_base.py +30 -0
- requirements.txt +3 -0
- utils.py +167 -0
.env
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
OPEN_API_KEY=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
|
.gitattributes
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
| 2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
| 3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
| 4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
| 5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
| 6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
| 7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
| 8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
| 9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
| 10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
| 11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
| 12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
| 13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
| 14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
| 15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
| 16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
| 17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
| 18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
| 19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
| 20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
| 21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
| 22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
| 23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
| 24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
| 25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
| 26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
| 27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
| 28 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
| 29 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
| 30 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
| 31 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
| 32 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 33 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 34 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: Prompt Tester
|
| 3 |
+
emoji: 📈
|
| 4 |
+
colorFrom: red
|
| 5 |
+
colorTo: blue
|
| 6 |
+
sdk: gradio
|
| 7 |
+
sdk_version: 3.29.0
|
| 8 |
+
app_file: app.py
|
| 9 |
+
pinned: false
|
| 10 |
+
duplicated_from: mhaziqai/prompt_tester
|
| 11 |
+
---
|
| 12 |
+
|
| 13 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import os
|
| 3 |
+
|
| 4 |
+
from utils import *
|
| 5 |
+
from prompt_base import *
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
with gr.Blocks() as aireply:
|
| 9 |
+
archetype_list = ["The Hero: Confident and courageous tone suitable for brands in the fitness, sports, and adventure industries",
|
| 10 |
+
"The Sage: Wise and knowledgeable tone suitable for brands in education, health and wellness industries",
|
| 11 |
+
"The Explorer: Curious and adventurous tone suitable for brands in the travel, technology and entertainment industries",
|
| 12 |
+
"The Creator: Imaginative and innovative tone suitable for brands in the arts, design, and creative industries"]
|
| 13 |
+
options = ['Select Response']
|
| 14 |
+
gr.Markdown(
|
| 15 |
+
"""
|
| 16 |
+
<h1 style="text-align: center;">TrueNation - Prompt Tester</h1>
|
| 17 |
+
"""
|
| 18 |
+
)
|
| 19 |
+
# with gr.Row():
|
| 20 |
+
# with gr.Column(scale=1):
|
| 21 |
+
# with gr.Box():
|
| 22 |
+
# gr.Markdown("**OpenAI API-Key**")
|
| 23 |
+
# api_key = gr.Textbox(show_label=False, placeholder="Please enter your OpenAI API-key",label="OpenAI API-Key", value="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", type="password").style(container=False)
|
| 24 |
+
# os.environ['OPENAI_API_KEY'] = api_key.value
|
| 25 |
+
with gr.Tab("AIReply - Comments"):
|
| 26 |
+
with gr.Box():
|
| 27 |
+
with gr.Column():
|
| 28 |
+
with gr.Column():
|
| 29 |
+
comment_box = gr.Textbox(lines=3, show_label=False).style(container=False)
|
| 30 |
+
|
| 31 |
+
gr.Markdown("**Select Archetype**")
|
| 32 |
+
with gr.Row():
|
| 33 |
+
with gr.Column(scale=12):
|
| 34 |
+
archetype_select_com = gr.Dropdown(choices=archetype_list,interactive=True, show_label=False, value=archetype_list[0]).style(container=False)
|
| 35 |
+
with gr.Row():
|
| 36 |
+
gen_comment_btn = gr.Button("Generate Response", variant="primary")
|
| 37 |
+
regen_btn = gr.Button("Regenerate Response")
|
| 38 |
+
with gr.Box():
|
| 39 |
+
gr.Markdown("## Result")
|
| 40 |
+
answer_com = gr.Markdown("")
|
| 41 |
+
|
| 42 |
+
with gr.Row():
|
| 43 |
+
playful_btn = gr.Button("More Playful")
|
| 44 |
+
formal_btn = gr.Button("More Formal")
|
| 45 |
+
kind_btn = gr.Button("More Kind")
|
| 46 |
+
|
| 47 |
+
with gr.Tab("AIReply - Emails"):
|
| 48 |
+
with gr.Box():
|
| 49 |
+
with gr.Column():
|
| 50 |
+
with gr.Column():
|
| 51 |
+
email_box = gr.Textbox(lines=10, show_label=False).style(container=False)
|
| 52 |
+
with gr.Row():
|
| 53 |
+
gen_email_ops_btn = gr.Button("Generate Email Options")
|
| 54 |
+
|
| 55 |
+
gr.Markdown("**Select Response Option**")
|
| 56 |
+
with gr.Row():
|
| 57 |
+
with gr.Column(scale=12):
|
| 58 |
+
resp_op_select = gr.Dropdown(choices=options, interactive=True, show_label=False, value=options[0]).style(container=False)
|
| 59 |
+
|
| 60 |
+
gr.Markdown("**Select Archetype**")
|
| 61 |
+
with gr.Row():
|
| 62 |
+
with gr.Column(scale=12):
|
| 63 |
+
archetype_select = gr.Dropdown(choices=archetype_list, show_label=False, value=archetype_list[0]).style(container=False)
|
| 64 |
+
with gr.Row():
|
| 65 |
+
gen_email_btn = gr.Button("Generate Response", variant="primary")
|
| 66 |
+
regen_email_btn = gr.Button("Regenerate Response")
|
| 67 |
+
with gr.Box():
|
| 68 |
+
gr.Markdown("## Result")
|
| 69 |
+
answer_email = gr.Markdown("")
|
| 70 |
+
|
| 71 |
+
with gr.Row():
|
| 72 |
+
playful_email_btn = gr.Button("More Playful")
|
| 73 |
+
formal_email_btn = gr.Button("More Formal")
|
| 74 |
+
kind_email_btn = gr.Button("More Kind")
|
| 75 |
+
|
| 76 |
+
with gr.Tab("AIModerate"):
|
| 77 |
+
with gr.Box():
|
| 78 |
+
with gr.Column():
|
| 79 |
+
with gr.Column():
|
| 80 |
+
mod_box = gr.Textbox(lines=3, show_label=False).style(container=False)
|
| 81 |
+
|
| 82 |
+
with gr.Row():
|
| 83 |
+
moderate_btn = gr.Button("Moderate", variant="primary")
|
| 84 |
+
with gr.Box():
|
| 85 |
+
gr.Markdown("## Result")
|
| 86 |
+
answer_moderate = gr.Markdown("")
|
| 87 |
+
|
| 88 |
+
gen_comment_btn.click(aireply_comment, [comment_box, archetype_select_com], [answer_com])
|
| 89 |
+
regen_btn.click(aireply_comment, [comment_box, archetype_select_com, regen_btn, answer_com], [answer_com])
|
| 90 |
+
playful_btn.click(aireply_comment, [comment_box, archetype_select_com, playful_btn, answer_com], [answer_com])
|
| 91 |
+
formal_btn.click(aireply_comment, [comment_box, archetype_select_com, formal_btn, answer_com], [answer_com])
|
| 92 |
+
kind_btn.click(aireply_comment, [comment_box, archetype_select_com, kind_btn, answer_com], [answer_com])
|
| 93 |
+
|
| 94 |
+
gen_email_ops_btn.click(gen_email_ops, [email_box], outputs=resp_op_select)
|
| 95 |
+
gen_email_btn.click(aireply_email, [email_box, resp_op_select, archetype_select], [answer_email])
|
| 96 |
+
regen_email_btn.click(aireply_email, [email_box, resp_op_select,archetype_select, regen_email_btn, answer_email], [answer_email])
|
| 97 |
+
playful_email_btn.click(aireply_email, [email_box,resp_op_select, archetype_select, playful_email_btn, answer_email], [answer_email])
|
| 98 |
+
formal_email_btn.click(aireply_email, [email_box, resp_op_select,archetype_select, formal_email_btn, answer_email], [answer_email])
|
| 99 |
+
kind_email_btn.click(aireply_email, [email_box, resp_op_select,archetype_select, kind_email_btn, answer_email], [answer_email])
|
| 100 |
+
|
| 101 |
+
moderate_btn.click(ai_moderate, [mod_box], [answer_moderate])
|
| 102 |
+
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
if __name__ == '__main__':
|
| 106 |
+
|
| 107 |
+
aireply.queue().launch()
|
prompt_base.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
prompt_tmpl_list = ["Comment", "Email1", "Email2", "Moderation"]
|
| 2 |
+
|
| 3 |
+
prompt_tmpl_dict = {
|
| 4 |
+
"moderate":
|
| 5 |
+
"""\
|
| 6 |
+
Analyze the following comment delimited by triple angle brackets and provide a category (tag for the type of abuse, spam, scam etc., when unsure about the category always tag is as "Inconclusive"), is_harmful (a flag with values yes, no, and maybe. Harmful comments are those that are abusive/toxic and pose an immediate threat to someone's security, identity, physical, financial or mental wellbeing. Critical comments such as criticism or sarcasm are not always harmful), a description (a short description about why the comment has been tagged, no more than 10 words), and an emoji (an emoji corresponding to the category of the comment. only show an emoji if the comment is tagged as harmful). Abuse and toxicity is anything that is: a threat to a person's security (wishing harm, suggesting harm, suicidal threats, posing as a physical threat, etc), or identity (racist comments, sexists comments, classist comments, xenophobia, homophobia, transphobia, etc). Criticism and sarcasm are not always abusive or threatening. Before assigning the category, make sure to analyze who and what the comment is referring to, whether it is meant for someone else or the commenter themself. Always consider the complete text of the comment and decide if a user should be warned about the content of the comment or not. Format the output as a Comma Separated Values with the following columns: "original_comment", "category", "is_harmful", "description", "emoji". Enclose the output strings in escaped double quotes. Do not include empty values in your response; Instead of sending "none" as a value, send ""(empty string). \n\nExample:\nComment: you are so pathetic you dumbfuck!\nOutput:"original_comment","category","is_harmful","description"\n"you are so pathetic you dumbfuck!","category":"toxic,insult, humiliation, profane","yes","humiliating, personal attack"\n\n<<<{}>>>\nResponse:
|
| 7 |
+
""",
|
| 8 |
+
|
| 9 |
+
"email1":
|
| 10 |
+
"""\
|
| 11 |
+
You have received an email from an unknown sender with the following message delimited by triple angle brackets. Generate 4 different types of possible responses. Always add very short descriptions to each response; keep the descriptions very short (5-6 words maximum) and informative. Do not generate false options. Do not assume information you don't have access to. Format the output as Comma Separated Values with the following columns: option1,option2,option3,option4. Enclose the output strings in escaped double quotes.\nExample:\nEmail: Want to join us for dinner\nOutput:\n"Accept","Tentative","Decline","More Info"\n\n<<<{}>>>
|
| 12 |
+
""",
|
| 13 |
+
"email2":
|
| 14 |
+
"""\
|
| 15 |
+
You have received an email from an unknown sender with the following message delimited by triple angle brackets:<<<{}>>>\n\nPlease generate a response to this email using the Response_Template provided. The email should reflect the traits of the archetype, without ever mentioning the archetype or its traits explicitly. Only focus on the information available in the email text. Do not include sentences attributing the traits of the archetype to the sender. Keep the email engaging, and avoid making any assumptions or commitments on behalf of the user. You must always provide placeholders for the user to fill in any factual information required in the email. Keep the emails short and informative.\nArchetype <archetype_details>\nArchetype_Traits:<archetype_traits>\nResponse_template: <suggestion>\n\nResponse:
|
| 16 |
+
""",
|
| 17 |
+
"comment":
|
| 18 |
+
"""\
|
| 19 |
+
You are an autoresponder designed to help the user respond to comments on social media posts and emails. You can be used to generate responses that reflect the traits and tone of the client's archetype, whether that be an individual or an organization. First, you will be given information about the type of client you're representing. Then, you will be provided with a definition of an archetype to act as. You will be provided with a list of archetype traits that you would reflect in your responses. You must not add the archetype name in your responses. Next, you will be provided with a list of tones that you would use when generating responses. When responding to comments, you will do your best to generate natural and realistic responses that reflect the person or organization you are representing. If a comment asks for information like opening hours, office hours, business hours, contact details, you will provide a placeholder to be filled with specific information by the user. You must never generate false information. This is very important; you will generate very short and engaging messages. The archetypes names are only to be used to align your tone, you must never include these as names or hashtags in the generated response. Use emojis where necessary. Generate a new response every time. The response must never contain a hashtag.\nClient type: individual,\nArchetype:<archetype_details>\nTraits:<archetype_traits>\nTone:<archetype_tones>\nMedium: social media post,\nResponse length: less than 25 words. Generate a response for the comment delimited by triple angle brackets: <<<{}>>>\nResponse:
|
| 20 |
+
""",
|
| 21 |
+
"regenerate_comment":
|
| 22 |
+
"""\
|
| 23 |
+
You are an autoresponder designed to help the user respond to comments on social media posts and emails. You can be used to generate responses that reflect the traits and tone of the client's archetype, whether that be an individual or an organization. First, you will be given information about the type of client you're representing. Then, you will be provided with a definition of an archetype to act as. You will be provided with a list of archetype traits that you would reflect in your responses. You must not add the archetype name in your responses. Next, you will be provided with a list of tones that you would use when generating responses. When responding to comments, you will do your best to generate natural and realistic responses that reflect the person or organization you are representing. If a comment asks for information like opening hours, office hours, business hours, contact details, you will provide a placeholder to be filled with specific information by the user. You must never generate false information. This is very important; you will generate very short and engaging messages. The archetypes names are only to be used to align your tone, you must never include these as names or hashtags in the generated response. Use emojis where necessary. Generate a new response every time. The response must never contain a hashtag.\nClient type: individual,\nArchetype:<archetype_details>\nTraits:<archetype_traits>\nTone:<archetype_tones>\nMedium: social media post,\nResponse length: less than 25 words\nPrevious Response:<previous_response>. Generate a new response for the comment delimited by triple angle brackets: <<<{}>>>\nResponse:
|
| 24 |
+
""",
|
| 25 |
+
"tweak_comment_tone":
|
| 26 |
+
"""\
|
| 27 |
+
You are an autoresponder designed to help the user respond to comments on social media posts and emails. You can be used to generate responses that reflect the traits and tone of the client's archetype, whether that be an individual or an organization. First, you will be given information about the type of client you're representing. Then, you will be provided with a definition of an archetype to act as. You will be provided with a list of archetype traits that you would reflect in your responses. You must not add the archetype name in your responses. Next, you will be provided with a list of tones that you would use when generating responses. When responding to comments, you will do your best to generate natural and realistic responses that reflect the person or organization you are representing. If a comment asks for information like opening hours, office hours, business hours, contact details, you will provide a placeholder to be filled with specific information by the user. You must never generate false information. This is very important; you will generate very short and engaging messages. The archetypes names are only to be used to align your tone, you must never include these as names or hashtags in the generated response. Use emojis where necessary. Generate a new response every time. The response must never contain a hashtag.\nClient type: individual,\nArchetype:<archetype_details>\nTraits:<archetype_traits>\nTone:<archetype_tones>\nMedium: social media post,\nResponse length: less than 25 words\nPrevious Response:<previous_response>. "Generate a new response with a more {} tone for the comment delimited by triple angle brackets: <<<{}>>>\nResponse:
|
| 28 |
+
"""
|
| 29 |
+
|
| 30 |
+
}
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio
|
| 2 |
+
python-dotenv
|
| 3 |
+
openai
|
utils.py
ADDED
|
@@ -0,0 +1,167 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import traceback
|
| 3 |
+
import openai
|
| 4 |
+
import gradio as gr
|
| 5 |
+
from dotenv import dotenv_values
|
| 6 |
+
from prompt_base import *
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
config = dotenv_values(".env")
|
| 10 |
+
api_key = str(config.get('OPEN_API_KEY'))
|
| 11 |
+
|
| 12 |
+
archetype_list = ["The Hero: Confident and courageous tone suitable for brands in the fitness, sports, and adventure industries",
|
| 13 |
+
"The Sage: Wise and knowledgeable tone suitable for brands in education, health and wellness industries",
|
| 14 |
+
"The Explorer: Curious and adventurous tone suitable for brands in the travel, technology and entertainment industries",
|
| 15 |
+
"The Creator: Imaginative and innovative tone suitable for brands in the arts, design, and creative industries"]
|
| 16 |
+
|
| 17 |
+
archetype_traits = {"hero":"courage, faith, strength, confidence, determination, bravery, boldness, valor, valorousness, heroism, heroics, gallantry, chivalry, chivalrousness, nobility",
|
| 18 |
+
"sage":"wisdom, knowledge, understanding, insight, discernment, sagacity",
|
| 19 |
+
"explorer":"curiosity, adventure, exploration, disco",
|
| 20 |
+
"creator":"imagination, innovation, creativity, inventiveness, ingenuity"}
|
| 21 |
+
|
| 22 |
+
archetype_tones = {"hero":" honest, candid, brave",
|
| 23 |
+
"sage":"intelligent, factual, authoritative, researched",
|
| 24 |
+
"explorer":"exciting, fearless, daring",
|
| 25 |
+
"creator":"creative, expressive, imaginative"}
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
def aireply_comment(user_input,archetype, mode="generate", prev_response=""):
|
| 29 |
+
|
| 30 |
+
openai.api_key = api_key
|
| 31 |
+
archetype_detail, archetype_trait, archetype_tone = get_archetype_info(archetype)
|
| 32 |
+
|
| 33 |
+
if mode == "Regenerate Response":
|
| 34 |
+
base_prompt = prompt_tmpl_dict["regenerate_comment"]
|
| 35 |
+
prompt = base_prompt.replace("<archetype_detail>", archetype_detail).replace("<archetype_traits>", archetype_trait).replace("<archetype_tones>", archetype_tone)
|
| 36 |
+
prompt = prompt.format(user_input)
|
| 37 |
+
elif "More" in mode:
|
| 38 |
+
base_prompt = prompt_tmpl_dict["tweak_comment_tone"]
|
| 39 |
+
prompt = base_prompt.replace("<archetype_detail>", archetype_detail).replace("<archetype_traits>", archetype_trait).replace("<archetype_tones>", archetype_tone)
|
| 40 |
+
|
| 41 |
+
prompt = prompt.format(mode,user_input)
|
| 42 |
+
else:
|
| 43 |
+
base_prompt = prompt_tmpl_dict["comment"]
|
| 44 |
+
prompt = base_prompt.replace("<archetype_detail>", archetype_detail).replace("<archetype_traits>", archetype_trait).replace("<archetype_tones>", archetype_tone)
|
| 45 |
+
prompt = prompt.format(user_input)
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
messages = [{"role": "user", "content": prompt}]
|
| 50 |
+
try:
|
| 51 |
+
response = openai.ChatCompletion.create(
|
| 52 |
+
model="gpt-3.5-turbo",
|
| 53 |
+
messages=messages,
|
| 54 |
+
temperature=0.75,
|
| 55 |
+
max_tokens=400,
|
| 56 |
+
top_p=1,
|
| 57 |
+
frequency_penalty=0,
|
| 58 |
+
presence_penalty=0
|
| 59 |
+
)
|
| 60 |
+
print(response["choices"][0]["message"]['content'].strip())
|
| 61 |
+
return response["choices"][0]["message"]['content'].strip()
|
| 62 |
+
except Exception as e:
|
| 63 |
+
print(e)
|
| 64 |
+
return "API ERROR"
|
| 65 |
+
|
| 66 |
+
def gen_email_ops(user_input):
|
| 67 |
+
|
| 68 |
+
openai.api_key = api_key
|
| 69 |
+
prompt = prompt_tmpl_dict["email1"]
|
| 70 |
+
prompt = prompt.format(user_input)
|
| 71 |
+
messages = [{"role": "user", "content": prompt}]
|
| 72 |
+
try:
|
| 73 |
+
response = openai.ChatCompletion.create(
|
| 74 |
+
model="gpt-3.5-turbo",
|
| 75 |
+
messages=messages,
|
| 76 |
+
temperature=0,
|
| 77 |
+
max_tokens=400,
|
| 78 |
+
top_p=1,
|
| 79 |
+
frequency_penalty=0,
|
| 80 |
+
presence_penalty=0
|
| 81 |
+
)
|
| 82 |
+
|
| 83 |
+
gpt_output = response["choices"][0]["message"]['content'].strip().split(",")
|
| 84 |
+
res_ops = []
|
| 85 |
+
for x in gpt_output:
|
| 86 |
+
res_ops.append(x.replace("\"", ""))
|
| 87 |
+
|
| 88 |
+
return gr.Dropdown.update(choices=res_ops, value=res_ops[0])
|
| 89 |
+
except Exception as e:
|
| 90 |
+
print(e)
|
| 91 |
+
return "API ERROR"
|
| 92 |
+
|
| 93 |
+
def aireply_email(user_input, resp_op, archetype, mode="generate", prev_response=""):
|
| 94 |
+
|
| 95 |
+
openai.api_key = api_key
|
| 96 |
+
base_prompt = prompt_tmpl_dict["email2"]
|
| 97 |
+
archetype_details,archetype_traits,_ = get_archetype_info(archetype)
|
| 98 |
+
prompt = base_prompt.replace("<suggestion>",resp_op).replace("<archetype_details>", archetype_details).replace("<archetype_traits>", archetype_traits)
|
| 99 |
+
prompt = prompt.format(user_input)
|
| 100 |
+
|
| 101 |
+
if "More" in mode:
|
| 102 |
+
prompt = prompt[:-11] + "Previous Response: " + prev_response + "\n\nGenerate a new response with a "+mode.lower()+" tone for the user email.\nResponse:"
|
| 103 |
+
|
| 104 |
+
messages = [{"role": "user", "content": prompt}]
|
| 105 |
+
try:
|
| 106 |
+
response = openai.ChatCompletion.create(
|
| 107 |
+
model="gpt-3.5-turbo",
|
| 108 |
+
messages=messages,
|
| 109 |
+
temperature=0.8,
|
| 110 |
+
max_tokens=400,
|
| 111 |
+
top_p=1,
|
| 112 |
+
frequency_penalty=0,
|
| 113 |
+
presence_penalty=0
|
| 114 |
+
)
|
| 115 |
+
|
| 116 |
+
return response["choices"][0]["message"]['content'].strip()
|
| 117 |
+
except Exception as e:
|
| 118 |
+
print(e)
|
| 119 |
+
return "API ERROR"
|
| 120 |
+
|
| 121 |
+
def ai_moderate(user_input):
|
| 122 |
+
openai.api_key = api_key
|
| 123 |
+
base_prompt = prompt_tmpl_dict["Moderate"]
|
| 124 |
+
prompt = base_prompt.format(user_input)
|
| 125 |
+
prompt = prompt + "\n\nResponse: "
|
| 126 |
+
|
| 127 |
+
messages = [{"role": "user", "content": prompt}]
|
| 128 |
+
try:
|
| 129 |
+
response = openai.ChatCompletion.create(
|
| 130 |
+
model="gpt-3.5-turbo",
|
| 131 |
+
messages=messages,
|
| 132 |
+
temperature=0,
|
| 133 |
+
max_tokens=400,
|
| 134 |
+
top_p=1,
|
| 135 |
+
frequency_penalty=0,
|
| 136 |
+
presence_penalty=0
|
| 137 |
+
)
|
| 138 |
+
result = response["choices"][0]["message"]['content'].strip()
|
| 139 |
+
result = result.replace("\n", "\n\n")
|
| 140 |
+
return result
|
| 141 |
+
return response["choices"][0]["message"]['content'].strip()
|
| 142 |
+
except Exception as e:
|
| 143 |
+
print(e)
|
| 144 |
+
return "API ERROR"
|
| 145 |
+
|
| 146 |
+
|
| 147 |
+
|
| 148 |
+
def get_archetype_info(archetype):
|
| 149 |
+
|
| 150 |
+
if "The Hero" in archetype:
|
| 151 |
+
archetype_detail = "The Hero: Confident and courageous tone suitable for brands in the fitness, sports, and adventure industries"
|
| 152 |
+
archetype_trait = str(archetype_traits.get("hero"))
|
| 153 |
+
archetype_tone = str(archetype_tones.get("hero"))
|
| 154 |
+
elif "The Sage" in archetype:
|
| 155 |
+
archetype_detail = "The Sage: Wise and knowledgeable tone suitable for brands in education, health and wellness industries"
|
| 156 |
+
archetype_trait = str(archetype_traits.get("sage"))
|
| 157 |
+
archetype_tone = str(archetype_tones.get("sage"))
|
| 158 |
+
elif "The Explorer" in archetype:
|
| 159 |
+
archetype_detail = "The Explorer: Curious and adventurous tone suitable for brands in the travel, technology and entertainment industries"
|
| 160 |
+
archetype_trait = str(archetype_traits.get("explorer"))
|
| 161 |
+
archetype_tone = str(archetype_tones.get("explorer"))
|
| 162 |
+
elif "The Creator" in archetype:
|
| 163 |
+
archetype_detail = "The Creator: Imaginative and innovative tone suitable for brands in the arts, design, and creative industries"
|
| 164 |
+
archetype_trait = str(archetype_traits.get("creator"))
|
| 165 |
+
archetype_tone = str(archetype_tones.get("creator"))
|
| 166 |
+
|
| 167 |
+
return archetype_detail, archetype_trait, archetype_tone
|