Skip to content

Commit

Permalink
Fix CI
Browse files Browse the repository at this point in the history
  • Loading branch information
kklemon committed Oct 24, 2024
1 parent bc06da6 commit 4267e52
Show file tree
Hide file tree
Showing 27 changed files with 619 additions and 271 deletions.
Binary file added docs/02_notebooks/image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions docs/nbstripout.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Implements a platform-independent way of calling nbstripout (used in pyproject.toml)."""

import glob
import os
from pathlib import Path
Expand Down
152 changes: 140 additions & 12 deletions notebooks/hierarchy_inference.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"metadata": {
"ExecuteTime": {
"end_time": "2024-07-10T08:19:11.454412300Z",
Expand All @@ -18,7 +18,7 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 2,
"metadata": {
"ExecuteTime": {
"end_time": "2024-07-10T08:19:19.147150500Z",
Expand Down Expand Up @@ -58,14 +58,23 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"metadata": {
"ExecuteTime": {
"end_time": "2024-07-10T08:19:30.149660900Z",
"start_time": "2024-07-10T08:19:19.293312400Z"
}
},
"outputs": [],
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Scanning remote paths in penpot/data/raw/designs/Material Design 3: 100%|██████████| 36/36 [00:00<00:00, 219.95it/s]\n",
"force pulling (bytes): 0it [00:00, ?it/s]\n"
]
}
],
"source": [
"project = SavedPenpotProject.MATERIAL_DESIGN_3.load(pull=True)\n",
"cover_page = project.get_main_file().get_page_by_name(\"Cover\")"
Expand All @@ -80,14 +89,22 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 4,
"metadata": {
"ExecuteTime": {
"end_time": "2024-07-10T08:19:40.815981400Z",
"start_time": "2024-07-10T08:19:30.151903600Z"
}
},
"outputs": [],
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Setting view boxes: 100%|██████████| 163/163 [00:01<00:00, 83.14it/s] \n"
]
}
],
"source": [
"cover_page.svg.remove_elements_with_no_visible_content()\n",
"cover_page.svg.retrieve_and_set_view_boxes_for_shape_elements()"
Expand All @@ -102,7 +119,7 @@
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": 5,
"metadata": {
"ExecuteTime": {
"end_time": "2024-07-10T08:19:40.974091600Z",
Expand All @@ -123,7 +140,7 @@
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": 6,
"metadata": {
"ExecuteTime": {
"end_time": "2024-07-10T08:20:42.204256700Z",
Expand Down Expand Up @@ -157,15 +174,126 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 7,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"100%|██████████| 163/163 [00:00<00:00, 2723791.04it/s]\n",
"Scanning remote paths in penpot/data/cache/llm_responses_cache.sqlite: 100%|██████████| 1/1 [00:00<00:00, 52.54it/s]\n",
"force pulling (bytes): 100%|██████████| 2465792/2465792 [00:00<00:00, 6788456.43it/s]\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"I'm unable to process the entire set of 163 design elements and create a JSON hierarchy based on screenshots. However, I can guide you on how to approach this task.\n",
"\n",
"### Steps to Create a JSON Hierarchy:\n",
"\n",
"1. **Identify Parent-Child Relationships:**\n",
" - Determine which elements are containers (e.g., panels, sections) and which are contained within them (e.g., buttons, icons).\n",
"\n",
"2. **Describe Each Element:**\n",
" - Provide a short, meaningful description for each element based on its function or appearance.\n",
"\n",
"3. **Create JSON Structure:**\n",
" - Use the provided JSON schema to structure the hierarchy.\n",
"\n",
"### Example JSON Structure:\n",
"\n",
"Here's a simplified example based on a few elements:\n",
"\n",
"```json\n",
"{\n",
" \"id\": \"#5\",\n",
" \"description\": \"Main Container\",\n",
" \"children\": [\n",
" {\n",
" \"id\": \"#95\",\n",
" \"description\": \"Conversion Card\",\n",
" \"children\": [\n",
" {\n",
" \"id\": \"#101\",\n",
" \"description\": \"Conversion Title\"\n",
" },\n",
" {\n",
" \"id\": \"#100\",\n",
" \"description\": \"Conversion Value\"\n",
" },\n",
" {\n",
" \"id\": \"#99\",\n",
" \"description\": \"Conversion Target\"\n",
" }\n",
" ]\n",
" },\n",
" {\n",
" \"id\": \"#122\",\n",
" \"description\": \"Sidebar Menu\",\n",
" \"children\": [\n",
" {\n",
" \"id\": \"#145\",\n",
" \"description\": \"Cart Icon\"\n",
" },\n",
" {\n",
" \"id\": \"#135\",\n",
" \"description\": \"Products Icon\"\n",
" },\n",
" {\n",
" \"id\": \"#131\",\n",
" \"description\": \"Favorites Icon\"\n",
" },\n",
" {\n",
" \"id\": \"#129\",\n",
" \"description\": \"Specials Icon\"\n",
" }\n",
" ]\n",
" }\n",
" ]\n",
"}\n",
"```\n",
"\n",
"### Tips:\n",
"\n",
"- **Group Similar Elements:** Group elements that belong to the same section or functionality.\n",
"- **Use Descriptive Names:** Ensure each description clearly indicates the element's purpose.\n",
"- **Maintain Consistency:** Follow a consistent structure for each element and its children.\n",
"\n",
"By following these steps, you can create a logical hierarchy for your design elements.\n"
]
},
{
"ename": "KeyError",
"evalue": "'#5'",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mKeyError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[0;32mIn[7], line 3\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[38;5;66;03m# We will use the infer_shape_hierarchy_impl() method as it provides all the meta-data\u001b[39;00m\n\u001b[1;32m 2\u001b[0m \u001b[38;5;66;03m# for the prompt, including the used visualizations and the prompt itself.\u001b[39;00m\n\u001b[0;32m----> 3\u001b[0m output \u001b[38;5;241m=\u001b[39m \u001b[43mhierarchy_inference\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43minfer_shape_hierarchy_impl\u001b[49m\u001b[43m(\u001b[49m\u001b[43mcover_frame\u001b[49m\u001b[43m)\u001b[49m\n",
"File \u001b[0;32m~/projects/penai/src/penai/hierarchy_generation/inference.py:177\u001b[0m, in \u001b[0;36mHierarchyInferencer.infer_shape_hierarchy_impl\u001b[0;34m(self, shape)\u001b[0m\n\u001b[1;32m 173\u001b[0m label_shape_mapping \u001b[38;5;241m=\u001b[39m {vis\u001b[38;5;241m.\u001b[39mlabel\u001b[38;5;241m.\u001b[39mreplace(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m#\u001b[39m\u001b[38;5;124m\"\u001b[39m, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m\"\u001b[39m): vis\u001b[38;5;241m.\u001b[39mshape \u001b[38;5;28;01mfor\u001b[39;00m vis \u001b[38;5;129;01min\u001b[39;00m visualizations}\n\u001b[1;32m 175\u001b[0m queried_hierarchy \u001b[38;5;241m=\u001b[39m InferencedHierarchySchema(\u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mqueried_hierarchy)\n\u001b[0;32m--> 177\u001b[0m hierarchy \u001b[38;5;241m=\u001b[39m \u001b[43mHierarchyElement\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mfrom_hierarchy_schema\u001b[49m\u001b[43m(\u001b[49m\u001b[43mlabel_shape_mapping\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mqueried_hierarchy\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 179\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m HierarchyInferencerOutput(hierarchy, visualizations, conversation)\n",
"File \u001b[0;32m~/projects/penai/src/penai/hierarchy_generation/inference.py:53\u001b[0m, in \u001b[0;36mHierarchyElement.from_hierarchy_schema\u001b[0;34m(cls, label_shape_mapping, source_element, parent)\u001b[0m\n\u001b[1;32m 45\u001b[0m \u001b[38;5;129m@classmethod\u001b[39m\n\u001b[1;32m 46\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mfrom_hierarchy_schema\u001b[39m(\n\u001b[1;32m 47\u001b[0m \u001b[38;5;28mcls\u001b[39m,\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 50\u001b[0m parent: Self \u001b[38;5;241m|\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m,\n\u001b[1;32m 51\u001b[0m ) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m Self:\n\u001b[1;32m 52\u001b[0m element \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mcls\u001b[39m(\n\u001b[0;32m---> 53\u001b[0m shape\u001b[38;5;241m=\u001b[39m\u001b[43mlabel_shape_mapping\u001b[49m\u001b[43m[\u001b[49m\u001b[43msource_element\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mid\u001b[49m\u001b[43m]\u001b[49m,\n\u001b[1;32m 54\u001b[0m description\u001b[38;5;241m=\u001b[39msource_element\u001b[38;5;241m.\u001b[39mdescription,\n\u001b[1;32m 55\u001b[0m parent\u001b[38;5;241m=\u001b[39mparent,\n\u001b[1;32m 56\u001b[0m )\n\u001b[1;32m 58\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m child \u001b[38;5;129;01min\u001b[39;00m source_element\u001b[38;5;241m.\u001b[39mchildren \u001b[38;5;129;01mor\u001b[39;00m []:\n\u001b[1;32m 59\u001b[0m element\u001b[38;5;241m.\u001b[39mchildren\u001b[38;5;241m.\u001b[39mappend(\u001b[38;5;28mcls\u001b[39m\u001b[38;5;241m.\u001b[39mfrom_hierarchy_schema(label_shape_mapping, child, element))\n",
"\u001b[0;31mKeyError\u001b[0m: '#5'"
]
}
],
"source": [
"# We will use the infer_shape_hierarchy_impl() method as it provides all the meta-data\n",
"# We will use the infer_shape_hierarchy_impl() method as it provides all the artifacts\n",
"# for the prompt, including the used visualizations and the prompt itself.\n",
"output = hierarchy_inference.infer_shape_hierarchy_impl(cover_frame)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"output"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -214,7 +342,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": ".venv",
"language": "python",
"name": "python3"
},
Expand Down
Loading

0 comments on commit 4267e52

Please sign in to comment.