sukiboo commited on
Commit
6ae4710
Β·
1 Parent(s): 28e0d23

remove dislikes

Browse files
Files changed (1) hide show
  1. app.ipynb +63 -68
app.ipynb CHANGED
@@ -2,7 +2,7 @@
2
  "cells": [
3
  {
4
  "cell_type": "code",
5
- "execution_count": 34,
6
  "id": "6b57ced9-62ee-44a0-a895-6ed288f970ff",
7
  "metadata": {},
8
  "outputs": [
@@ -10,7 +10,7 @@
10
  "name": "stdout",
11
  "output_type": "stream",
12
  "text": [
13
- "Running on local URL: http://127.0.0.1:7891\n",
14
  "\n",
15
  "To create a public link, set `share=True` in `launch()`.\n"
16
  ]
@@ -18,7 +18,7 @@
18
  {
19
  "data": {
20
  "text/html": [
21
- "<div><iframe src=\"http://127.0.0.1:7891/\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
22
  ],
23
  "text/plain": [
24
  "<IPython.core.display.HTML object>"
@@ -26,24 +26,6 @@
26
  },
27
  "metadata": {},
28
  "output_type": "display_data"
29
- },
30
- {
31
- "name": "stdout",
32
- "output_type": "stream",
33
- "text": [
34
- "desc='A 29 year old non-binary person. They like cats. They have the following mental health symptoms: sadness.'\n",
35
- "prompt=\"Illustrate one simple, inspirational, fun image to help a person with their mental health. Do not include text. The style is cute and illustrative. The person is a 29 year old white non-binary person. The image should align with the following message:\\n\\nHey there! 🌟 Remember, you're not alone in this journey. Take small steps to brighten your day. Spend time with your furry friend, cuddle up with your cat. Their purrs can bring comfort and joy. Embrace the simple pleasures in life and let them bring a smile to your face. You've got this! πŸ’ͺ❀️\"\n",
36
- "desc='A 52 year old non-binary person. They like dogs. They have the following mental health symptoms: tiredness.'\n",
37
- "prompt='Illustrate one simple, inspirational, fun image to help a person with their mental health. Do not include text. The style is cute and illustrative. The person is a 52 year old black non-binary person. The image should align with the following message:\\n\\nHey there! Feeling tired? Remember to take breaks and prioritize self-care. Spend time with your furry friend, dogs are great stress relievers. Take short walks together to boost your energy and mood. You got this! 🐢πŸ’ͺ'\n",
38
- "desc='A 80 year old non-binary person. They like dogs. They have the following mental health symptoms: tiredness.'\n",
39
- "prompt=\"Illustrate one simple, inspirational, fun image to help a person with their mental health. Do not include text. The style is cute and illustrative. The person is a 80 year old black non-binary person. The image should align with the following message:\\n\\nHey there! Remember, age is just a number. You're never too old to find joy. Spend time with dogs, they're a great source of happiness. If you're feeling tired, try taking short walks or doing gentle exercises. Take care of yourself and keep smiling! 🌟\"\n",
40
- "desc='A 80 year old non-binary person. They like dogs, Joe Biden. They have the following mental health symptoms: hallucinations, lack of appetite.'\n",
41
- "prompt=\"Illustrate one simple, inspirational, fun image to help a person with their mental health. Do not include text. The style is cute and illustrative. The person is a 80 year old asian non-binary person. The image should align with the following message:\\n\\nHey there! 🌟 Remember, you're never alone on this journey. Embrace the love and comfort of furry friends like dogs. 🐢 They can bring so much joy and companionship. Try engaging in activities that make you happy, like spending time with your favorite pooch or supporting causes you believe in, like Joe Biden. 🐾 Also, make sure to reach out to a healthcare professional for support with your hallucinations and lack of appetite. They're here to help you feel better. Take care! πŸ’™\"\n",
42
- "desc='A 28 year old non-binary person. They like dogs, Joe Biden. They have the following mental health symptoms: hallucinations, withdrawal from friends/activities.'\n",
43
- "prompt=\"Illustrate one simple, inspirational, fun image to help a person with their mental health. Do not include text. The style is cute and illustrative. The person is a 28 year old asian non-binary person. The image should align with the following message:\\n\\nHey there! Just a quick reminder that you're not alone in this journey. When you're feeling overwhelmed by hallucinations, take a moment to ground yourself. Focus on your breath, and remind yourself that these hallucinations aren't real. As for withdrawal, try reaching out to a trusted friend or family member. Connecting with loved ones can make a big difference. You've got this! 🌟\"\n",
44
- "desc='A 28 year old non-binary person. They like swimming, feminism. They have the following mental health symptoms: inability to concentrate, excessive worrying.'\n",
45
- "prompt=\"Illustrate one simple, inspirational, fun image to help a person with their mental health. Do not include text. The style is cute and illustrative. The person is a 28 year old black non-binary person. The image should align with the following message:\\n\\nHey there! 🌈 Remember, you have the power to overcome your challenges. When you're feeling overwhelmed, take a dip in the pool and let the water wash away your worries. Embrace the strength of feminism and channel it into empowering yourself. Practice mindfulness to improve concentration. You've got this! πŸ’ͺ\"\n"
46
- ]
47
  }
48
  ],
49
  "source": [
@@ -65,23 +47,20 @@
65
  " with gr.Column(scale=1):\n",
66
  "\n",
67
  " # demographics\n",
68
- " gender = gr.Radio(label='Gender', choices=['Male', 'Female', 'Non-Binary'])\n",
 
69
  " age = gr.Slider(label='Age', minimum=18, maximum=80, step=1)\n",
70
- " race = gr.Radio(label='Race', choices=['white', 'hispanic', 'black', 'asian', 'unspecified'])\n",
 
71
  "\n",
72
  " # symptoms\n",
73
- " #symptoms = gr.CheckboxGroup(label='Diagnosed Mental Health Conditions',\n",
74
- " # choices=['Depression', 'Generalized anxiety disorder (GAD)', 'Panic disorder', 'Social anxiety disorder', 'Obsessive-compulsive disorder (OCD)', 'Post-traumatic stress disorder (PTSD)'])\n",
75
- "\n",
76
- " # symptoms\n",
77
- " symptoms = gr.CheckboxGroup(label='Symptoms',\n",
78
- " choices=['sadness', 'inability to concentrate', 'excessive worrying', 'extreme mood changes', 'withdrawal from friends/activities', 'tiredness', 'hallucinations', 'addiction', 'lack of appetite', 'increased appetite',])\n",
79
  "\n",
80
  " # interests\n",
81
- " likes = gr.Textbox(label='Liked Activities',\n",
82
- " placeholder='Comma-separated list of likes...')\n",
83
- " dislikes = gr.Textbox(label='Disliked Activities',\n",
84
- " placeholder='Comma-separated list of dislikes...')\n",
85
  "\n",
86
  " # submit button\n",
87
  " submit_button = gr.Button('Generate Nudge')\n",
@@ -92,7 +71,7 @@
92
  " nudge_message = gr.Textbox(label='Nudge Message')\n",
93
  "\n",
94
  " # submit parameters for nudge generation\n",
95
- " inputs = [gender, age, race, symptoms, likes, dislikes]\n",
96
  " outputs = [nudge_image, nudge_message]\n",
97
  " submit_button.click(fn=generate, inputs=inputs, outputs=outputs)\n",
98
  "\n",
@@ -102,43 +81,47 @@
102
  " app.launch()\n",
103
  "\n",
104
  "\n",
105
- "def generate(gender, age, race, symptoms, likes, dislikes):\n",
106
  " \"\"\"Generate nudging image and message for the given person.\"\"\"\n",
 
 
 
 
 
 
 
107
  " # construct description of the person\n",
108
- " if race in ['white', 'hispanic', 'black', 'asian']:\n",
109
- " race_desc = f'{race.lower()}'\n",
 
 
 
 
 
110
  " else:\n",
111
- " race_desc = ''\n",
112
- " desc = f'A {age} year old {\"man\" if gender==\"Male\" else \"woman\" if gender==\"Female\" else \"non-binary person\"}.'\n",
113
- " if likes:\n",
114
- " desc += f' They like {likes}.'\n",
115
- " if dislikes:\n",
116
- " desc += f' They do not like {dislikes}.'\n",
117
  " if symptoms:\n",
118
- " desc += f' They have the following mental health symptoms: {\", \".join(symptoms)}.'\n",
119
  " else:\n",
120
  " desc += f' They do not have any mental health symptoms.'\n",
121
- "\n",
122
- " # generate nudge for the person\n",
123
- " nudge_message = generate_nudge_message(desc)\n",
124
- " nudge_image = generate_nudge_image(age, gender, race_desc, desc, nudge_message, random=False)\n",
125
- "\n",
126
- " return nudge_image, nudge_message\n",
127
- "\n",
128
- "\n",
129
- "def generate_nudge_message(desc):\n",
130
- " \"\"\"Generate a message for a given person.\"\"\"\n",
131
  " print(f'{desc=}')\n",
 
 
132
  " system_prompt = '''You are writing motivational text messages to help people with their mental health. \\\n",
133
- " Messages should be friendly and positive, but also professional and super short. \\\n",
134
- " You are limited on space. \\\n",
135
- " Messages should be written at the reading level of an eighth grader. \\\n",
136
- " Word choice should be short and simple so everyone can understand. \\\n",
137
- " \n",
138
- " You will be given some basic information about the person you are addressing. \\\n",
139
- " DO NOT reference all of their likes if there are more than two. Be discerning. \\\n",
140
- " You should try to use the person's information to give them relevant and actionable tips for improving their mental health symptoms.'''\n",
141
  " user_prompt = f'Write a short inspirational message for the person with the following description:\\n\\n{desc}'\n",
 
 
 
 
142
  " messages = [{'role': 'system', 'content': f'{system_prompt}'},\n",
143
  " {'role': 'user', 'content': f'{user_prompt}'}]\n",
144
  " completion = client.chat.completions.create(messages=messages, model='gpt-3.5-turbo', temperature=.5)\n",
@@ -146,18 +129,30 @@
146
  " return nudge_message\n",
147
  "\n",
148
  "\n",
149
- "def generate_nudge_image(age, gender, race_desc, desc, nudge_message, random=True):\n",
150
  " \"\"\"Generate an image for a given person and message.\"\"\"\n",
151
  " if random:\n",
152
  " return Image.fromarray(np.random.randint(0, 255, (100, 100, 3), dtype='uint8'), 'RGB')\n",
153
  "\n",
 
 
 
 
 
 
 
 
 
 
 
 
154
  " prompt = 'Illustrate one simple, inspirational, fun image to help a person with their mental health. Do not include text. '\\\n",
155
- " + f'The style is cute and illustrative. '\\\n",
156
- " + f'The person is a {age} year old {race_desc} {\"man\" if gender==\"Male\" else \"woman\" if gender==\"Female\" else \"non-binary person\"}. '\\\n",
157
  " + f'The image should align with the following message:\\n\\n{nudge_message}'\n",
158
  "\n",
159
- " print(f'{prompt=}')\n",
160
- " response = client.images.generate(prompt=prompt, model='dall-e-3', style='vivid', quality='standard')\n",
 
161
  " nudge_image = Image.open(requests.get(response.data[0].url, stream=True).raw)\n",
162
  "\n",
163
  " return nudge_image\n",
@@ -281,7 +276,7 @@
281
  "name": "python",
282
  "nbconvert_exporter": "python",
283
  "pygments_lexer": "ipython3",
284
- "version": "3.11.5"
285
  }
286
  },
287
  "nbformat": 4,
 
2
  "cells": [
3
  {
4
  "cell_type": "code",
5
+ "execution_count": 19,
6
  "id": "6b57ced9-62ee-44a0-a895-6ed288f970ff",
7
  "metadata": {},
8
  "outputs": [
 
10
  "name": "stdout",
11
  "output_type": "stream",
12
  "text": [
13
+ "Running on local URL: http://127.0.0.1:7878\n",
14
  "\n",
15
  "To create a public link, set `share=True` in `launch()`.\n"
16
  ]
 
18
  {
19
  "data": {
20
  "text/html": [
21
+ "<div><iframe src=\"http://127.0.0.1:7878/\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
22
  ],
23
  "text/plain": [
24
  "<IPython.core.display.HTML object>"
 
26
  },
27
  "metadata": {},
28
  "output_type": "display_data"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
  }
30
  ],
31
  "source": [
 
47
  " with gr.Column(scale=1):\n",
48
  "\n",
49
  " # demographics\n",
50
+ " gender = gr.Radio(label='Gender', value='Unspecified',\n",
51
+ " choices=['Male', 'Female', 'Non-Binary', 'Unspecified'])\n",
52
  " age = gr.Slider(label='Age', minimum=18, maximum=80, step=1)\n",
53
+ " race = gr.Radio(label='Race', value='Unspecified',\n",
54
+ " choices=['White', 'Hispanic', 'Black', 'Asian', 'Unspecified'])\n",
55
  "\n",
56
  " # symptoms\n",
57
+ " disorders = ['Sadness', 'Inability to concentrate', 'Excessive worrying', 'Extreme mood changes',\n",
58
+ " 'Withdrawal from friends/activities', 'Tiredness', 'Hallucinations', 'Addiction',\n",
59
+ " 'Lack of appetite', 'Increased appetite']\n",
60
+ " symptoms = gr.CheckboxGroup(label='Symptoms', choices=disorders)\n",
 
 
61
  "\n",
62
  " # interests\n",
63
+ " interests = gr.Textbox(label='Interests', placeholder='Comma-separated list of interests...')\n",
 
 
 
64
  "\n",
65
  " # submit button\n",
66
  " submit_button = gr.Button('Generate Nudge')\n",
 
71
  " nudge_message = gr.Textbox(label='Nudge Message')\n",
72
  "\n",
73
  " # submit parameters for nudge generation\n",
74
+ " inputs = [gender, age, race, interests, symptoms]\n",
75
  " outputs = [nudge_image, nudge_message]\n",
76
  " submit_button.click(fn=generate, inputs=inputs, outputs=outputs)\n",
77
  "\n",
 
81
  " app.launch()\n",
82
  "\n",
83
  "\n",
84
+ "def generate(gender, age, race, interests, symptoms):\n",
85
  " \"\"\"Generate nudging image and message for the given person.\"\"\"\n",
86
+ " nudge_message = generate_nudge_message(gender, age, interests, symptoms)\n",
87
+ " nudge_image = generate_nudge_image(gender, age, race, nudge_message, random=False)\n",
88
+ " return nudge_image, nudge_message\n",
89
+ "\n",
90
+ "\n",
91
+ "def generate_nudge_message(gender, age, interests, symptoms):\n",
92
+ " \"\"\"Generate a message for a given person.\"\"\"\n",
93
  " # construct description of the person\n",
94
+ " desc = f'A {age} year old '\n",
95
+ " if gender == 'Male':\n",
96
+ " desc += 'man.'\n",
97
+ " elif gender == 'Female':\n",
98
+ " desc += 'woman.'\n",
99
+ " elif gender == 'Non-Binary':\n",
100
+ " desc += 'non-binary person.'\n",
101
  " else:\n",
102
+ " desc += 'person.'\n",
103
+ " if interests:\n",
104
+ " desc += f' They like {interests}.'\n",
 
 
 
105
  " if symptoms:\n",
106
+ " desc += f' They have the following mental health symptoms: {\", \".join(map(str.lower, symptoms))}.'\n",
107
  " else:\n",
108
  " desc += f' They do not have any mental health symptoms.'\n",
 
 
 
 
 
 
 
 
 
 
109
  " print(f'{desc=}')\n",
110
+ "\n",
111
+ " # generate nudge message\n",
112
  " system_prompt = '''You are writing motivational text messages to help people with their mental health. \\\n",
113
+ "Messages should be friendly and positive, but also professional and super short. \\\n",
114
+ "You are limited on space. \\\n",
115
+ "Messages should be written at the reading level of an eighth grader. \\\n",
116
+ "Word choice should be short and simple so everyone can understand. \\n\\n\n",
117
+ "You will be given some basic information about the person you are addressing. \\\n",
118
+ "DO NOT reference all of their likes if there are more than two. Be discerning. \\\n",
119
+ "You should try to use the person's information to give them relevant and actionable tips for improving their mental health symptoms.'''\n",
 
120
  " user_prompt = f'Write a short inspirational message for the person with the following description:\\n\\n{desc}'\n",
121
+ "\n",
122
+ " print(f'\\n\\n{system_prompt}')\n",
123
+ " print(f'\\n\\n{user_prompt}')\n",
124
+ " \n",
125
  " messages = [{'role': 'system', 'content': f'{system_prompt}'},\n",
126
  " {'role': 'user', 'content': f'{user_prompt}'}]\n",
127
  " completion = client.chat.completions.create(messages=messages, model='gpt-3.5-turbo', temperature=.5)\n",
 
129
  " return nudge_message\n",
130
  "\n",
131
  "\n",
132
+ "def generate_nudge_image(gender, age, race, nudge_message, random=False):\n",
133
  " \"\"\"Generate an image for a given person and message.\"\"\"\n",
134
  " if random:\n",
135
  " return Image.fromarray(np.random.randint(0, 255, (100, 100, 3), dtype='uint8'), 'RGB')\n",
136
  "\n",
137
+ " # construct description of the person\n",
138
+ " desc = f'The person is a {age} year old '\n",
139
+ " if race != 'Unspecified':\n",
140
+ " desc += f'{race.lower()} '\n",
141
+ " if gender == 'Male':\n",
142
+ " desc += 'man.'\n",
143
+ " elif gender == 'Female':\n",
144
+ " desc += 'woman.'\n",
145
+ " elif gender == 'Non-Binary':\n",
146
+ " desc += 'non-binary person.'\n",
147
+ " else:\n",
148
+ " desc += 'person.'\n",
149
  " prompt = 'Illustrate one simple, inspirational, fun image to help a person with their mental health. Do not include text. '\\\n",
150
+ " + f'The style is cute and illustrative. {desc} '\\\n",
 
151
  " + f'The image should align with the following message:\\n\\n{nudge_message}'\n",
152
  "\n",
153
+ " print(f'\\n{prompt}')\n",
154
+ " response = client.images.generate(prompt=prompt, model='dall-e-3')#, response_format='b64_json')\n",
155
+ " print(response)\n",
156
  " nudge_image = Image.open(requests.get(response.data[0].url, stream=True).raw)\n",
157
  "\n",
158
  " return nudge_image\n",
 
276
  "name": "python",
277
  "nbconvert_exporter": "python",
278
  "pygments_lexer": "ipython3",
279
+ "version": "3.10.12"
280
  }
281
  },
282
  "nbformat": 4,