├── py-notebook
├── README.md
├── .python-version
├── .idx
│ ├── icon.png
│ └── dev.nix
├── hello.py
├── .gitignore
├── pyproject.toml
└── main.ipynb
├── ace
└── eep595
│ └── project
│ └── projectproposal.pdf
├── idx-template.nix
├── idx-template.json
└── README.md
/py-notebook/README.md:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/py-notebook/.python-version:
--------------------------------------------------------------------------------
1 | 3.12
2 |
--------------------------------------------------------------------------------
/py-notebook/.idx/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/patterns/certification/main/py-notebook/.idx/icon.png
--------------------------------------------------------------------------------
/ace/eep595/project/projectproposal.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/patterns/certification/main/ace/eep595/project/projectproposal.pdf
--------------------------------------------------------------------------------
/py-notebook/hello.py:
--------------------------------------------------------------------------------
1 | def main():
2 | print("Hello from jupyter-generic!")
3 |
4 |
5 | if __name__ == "__main__":
6 | main()
7 |
--------------------------------------------------------------------------------
/py-notebook/.gitignore:
--------------------------------------------------------------------------------
1 | # Python-generated files
2 | __pycache__/
3 | *.py[oc]
4 | build/
5 | dist/
6 | wheels/
7 | *.egg-info
8 |
9 | # Virtual environments
10 | .venv
11 |
--------------------------------------------------------------------------------
/py-notebook/pyproject.toml:
--------------------------------------------------------------------------------
1 | [project]
2 | name = "jupyter-generic"
3 | version = "0.1.0"
4 | description = "Add your description here"
5 | readme = "README.md"
6 | requires-python = ">=3.12"
7 | dependencies = []
8 |
--------------------------------------------------------------------------------
/idx-template.nix:
--------------------------------------------------------------------------------
1 | { pkgs, environment ? "py-notebook", ... }: {
2 | packages = [];
3 |
4 | bootstrap = ''
5 |
6 | cp -rf ${./.}/${environment} "$WS_NAME"
7 | chmod -R +w "$WS_NAME"
8 |
9 | chmod -R +wx "$WS_NAME"
10 |
11 | mv "$WS_NAME" "$out"
12 |
13 | '';
14 | }
15 |
--------------------------------------------------------------------------------
/idx-template.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "IDX Placeholder Template",
3 | "description": "Start a Jupyter notebook",
4 | "categories": ["AI & ML"],
5 | "icon": "https://www.gstatic.com/monospace/231128/logo_gemini_512.png",
6 | "publisher": "",
7 | "params": [
8 | {
9 | "id": "environment",
10 | "name": "Environment",
11 | "type": "enum",
12 | "default": "py-notebook",
13 | "options": {
14 |
15 |
16 |
17 | "py-notebook": "Python Notebook",
18 | "go-web": "Go Web App"
19 | }
20 | }
21 | ]
22 | }
23 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # IDX template
2 |
3 |
4 |
5 |
6 |
7 |
10 |
13 |
17 |
18 |
19 |
20 | ### Credits
21 | Gemini Notebook template
22 | by [Project IDX](https://github.com/project-idx/templates/tree/main/gemini)
23 |
24 |
--------------------------------------------------------------------------------
/py-notebook/.idx/dev.nix:
--------------------------------------------------------------------------------
1 | # To learn more about how to use Nix to configure your environment
2 | # see: https://developers.google.com/idx/guides/customize-idx-env
3 | { pkgs, ... }: {
4 | # Which nixpkgs channel to use.
5 | channel = "stable-24.11"; # or "unstable"
6 | # Use https://search.nixos.org/packages to find packages
7 | packages = [
8 | pkgs.python311
9 | pkgs.python311Packages.pip
10 | pkgs.uv
11 | ];
12 | # Sets environment variables in the workspace
13 | env = {};
14 | idx = {
15 | # Search for the extensions you want on https://open-vsx.org/ and use "publisher.id"
16 | extensions = [
17 | "ms-toolsai.jupyter"
18 | "ms-python.python"
19 | ];
20 | workspace = {
21 | # Runs when a workspace is first created with this `dev.nix` file
22 | onCreate = {
23 | create-venv = ''
24 |
25 | uv add --dev ipykernel
26 |
27 | '';
28 | #### uv add pandas numpy scipy scikit-learn matplotlib
29 | # Open editors for the following files by default, if they exist:
30 | default.openFiles = [ "hello.py" "README.md" ];
31 | };
32 | # To run something each time the workspace is (re)started, use the `onStart` hook
33 | };
34 | # Enable previews and customize configuration
35 | previews = {};
36 | };
37 | }
38 |
--------------------------------------------------------------------------------
/py-notebook/main.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "attachments": {},
5 | "cell_type": "markdown",
6 | "metadata": {},
7 | "source": [
8 | "# Baking with the Gemini API\n",
9 | "\n",
10 | "To get started, [get an API key](https://g.co/ai/idxGetGeminiKey) and replace the word `TODO` below with your API key:"
11 | ]
12 | },
13 | {
14 | "cell_type": "code",
15 | "execution_count": 7,
16 | "metadata": {},
17 | "outputs": [],
18 | "source": [
19 | "API_KEY = 'TODO'"
20 | ]
21 | },
22 | {
23 | "attachments": {},
24 | "cell_type": "markdown",
25 | "metadata": {},
26 | "source": [
27 | "Once you're done, create a text prompt here:"
28 | ]
29 | },
30 | {
31 | "cell_type": "code",
32 | "execution_count": 22,
33 | "metadata": {},
34 | "outputs": [],
35 | "source": [
36 | "prompt = 'Provide an example recipe for the baked goods in the image'"
37 | ]
38 | },
39 | {
40 | "cell_type": "markdown",
41 | "metadata": {},
42 | "source": [
43 | "And load an image with PIL:"
44 | ]
45 | },
46 | {
47 | "cell_type": "code",
48 | "execution_count": null,
49 | "metadata": {},
50 | "outputs": [],
51 | "source": [
52 | "import PIL.Image\n",
53 | "img = PIL.Image.open('baked_goods_1.jpg')\n",
54 | "# img = PIL.Image.open('baked_goods_2.jpg')\n",
55 | "# img = PIL.Image.open('baked_goods_3.jpg')\n",
56 | "img"
57 | ]
58 | },
59 | {
60 | "attachments": {},
61 | "cell_type": "markdown",
62 | "metadata": {},
63 | "source": [
64 | "And finally, call the Gemini API using the Python client library. [See the docs](https://developers.generativeai.google/guide)"
65 | ]
66 | },
67 | {
68 | "cell_type": "code",
69 | "execution_count": 30,
70 | "metadata": {},
71 | "outputs": [
72 | {
73 | "data": {
74 | "text/markdown": [
75 | " Ingredients:\n",
76 | "\n",
77 | "* 2 1/4 cups all-purpose flour\n",
78 | "* 1 teaspoon baking soda\n",
79 | "* 1 teaspoon salt\n",
80 | "* 1 cup (2 sticks) unsalted butter, softened\n",
81 | "* 3/4 cup granulated sugar\n",
82 | "* 3/4 cup packed light brown sugar\n",
83 | "* 1 teaspoon vanilla extract\n",
84 | "* 2 large eggs\n",
85 | "* 1 cup semisweet chocolate chips\n",
86 | "\n",
87 | "Instructions:\n",
88 | "\n",
89 | "1. Preheat oven to 375 degrees F (190 degrees C).\n",
90 | "2. Line a baking sheet with parchment paper.\n",
91 | "3. In a medium bowl, whisk together the flour, baking soda, and salt.\n",
92 | "4. In a large bowl, cream together the butter, granulated sugar, and brown sugar until light and fluffy.\n",
93 | "5. Beat in the eggs one at a time, then stir in the vanilla.\n",
94 | "6. Gradually add the dry ingredients to the wet ingredients, mixing until just combined.\n",
95 | "7. Fold in the chocolate chips.\n",
96 | "8. Drop the dough by rounded tablespoons onto the prepared baking sheet, spacing them about 2 inches apart.\n",
97 | "9. Bake for 10-12 minutes, or until the edges are golden brown and the centers are set.\n",
98 | "10. Let cool on the baking sheet for a few minutes before transferring to a wire rack to cool completely."
99 | ],
100 | "text/plain": [
101 | ""
102 | ]
103 | },
104 | "metadata": {},
105 | "output_type": "display_data"
106 | }
107 | ],
108 | "source": [
109 | "import google.generativeai as genai\n",
110 | "from IPython.display import Markdown, clear_output, display\n",
111 | "\n",
112 | "genai.configure(api_key=API_KEY)\n",
113 | "\n",
114 | "model = genai.GenerativeModel(model_name='gemini-1.5-flash') # or gemini-1.5-pro\n",
115 | "response = model.generate_content([prompt, img], stream=True)\n",
116 | "\n",
117 | "buffer = []\n",
118 | "for chunk in response:\n",
119 | " for part in chunk.parts:\n",
120 | " buffer.append(part.text)\n",
121 | " clear_output()\n",
122 | " display(Markdown(''.join(buffer)))"
123 | ]
124 | }
125 | ],
126 | "metadata": {
127 | "kernelspec": {
128 | "display_name": "out",
129 | "language": "python",
130 | "name": "python3"
131 | },
132 | "language_info": {
133 | "codemirror_mode": {
134 | "name": "ipython",
135 | "version": 3
136 | },
137 | "file_extension": ".py",
138 | "mimetype": "text/x-python",
139 | "name": "python",
140 | "nbconvert_exporter": "python",
141 | "pygments_lexer": "ipython3",
142 | "version": "3.11.5"
143 | },
144 | "orig_nbformat": 4
145 | },
146 | "nbformat": 4,
147 | "nbformat_minor": 2
148 | }
149 |
--------------------------------------------------------------------------------