raghavgpt001 commited on
Commit
fab1cbd
1 Parent(s): 1a28b70

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -52
app.py CHANGED
@@ -7,11 +7,11 @@ import os
7
 
8
  os.environ["OPENAI_API_KEY"]="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"
9
 
10
- def getLLMResponse(query,age_option,tasktype_option):
11
- llm = OpenAI(temperature=.9)
 
12
  examples=[]
13
-
14
- if age_option=="Kid": #Silly and Sweet Kid
15
 
16
  examples = [
17
  {
@@ -23,25 +23,10 @@ def getLLMResponse(query,age_option,tasktype_option):
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
- }, {
36
- "query": "What math means to you?",
37
- "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!"
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?",
@@ -52,22 +37,10 @@ def getLLMResponse(query,age_option,tasktype_option):
52
  }, {
53
  "query": " What are your ambitions?",
54
  "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."
55
- }, {
56
- "query": "What happens when you get sick?",
57
- "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"
58
- }, {
59
- "query": "Tell me about your friend?",
60
- "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!"
61
- }, {
62
- "query": "What math means to you?",
63
- "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."
64
- }, {
65
- "query": "What is your fear?",
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?",
@@ -78,15 +51,6 @@ def getLLMResponse(query,age_option,tasktype_option):
78
  }, {
79
  "query": "What happens when you get sick?",
80
  "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."
81
- }, {
82
- "query": "How much do you love your dad?",
83
- "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."
84
- }, {
85
- "query": "Tell me about your friend?",
86
- "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."
87
- }, {
88
- "query": "What is your fear?",
89
- "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."
90
  }
91
  ]
92
 
@@ -102,8 +66,8 @@ def getLLMResponse(query,age_option,tasktype_option):
102
  )
103
 
104
 
105
- prefix = """You are a {template_ageoption}, and {template_tasktype_option}:
106
- Here are some examples:
107
  """
108
 
109
  suffix = """
@@ -126,20 +90,20 @@ def getLLMResponse(query,age_option,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
 
@@ -149,12 +113,11 @@ tasktype_option = st.selectbox(
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))
160
-
 
7
 
8
  os.environ["OPENAI_API_KEY"]="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"
9
 
10
+ def getLLMResponse(query,age_option,tasktype_option,numberOfWords):
11
+ llm = OpenAI(model="gpt-3.5-turbo-instruct", temperature=.9)
12
+
13
  examples=[]
14
+ if age_option=="Kids": #Silly and Sweet Kid
 
15
 
16
  examples = [
17
  {
 
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
  ]
28
 
29
+ elif age_option=="Adults": #Curious and Intelligent adult
30
  examples = [
31
  {
32
  "query": "What is a mobile?",
 
37
  }, {
38
  "query": " What are your ambitions?",
39
  "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."
 
 
 
 
 
 
 
 
 
 
 
 
40
  }
41
  ]
42
 
43
+ elif age_option=="Senior Citizens": #A 90 years old guys
44
  examples = [
45
  {
46
  "query": "What is a mobile?",
 
51
  }, {
52
  "query": "What happens when you get sick?",
53
  "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."
 
 
 
 
 
 
 
 
 
54
  }
55
  ]
56
 
 
66
  )
67
 
68
 
69
+ prefix = """You need to {template_tasktype_option} for a {template_ageoption} in not more than {template_numberOfWords} words:
70
+ Here are some examples of how you should tailor your response for this person:
71
  """
72
 
73
  suffix = """
 
90
  example_separator="\n"
91
  )
92
 
93
+ formated_prompt = new_prompt_template.format(template_userInput=query,template_ageoption=age_option,template_tasktype_option=tasktype_option,template_numberOfWords=str(numberOfWords))
94
+ print(formated_prompt)
95
+ response=llm(formated_prompt)
96
  print(response)
97
 
98
  return response
99
 
100
+ #Frontend Starts here
101
 
102
  st.set_page_config(page_title="Marketing Tool",
103
  page_icon='✅',
104
  layout='centered',
105
  initial_sidebar_state='collapsed')
106
+ st.header("Hey, how can I help you?")
107
 
108
  form_input = st.text_area('Enter text', height=275)
109
 
 
113
 
114
  age_option= st.selectbox(
115
  'For which age group?',
116
+ ('Kids', 'Adults', 'Senior Citizens'),key=2)
117
 
118
  numberOfWords= st.slider('Words limit', 1, 200, 25)
119
 
120
  submit = st.button("Generate")
121
 
122
  if submit:
123
+ st.write(getLLMResponse(form_input,age_option,tasktype_option,numberOfWords))