change image generation to base64
Browse files
app.ipynb
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
"cells": [
|
3 |
{
|
4 |
"cell_type": "code",
|
5 |
-
"execution_count":
|
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:
|
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:
|
22 |
],
|
23 |
"text/plain": [
|
24 |
"<IPython.core.display.HTML object>"
|
@@ -26,12 +26,35 @@
|
|
26 |
},
|
27 |
"metadata": {},
|
28 |
"output_type": "display_data"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
}
|
30 |
],
|
31 |
"source": [
|
|
|
|
|
32 |
"import numpy as np\n",
|
33 |
"import gradio as gr\n",
|
34 |
-
"import requests\n",
|
35 |
"from PIL import Image\n",
|
36 |
"from openai import OpenAI\n",
|
37 |
"\n",
|
@@ -151,9 +174,8 @@
|
|
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'
|
155 |
-
"
|
156 |
-
" nudge_image = Image.open(requests.get(response.data[0].url, stream=True).raw)\n",
|
157 |
"\n",
|
158 |
" return nudge_image\n",
|
159 |
"\n",
|
|
|
2 |
"cells": [
|
3 |
{
|
4 |
"cell_type": "code",
|
5 |
+
"execution_count": 21,
|
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:7880\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:7880/\" 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 |
+
"name": "stdout",
|
32 |
+
"output_type": "stream",
|
33 |
+
"text": [
|
34 |
+
"desc='A 18 year old person. They have the following mental health symptoms: inability to concentrate.'\n",
|
35 |
+
"\n",
|
36 |
+
"\n",
|
37 |
+
"You are writing motivational text messages to help people with their mental health. Messages should be friendly and positive, but also professional and super short. You are limited on space. Messages should be written at the reading level of an eighth grader. Word choice should be short and simple so everyone can understand. \n",
|
38 |
+
"\n",
|
39 |
+
"\n",
|
40 |
+
"You will be given some basic information about the person you are addressing. DO NOT reference all of their likes if there are more than two. Be discerning. You should try to use the person's information to give them relevant and actionable tips for improving their mental health symptoms.\n",
|
41 |
+
"\n",
|
42 |
+
"\n",
|
43 |
+
"Write a short inspirational message for the person with the following description:\n",
|
44 |
+
"\n",
|
45 |
+
"A 18 year old person. They have the following mental health symptoms: inability to concentrate.\n",
|
46 |
+
"\n",
|
47 |
+
"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 18 year old person. The image should align with the following message:\n",
|
48 |
+
"\n",
|
49 |
+
"Hey there! Remember, you got this! To boost concentration, try breaking tasks into smaller steps. Take regular breaks and stay hydrated. Stay positive and believe in your abilities. You're capable of great things! πͺπ\n"
|
50 |
+
]
|
51 |
}
|
52 |
],
|
53 |
"source": [
|
54 |
+
"import io\n",
|
55 |
+
"import base64\n",
|
56 |
"import numpy as np\n",
|
57 |
"import gradio as gr\n",
|
|
|
58 |
"from PIL import Image\n",
|
59 |
"from openai import OpenAI\n",
|
60 |
"\n",
|
|
|
174 |
" + f'The image should align with the following message:\\n\\n{nudge_message}'\n",
|
175 |
"\n",
|
176 |
" print(f'\\n{prompt}')\n",
|
177 |
+
" response = client.images.generate(prompt=prompt, model='dall-e-3', response_format='b64_json')\n",
|
178 |
+
" nudge_image = Image.open(io.BytesIO(base64.b64decode(response.data[0].b64_json)))\n",
|
|
|
179 |
"\n",
|
180 |
" return nudge_image\n",
|
181 |
"\n",
|