Spaces:
Sleeping
Sleeping
File size: 6,897 Bytes
37c00da |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
{
"cells": [
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"# A scratch pad notebook for testing out ideas"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"# import libraries\n",
"import os\n",
"import pandas as pd\n",
"import numpy as np"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"['Apricot', 'Apple', 'Asparagus', 'Basil', 'Beans', 'Broad Beans', 'Bush Beans', 'Climbing Beans', 'Beets', 'Borage', 'Broccoli', 'Brussel Sprouts', 'Cabbages', 'Chamomile', 'Carrots', 'Cauliflower', 'Celery', 'Cherry', 'Chervil', 'Chives', 'Coriander', 'Corn', 'Cucumber', 'Dill', 'Eggplant', 'Fennel', 'Marigold', 'Fruit Trees', 'Garlic', 'Gooseberry', 'Grape Vine', 'Grass', 'Horseradish', 'Lavendar', 'Leeks', 'Lemon Balm', 'Lettuce', 'Marjoram', 'Mints', 'Mulberry', 'Mustard', 'Nasturtiums', 'Onions', 'Parsley', 'Parsnip', 'Peas', 'Pennyroyal', 'Potato', 'Pumpkin', 'Radish', 'Raspberry', 'Rosemary', 'Roses', 'Rue', 'Sage', 'Savory', 'Shallots', 'Silverbeet', 'Spinach', 'Squash', 'Strawberries', 'Stinging Nettle', 'Sunflower', 'Tansy', 'Thyme', 'Tomato', 'Yarrow', 'Zucchini']\n"
]
}
],
"source": [
"# make plant_compatibility.csv into a matrix. it currently has indexes as rows and columns for plant names and then compatibility values as the values\n",
"plant_compatibility = pd.read_csv('../data/plant_compatibility.csv', index_col=0)\n",
"\n",
"# fill NaN values with 0\n",
"plant_compatibility = plant_compatibility.fillna(0)\n",
"\n",
"# get list of plants\n",
"plant_list = plant_compatibility.index.tolist()\n",
"print(plant_list)"
]
},
{
"cell_type": "code",
"execution_count": 32,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"https://oaidalleapiprodscus.blob.core.windows.net/private/org-5YS2GMCG8RfgP4OEokQn3hGg/user-6uCRR8MZKqJD3U6peXi7IE82/img-17pR4xJgtkBs5Gx5Kx48xElA.png?st=2023-12-17T18%3A20%3A53Z&se=2023-12-17T20%3A20%3A53Z&sp=r&sv=2021-08-06&sr=b&rscd=inline&rsct=image/png&skoid=6aaadede-4fb3-4698-a8f6-684d7786b067&sktid=a48cca56-e6da-484e-a814-9c849652bcb3&skt=2023-12-16T19%3A51%3A17Z&ske=2023-12-17T19%3A51%3A17Z&sks=b&skv=2021-08-06&sig=6TrxNFh%2BsgPEMxqnNRc6qYagOGmEWbISLKW3wMKFosw%3D\n",
"https://oaidalleapiprodscus.blob.core.windows.net/private/org-5YS2GMCG8RfgP4OEokQn3hGg/user-6uCRR8MZKqJD3U6peXi7IE82/img-vqmQfv9IUlKzR08WzaniBpzs.png?st=2023-12-17T18%3A21%3A04Z&se=2023-12-17T20%3A21%3A04Z&sp=r&sv=2021-08-06&sr=b&rscd=inline&rsct=image/png&skoid=6aaadede-4fb3-4698-a8f6-684d7786b067&sktid=a48cca56-e6da-484e-a814-9c849652bcb3&skt=2023-12-17T19%3A11%3A33Z&ske=2023-12-18T19%3A11%3A33Z&sks=b&skv=2021-08-06&sig=dqymS6fNQkfntMPb31owYanMCfHwRcTnHMC7qc1OISI%3D\n"
]
}
],
"source": [
"\n",
"import openai\n",
"import requests\n",
"\n",
"# setup keys and api info\n",
"file_path = '/Users/dheym/Library/CloudStorage/OneDrive-Personal/Documents/side_projects/api_keys/openai_api_keys.txt'\n",
"with open(file_path, 'r') as file:\n",
" OPENAI_API_KEY = file.read()\n",
"\n",
"os.environ[\"OPENAI_API_KEY\"] = OPENAI_API_KEY\n",
"\n",
"# setup openai\n",
"openai.api_key = os.getenv(\"OPENAI_API_KEY\")\n",
"\n",
"from openai import OpenAI\n",
"client = OpenAI()\n",
"\n",
"\n",
"\n",
"# call Dalle3 to generate images for each plant and save them in the assets folder. use the filename plant_x.png where x is the index of the plant in the plant_list.\n",
"#for i in range(45,len(plant_list)):\n",
"# edit 46, 48, 49, 51, 52, 53, 54, 55, 63 \n",
"for i in [46, 52]:\n",
"# 46, 48, 49, 51, 52, 53, 54, 55, 63 \n",
" plant_name = plant_list[i]\n",
" response = client.images.generate(\n",
" model=\"dall-e-3\",\n",
" prompt=\"a high quality color pixel image (think videogame) of \" + plant_name + \" (as in produce or the plant) with a solid black background. no other objects in the image.\",\n",
" size=\"1024x1024\",\n",
" quality=\"standard\",\n",
" n=1,\n",
" )\n",
"\n",
" # Get the image URL from the response\n",
" image_url = response.data[0].url\n",
" print(image_url)\n",
" \n",
" # Download the image\n",
" img_data = requests.get(image_url).content\n",
"\n",
" # Save the image in the assets folder with the specified filename\n",
" with open(f'../assets/plant_images/plant_{i}.png', 'wb') as handler:\n",
" handler.write(img_data)\n"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Index(['Apricot', 'Apple', 'Asparagus', 'Basil', 'Beans', 'Broad Beans',\n",
" 'Bush Beans', 'Climbing Beans', 'Beets', 'Borage', 'Broccoli',\n",
" 'Brussel Sprouts', 'Cabbages', 'Chamomile', 'Carrots', 'Cauliflower',\n",
" 'Celery', 'Cherry', 'Chervil', 'Chives', 'Coriander', 'Corn',\n",
" 'Cucumber', 'Dill', 'Eggplant', 'Fennel', 'Marigold', 'Fruit Trees',\n",
" 'Garlic', 'Gooseberry', 'Grape Vine', 'Grass', 'Horseradish',\n",
" 'Lavendar', 'Leeks', 'Lemon Balm', 'Lettuce', 'Marjoram', 'Mints',\n",
" 'Mulberry', 'Mustard', 'Nasturtiums', 'Onions', 'Parsley', 'Parsnip',\n",
" 'Peas', 'Pennyroyal', 'Potato', 'Pumpkin', 'Radish', 'Raspberry',\n",
" 'Rosemary', 'Roses', 'Rue', 'Sage', 'Savory', 'Shallots', 'Silverbeet',\n",
" 'Spinach', 'Squash', 'Strawberries', 'Stinging Nettle', 'Sunflower',\n",
" 'Tansy', 'Thyme', 'Tomato', 'Yarrow', 'Zucchini'],\n",
" dtype='object')"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"\n",
"\n",
"\n",
"plant_compatibility.columns.tolist()\n",
"# call Dalle3 to generate images for each plant and save them in the assets folder. use the filename plant_x.png where x is the index of the plant in the plant_list.\n",
"# for i in range(len(plant_list)):\n",
"\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "GRDN_env",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.3"
},
"orig_nbformat": 4
},
"nbformat": 4,
"nbformat_minor": 2
}
|