Spaces:
Sleeping
Sleeping
Commit
·
3565246
1
Parent(s):
1229dae
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,43 +7,29 @@ from dotenv import load_dotenv
|
|
| 7 |
|
| 8 |
load_dotenv()
|
| 9 |
|
| 10 |
-
def
|
| 11 |
-
|
| 12 |
-
"model"
|
| 13 |
-
|
| 14 |
llm = OpenAI(temperature=.9, model="gpt-3.5-turbo-instruct")
|
| 15 |
|
| 16 |
-
|
| 17 |
|
| 18 |
-
# Silly and Sweet Kid
|
| 19 |
-
if age_option == "Kid":
|
| 20 |
examples = [
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
"
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
"
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
"
|
| 35 |
-
"
|
| 36 |
-
|
| 37 |
-
"query": "What happens when you get sick?",
|
| 38 |
-
"answer": "When I get sick, it's like a sneaky monster visits. I feel tired, "
|
| 39 |
-
"sniffly, and need lots of cuddles. But don't worry, with medicine, rest, and love, "
|
| 40 |
-
"I bounce back to being a mischievous sweetheart!"
|
| 41 |
-
}, {
|
| 42 |
-
"query": "How much do you love your dad?",
|
| 43 |
-
"answer": "Oh, I love my dad to the moon and back, with sprinkles and unicorns "
|
| 44 |
-
"on top! He's my superhero, my partner in silly adventures, and the one who gives "
|
| 45 |
-
"the best tickles and hugs!"
|
| 46 |
-
}, {
|
| 47 |
"query": "Tell me about your friend?",
|
| 48 |
"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!"
|
| 49 |
}, {
|
|
@@ -52,10 +38,10 @@ def getLLMResonse(query, age_option, tasktype_option):
|
|
| 52 |
}, {
|
| 53 |
"query": "What is your fear?",
|
| 54 |
"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!"
|
| 55 |
-
|
| 56 |
]
|
| 57 |
-
|
| 58 |
-
elif age_option=="Adult":
|
| 59 |
examples = [
|
| 60 |
{
|
| 61 |
"query": "What is a mobile?",
|
|
@@ -80,8 +66,8 @@ def getLLMResonse(query, age_option, tasktype_option):
|
|
| 80 |
"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"
|
| 81 |
}
|
| 82 |
]
|
| 83 |
-
|
| 84 |
-
elif age_option
|
| 85 |
examples = [
|
| 86 |
{
|
| 87 |
"query": "What is a mobile?",
|
|
@@ -104,24 +90,25 @@ def getLLMResonse(query, age_option, tasktype_option):
|
|
| 104 |
}
|
| 105 |
]
|
| 106 |
|
|
|
|
| 107 |
example_template = """
|
| 108 |
Question: {query}
|
| 109 |
Response: {answer}
|
| 110 |
"""
|
| 111 |
|
| 112 |
example_prompt = PromptTemplate(
|
| 113 |
-
input_variables
|
| 114 |
-
template
|
| 115 |
)
|
| 116 |
|
| 117 |
-
|
| 118 |
-
|
|
|
|
| 119 |
"""
|
| 120 |
|
| 121 |
suffix = """
|
| 122 |
Question: {template_userInput}
|
| 123 |
-
Response:
|
| 124 |
-
"""
|
| 125 |
|
| 126 |
example_selector = LengthBasedExampleSelector(
|
| 127 |
examples=examples,
|
|
@@ -129,36 +116,44 @@ def getLLMResonse(query, age_option, tasktype_option):
|
|
| 129 |
max_length=200
|
| 130 |
)
|
| 131 |
|
|
|
|
| 132 |
new_prompt_template = FewShotPromptTemplate(
|
| 133 |
-
example_selector=example_selector,
|
| 134 |
example_prompt=example_prompt,
|
| 135 |
prefix=prefix,
|
| 136 |
suffix=suffix,
|
| 137 |
-
input_variables=["template_userInput",
|
| 138 |
-
|
| 139 |
)
|
| 140 |
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
response
|
| 144 |
-
template_tasktype_option=tasktype_option))
|
| 145 |
print(response)
|
| 146 |
|
| 147 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 148 |
|
| 149 |
-
st.
|
| 150 |
-
initial_sidebar_state='collapsed')
|
| 151 |
-
st.header("Hey, How can I help you")
|
| 152 |
-
from_iput = st.text_area('Enter text', height=275)
|
| 153 |
|
| 154 |
-
tasktype_option = st.selectbox(
|
| 155 |
-
|
|
|
|
| 156 |
|
| 157 |
-
age_option
|
|
|
|
|
|
|
| 158 |
|
| 159 |
-
numberOfWords
|
| 160 |
|
| 161 |
submit = st.button("Generate")
|
| 162 |
|
| 163 |
if submit:
|
| 164 |
-
st.write(
|
|
|
|
| 7 |
|
| 8 |
load_dotenv()
|
| 9 |
|
| 10 |
+
def getLLMResponse(query,age_option,tasktype_option):
|
| 11 |
+
# 'text-davinci-003' model is depreciated now, so we are using the openai's recommended model
|
|
|
|
|
|
|
| 12 |
llm = OpenAI(temperature=.9, model="gpt-3.5-turbo-instruct")
|
| 13 |
|
| 14 |
+
if age_option=="Kid": #Silly and Sweet Kid
|
| 15 |
|
|
|
|
|
|
|
| 16 |
examples = [
|
| 17 |
+
{
|
| 18 |
+
"query": "What is a mobile?",
|
| 19 |
+
"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!"
|
| 20 |
+
}, {
|
| 21 |
+
"query": "What are your dreams?",
|
| 22 |
+
"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.."
|
| 23 |
+
}, {
|
| 24 |
+
"query": " What are your ambitions?",
|
| 25 |
+
"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!"
|
| 26 |
+
}, {
|
| 27 |
+
"query": "What happens when you get sick?",
|
| 28 |
+
"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!"
|
| 29 |
+
}, {
|
| 30 |
+
"query": "How much do you love your dad?",
|
| 31 |
+
"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!"
|
| 32 |
+
}, {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
"query": "Tell me about your friend?",
|
| 34 |
"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!"
|
| 35 |
}, {
|
|
|
|
| 38 |
}, {
|
| 39 |
"query": "What is your fear?",
|
| 40 |
"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!"
|
| 41 |
+
}
|
| 42 |
]
|
| 43 |
+
|
| 44 |
+
elif age_option=="Adult": #Curious and Intelligent adult
|
| 45 |
examples = [
|
| 46 |
{
|
| 47 |
"query": "What is a mobile?",
|
|
|
|
| 66 |
"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"
|
| 67 |
}
|
| 68 |
]
|
| 69 |
+
|
| 70 |
+
elif age_option=="Senior Citizen": #A 90 years old guys
|
| 71 |
examples = [
|
| 72 |
{
|
| 73 |
"query": "What is a mobile?",
|
|
|
|
| 90 |
}
|
| 91 |
]
|
| 92 |
|
| 93 |
+
|
| 94 |
example_template = """
|
| 95 |
Question: {query}
|
| 96 |
Response: {answer}
|
| 97 |
"""
|
| 98 |
|
| 99 |
example_prompt = PromptTemplate(
|
| 100 |
+
input_variables=["query", "answer"],
|
| 101 |
+
template=example_template
|
| 102 |
)
|
| 103 |
|
| 104 |
+
|
| 105 |
+
prefix = """You are a {template_ageoption}, and {template_tasktype_option}:
|
| 106 |
+
Here are some examples:
|
| 107 |
"""
|
| 108 |
|
| 109 |
suffix = """
|
| 110 |
Question: {template_userInput}
|
| 111 |
+
Response: """
|
|
|
|
| 112 |
|
| 113 |
example_selector = LengthBasedExampleSelector(
|
| 114 |
examples=examples,
|
|
|
|
| 116 |
max_length=200
|
| 117 |
)
|
| 118 |
|
| 119 |
+
|
| 120 |
new_prompt_template = FewShotPromptTemplate(
|
| 121 |
+
example_selector=example_selector, # use example_selector instead of examples
|
| 122 |
example_prompt=example_prompt,
|
| 123 |
prefix=prefix,
|
| 124 |
suffix=suffix,
|
| 125 |
+
input_variables=["template_userInput","template_ageoption","template_tasktype_option"],
|
| 126 |
+
example_separator="\n"
|
| 127 |
)
|
| 128 |
|
| 129 |
+
|
| 130 |
+
print(new_prompt_template.format(template_userInput=query,template_ageoption=age_option,template_tasktype_option=tasktype_option))
|
| 131 |
+
response=llm(new_prompt_template.format(template_userInput=query,template_ageoption=age_option,template_tasktype_option=tasktype_option))
|
|
|
|
| 132 |
print(response)
|
| 133 |
|
| 134 |
+
return response
|
| 135 |
+
|
| 136 |
+
#UI Starts here
|
| 137 |
+
|
| 138 |
+
st.set_page_config(page_title="Marketing Tool",
|
| 139 |
+
page_icon='✅',
|
| 140 |
+
layout='centered',
|
| 141 |
+
initial_sidebar_state='collapsed')
|
| 142 |
+
st.header("Hey, How can I help you?")
|
| 143 |
|
| 144 |
+
form_input = st.text_area('Enter text', height=275)
|
|
|
|
|
|
|
|
|
|
| 145 |
|
| 146 |
+
tasktype_option = st.selectbox(
|
| 147 |
+
'Please select the action to be performed?',
|
| 148 |
+
('Write a sales copy', 'Create a tweet', 'Write a product description'),key=1)
|
| 149 |
|
| 150 |
+
age_option= st.selectbox(
|
| 151 |
+
'For which age group?',
|
| 152 |
+
('Kid', 'Adult', 'senior Citizen'),key=2)
|
| 153 |
|
| 154 |
+
numberOfWords= st.slider('Words limit', 1, 200, 25)
|
| 155 |
|
| 156 |
submit = st.button("Generate")
|
| 157 |
|
| 158 |
if submit:
|
| 159 |
+
st.write(getLLMResponse(form_input,age_option,tasktype_option))
|