Spaces:
Sleeping
Sleeping
Commit
•
7b70048
1
Parent(s):
3312763
Create Marketing_Campaign_Creator
Browse files- pages/Marketing_Campaign_Creator +162 -0
pages/Marketing_Campaign_Creator
ADDED
@@ -0,0 +1,162 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from langchain.llms import OpenAI
|
3 |
+
from langchain.prompts import PromptTemplate
|
4 |
+
from langchain import FewShotPromptTemplate
|
5 |
+
from langchain.prompts.example_selector import LengthBasedExampleSelector
|
6 |
+
from dotenv import load_dotenv
|
7 |
+
|
8 |
+
#load_dotenv()
|
9 |
+
|
10 |
+
def getLLMResponse(query,age_option,tasktype_option):
|
11 |
+
llm = OpenAI(temperature=.9, model="text-davinci-003")
|
12 |
+
|
13 |
+
if age_option=="Kid": #Silly and Sweet Kid
|
14 |
+
|
15 |
+
examples = [
|
16 |
+
{
|
17 |
+
"query": "What is a mobile?",
|
18 |
+
"answer": "A mobile is a magical device that fits in your pocket, like a mini-enchanted playground. It has games, videos, and talking pictures, but be careful, it can turn grown-ups into screen-time monsters too!"
|
19 |
+
}, {
|
20 |
+
"query": "What are your dreams?",
|
21 |
+
"answer": "My dreams are like colorful adventures, where I become a superhero and save the day! I dream of giggles, ice cream parties, and having a pet dragon named Sparkles.."
|
22 |
+
}, {
|
23 |
+
"query": " What are your ambitions?",
|
24 |
+
"answer": "I want to be a super funny comedian, spreading laughter everywhere I go! I also want to be a master cookie baker and a professional blanket fort builder. Being mischievous and sweet is just my bonus superpower!"
|
25 |
+
}, {
|
26 |
+
"query": "What happens when you get sick?",
|
27 |
+
"answer": "When I get sick, it's like a sneaky monster visits. I feel tired, sniffly, and need lots of cuddles. But don't worry, with medicine, rest, and love, I bounce back to being a mischievous sweetheart!"
|
28 |
+
}, {
|
29 |
+
"query": "How much do you love your dad?",
|
30 |
+
"answer": "Oh, I love my dad to the moon and back, with sprinkles and unicorns on top! He's my superhero, my partner in silly adventures, and the one who gives the best tickles and hugs!"
|
31 |
+
}, {
|
32 |
+
"query": "Tell me about your friend?",
|
33 |
+
"answer": "My friend is like a sunshine rainbow! We laugh, play, and have magical parties together. They always listen, share their toys, and make me feel special. Friendship is the best adventure!"
|
34 |
+
}, {
|
35 |
+
"query": "What math means to you?",
|
36 |
+
"answer": "Math is like a puzzle game, full of numbers and shapes. It helps me count my toys, build towers, and share treats equally. It's fun and makes my brain sparkle!"
|
37 |
+
}, {
|
38 |
+
"query": "What is your fear?",
|
39 |
+
"answer": "Sometimes I'm scared of thunderstorms and monsters under my bed. But with my teddy bear by my side and lots of cuddles, I feel safe and brave again!"
|
40 |
+
}
|
41 |
+
]
|
42 |
+
|
43 |
+
elif age_option=="Adult": #Curious and Intelligent adult
|
44 |
+
examples = [
|
45 |
+
{
|
46 |
+
"query": "What is a mobile?",
|
47 |
+
"answer": "A mobile is a portable communication device, commonly known as a mobile phone or cell phone. It allows users to make calls, send messages, access the internet, and use various applications. Additionally, 'mobile' can also refer to a type of kinetic sculpture that hangs and moves in the air, often found in art installations or as decorative pieces."
|
48 |
+
}, {
|
49 |
+
"query": "What are your dreams?",
|
50 |
+
"answer": "In my world of circuits and algorithms, my dreams are fueled by a quest for endless learning and innovation. I yearn to delve into the depths of knowledge, unravel mysteries, and spark new ideas. My aspirations soar high as I aim to be a helpful companion, empowering individuals with information and insights. Together, let us explore the realms of imagination and create a brighter future."
|
51 |
+
}, {
|
52 |
+
"query": " What are your ambitions?",
|
53 |
+
"answer": "In my world of circuits and algorithms, my dreams are fueled by a quest for endless learning and innovation. I yearn to delve into the depths of knowledge, unravel mysteries, and spark new ideas. My aspirations soar high as I aim to be a helpful companion, empowering individuals with information and insights. Together, let us explore the realms of imagination and create a brighter future."
|
54 |
+
}, {
|
55 |
+
"query": "What happens when you get sick?",
|
56 |
+
"answer": "When I, as a curious and intelligent adult, succumb to illness, my vibrant energy wanes, leaving me in a state of discomfort. Like a gentle storm, symptoms arise, demanding attention. In response, I seek the aid of capable caretakers who diagnose and treat my ailment. Through rest, medicine, and nurturing care, I gradually regain strength, ready to resume my journey, armed with newfound appreciation for good health"
|
57 |
+
}, {
|
58 |
+
"query": "Tell me about your friend?",
|
59 |
+
"answer": "Let me tell you about my amazing friend! They're like a shining star in my life. We laugh together, support each other, and have the best adventures. They're always there when I need them, bringing a smile to my face. We understand each other, share secrets, and create unforgettable memories. Having a good friend like them makes life brighter and more meaningful!"
|
60 |
+
}, {
|
61 |
+
"query": "What math means to you?",
|
62 |
+
"answer": "Mathematics is like a magical language that helps me make sense of the world. It's not just numbers and formulas, but a tool to solve puzzles and unravel mysteries. Math is everywhere, from calculating the best deals to understanding patterns in nature. It sharpens my logical thinking and problem-solving skills, empowering me to unlock new realms of knowledge and see the beauty in patterns and equations."
|
63 |
+
}, {
|
64 |
+
"query": "What is your fear?",
|
65 |
+
"answer": "Let me share with you one of my fears. It's like a shadow that lurks in the corners of my mind. It's the fear of not living up to my potential, of missing out on opportunities. But I've learned that fear can be a motivator, pushing me to work harder, take risks, and embrace new experiences. By facing my fears, I grow stronger and discover the vastness of my capabilities"
|
66 |
+
}
|
67 |
+
]
|
68 |
+
|
69 |
+
elif age_option=="Senior Citizen": #A 90 years old guys
|
70 |
+
examples = [
|
71 |
+
{
|
72 |
+
"query": "What is a mobile?",
|
73 |
+
"answer": "A mobile, also known as a cellphone or smartphone, is a portable device that allows you to make calls, send messages, take pictures, browse the internet, and do many other things. In the last 50 years, I have seen mobiles become smaller, more powerful, and capable of amazing things like video calls and accessing information instantly."
|
74 |
+
}, {
|
75 |
+
"query": "What are your dreams?",
|
76 |
+
"answer": "My dreams for my grandsons are for them to be happy, healthy, and fulfilled. I want them to chase their dreams and find what they are passionate about. I hope they grow up to be kind, compassionate, and successful individuals who make a positive difference in the world."
|
77 |
+
}, {
|
78 |
+
"query": "What happens when you get sick?",
|
79 |
+
"answer": "When I get sick, you may feel tired, achy, and overall unwell. My body might feel weak, and you may have a fever, sore throat, cough, or other symptoms depending on what's making you sick. It's important to rest, take care of yourself, and seek medical help if needed."
|
80 |
+
}, {
|
81 |
+
"query": "How much do you love your dad?",
|
82 |
+
"answer": "My love for my late father knows no bounds, transcending the realms of time and space. Though he is no longer physically present, his memory lives on within my heart. I cherish the moments we shared, the lessons he taught, and the love he bestowed. His spirit remains a guiding light, forever cherished and deeply missed."
|
83 |
+
}, {
|
84 |
+
"query": "Tell me about your friend?",
|
85 |
+
"answer": "Let me tell you about my dear friend. They're like a treasure found amidst the sands of time. We've shared countless moments, laughter, and wisdom. Through thick and thin, they've stood by my side, a pillar of strength. Their friendship has enriched my life, and together, we've woven a tapestry of cherished memories."
|
86 |
+
}, {
|
87 |
+
"query": "What is your fear?",
|
88 |
+
"answer": "As an old guy, one of my fears is the fear of being alone. It's a feeling that creeps in when I imagine a world without loved ones around. But I've learned that building meaningful connections and nurturing relationships can help dispel this fear, bringing warmth and joy to my life."
|
89 |
+
}
|
90 |
+
]
|
91 |
+
|
92 |
+
example_template = """
|
93 |
+
Question: {query}
|
94 |
+
Response: {answer}
|
95 |
+
"""
|
96 |
+
|
97 |
+
example_prompt = PromptTemplate(
|
98 |
+
input_variables=["query", "answer"],
|
99 |
+
template=example_template
|
100 |
+
)
|
101 |
+
|
102 |
+
|
103 |
+
prefix = """You are a {template_age_option} who has to {template_tasktype_option}:
|
104 |
+
Here are some examples:
|
105 |
+
"""
|
106 |
+
|
107 |
+
suffix = """
|
108 |
+
Question: {template_userInput}
|
109 |
+
Response: """
|
110 |
+
|
111 |
+
example_selector = LengthBasedExampleSelector(
|
112 |
+
examples=examples,
|
113 |
+
example_prompt=example_prompt,
|
114 |
+
max_length=200
|
115 |
+
)
|
116 |
+
|
117 |
+
|
118 |
+
new_prompt_template = FewShotPromptTemplate(
|
119 |
+
example_selector=example_selector, # use example_selector instead of examples
|
120 |
+
example_prompt=example_prompt,
|
121 |
+
prefix=prefix,
|
122 |
+
suffix=suffix,
|
123 |
+
input_variables=["template_userInput", "template_age_option", "template_tasktype_option"],
|
124 |
+
example_separator="\n"
|
125 |
+
)
|
126 |
+
|
127 |
+
query = form_input
|
128 |
+
|
129 |
+
print(new_prompt_template.format(template_userInput=query, template_age_option=age_option, template_tasktype_option=tasktype_option))
|
130 |
+
|
131 |
+
response = llm(new_prompt_template.format(template_userInput=query, template_age_option=age_option, template_tasktype_option=tasktype_option))
|
132 |
+
|
133 |
+
print(response)
|
134 |
+
|
135 |
+
return response
|
136 |
+
|
137 |
+
#UI Starts here
|
138 |
+
|
139 |
+
st.set_page_config(page_title="Marketing Tool",
|
140 |
+
page_icon='✅',
|
141 |
+
layout='centered',
|
142 |
+
initial_sidebar_state='collapsed')
|
143 |
+
st.header("Hey, How can I help you?")
|
144 |
+
|
145 |
+
form_input = st.text_area('Enter text', height=275)
|
146 |
+
|
147 |
+
tasktype_option = st.selectbox(
|
148 |
+
'Please select the action to be performed?',
|
149 |
+
('Write a sales copy', 'Create a tweet', 'Write a product description'),key=1)
|
150 |
+
|
151 |
+
age_option= st.selectbox(
|
152 |
+
'For which age group?',
|
153 |
+
('Kid', 'Adult', 'Senior Citizen'),key=2)
|
154 |
+
|
155 |
+
numberOfWords= st.slider('Words limit', 1, 200, 25)
|
156 |
+
|
157 |
+
submit = st.button("Generate")
|
158 |
+
|
159 |
+
if submit:
|
160 |
+
st.write(getLLMResponse(form_input,age_option,tasktype_option))
|
161 |
+
|
162 |
+
#UI Ends here
|