lorentz commited on
Commit
bba9405
1 Parent(s): c7ccf48

Upload 5 files

Browse files
Files changed (5) hide show
  1. README.md +5 -5
  2. app.py +160 -0
  3. env-sample.txt +1 -0
  4. gitattributes.txt +34 -0
  5. requirements.txt +5 -0
README.md CHANGED
@@ -1,12 +1,12 @@
1
  ---
2
- title: Llm 3
3
  emoji: 💻
4
- colorFrom: blue
5
- colorTo: yellow
6
  sdk: streamlit
7
- sdk_version: 1.30.0
8
  app_file: app.py
9
  pinned: false
10
  ---
11
 
12
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
  ---
2
+ title: Lorentz's LLM Marketing Campaign App
3
  emoji: 💻
4
+ colorFrom: pink
5
+ colorTo: purple
6
  sdk: streamlit
7
+ sdk_version: 1.21.0
8
  app_file: app.py
9
  pinned: false
10
  ---
11
 
12
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py ADDED
@@ -0,0 +1,160 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
93
+ example_template = """
94
+ Question: {query}
95
+ Response: {answer}
96
+ """
97
+
98
+ example_prompt = PromptTemplate(
99
+ input_variables=["query", "answer"],
100
+ template=example_template
101
+ )
102
+
103
+
104
+ prefix = """You are a {template_ageoption}, and {template_tasktype_option}:
105
+ Here are some examples:
106
+ """
107
+
108
+ suffix = """
109
+ Question: {template_userInput}
110
+ Response: """
111
+
112
+ example_selector = LengthBasedExampleSelector(
113
+ examples=examples,
114
+ example_prompt=example_prompt,
115
+ max_length=200
116
+ )
117
+
118
+
119
+ new_prompt_template = FewShotPromptTemplate(
120
+ example_selector=example_selector, # use example_selector instead of examples
121
+ example_prompt=example_prompt,
122
+ prefix=prefix,
123
+ suffix=suffix,
124
+ input_variables=["template_userInput","template_ageoption","template_tasktype_option"],
125
+ example_separator="\n"
126
+ )
127
+
128
+
129
+ print(new_prompt_template.format(template_userInput=query,template_ageoption=age_option,template_tasktype_option=tasktype_option))
130
+ response=llm(new_prompt_template.format(template_userInput=query,template_ageoption=age_option,template_tasktype_option=tasktype_option))
131
+ print(response)
132
+
133
+ return response
134
+
135
+ #UI Starts here
136
+
137
+ st.set_page_config(page_title="Marketing Tool",
138
+ page_icon='✅',
139
+ layout='centered',
140
+ initial_sidebar_state='collapsed')
141
+ st.header("Hey, How can I help you?")
142
+
143
+ form_input = st.text_area('Enter text', height=275)
144
+
145
+ tasktype_option = st.selectbox(
146
+ 'Please select the action to be performed?',
147
+ ('Write a sales copy', 'Create a tweet', 'Write a product description'),key=1)
148
+
149
+ age_option= st.selectbox(
150
+ 'For which age group?',
151
+ ('Kid', 'Adult', 'senior Citizen'),key=2)
152
+
153
+ numberOfWords= st.slider('Words limit', 1, 200, 25)
154
+
155
+ submit = st.button("Generate")
156
+
157
+ if submit:
158
+ st.write(getLLMResponse(form_input,tasktype_option,age_option))
159
+
160
+
env-sample.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ OPENAI_API_KEY=""
gitattributes.txt 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
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ langchain
2
+ streamlit
3
+ openai==0.28.0
4
+ tiktoken
5
+ python-dotenv