Skip to content

Commit 8a38125

Browse files
committed
live coding button
1 parent 7cfd0b1 commit 8a38125

10 files changed

Lines changed: 289 additions & 141 deletions

_config.yml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,21 @@ title: "Practical AI for Scientists - FutureHouse Tutorial"
22
author: FutureHouse
33
copyright: "2026 FutureHouse"
44

5-
# ──────────────────────────────────────────────
6-
# Execution settings
7-
# "off" means notebooks are NOT re-run during build.
8-
# This is safest for tutorials that call external APIs (like Anthropic).
9-
# Pre-run your notebooks and save the outputs before pushing.
10-
# ──────────────────────────────────────────────
115
execute:
126
execute_notebooks: "off"
137

148
launch_buttons:
159
notebook_interface: "jupyterlab"
1610
colab_url: "https://colab.research.google.com"
11+
thebe: true
12+
binderhub_url: "https://mybinder.org"
1713

1814
bibtex_bibfiles:
1915
- references.bib
2016
sphinx:
2117
extra_extensions:
2218
- sphinxcontrib.bibtex
19+
- sphinx_thebe
2320
config:
2421
numfig: false
2522
html_theme_options:

_toc.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ parts:
66
chapters:
77
- file: chapter_1/background
88
- file: chapter_1/models_in_ai
9-
- file: chapter_1/LLMs_for_biology
9+
- file: chapter_1/llms_in_biology
1010

1111
- caption: "2. Applications of AI in Biology"
1212
chapters:

binder/requirements.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
requests
2+
anthropic
3+
py3Dmol
4+
python-dotenv
5+
openai
6+
pandas
7+
matplotlib
8+
datasets
9+
trl
10+
peft
11+
nltk
12+
rank_bm25
13+
biopython
14+
fhaviary
15+
ldp
16+
pydantic
17+
mcp
18+
uvicorn
19+
ipywidgets
File renamed without changes.

chapter_2/llms_for_biology.ipynb

Lines changed: 52 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@
1414
"As the volume of scientific literature continues to grow rapidly, manually extracting and organizing this information becomes increasingly difficult and time-consuming. Therefore, automating data extraction from the literature using AI can help researchers to rapidly identify relevant findings, convert unstructured text into structured datasets, and integrate knowledge across thousands of publications. \n",
1515
"\n",
1616
":::{note}\n",
17-
"To run the code snippets, you should click the 🚀 icon at the top of the page to launch the page as an interactive Google Colab notebook.\n",
17+
"To run the code snippets, you can click the **Live Code** button OR the 🚀 icon at the top of the page to launch the page as an interactive Google Colab notebook.\n",
18+
"\n",
19+
"Clicking **Live Code** will launch a Binder environment (~1-2 min). \n",
20+
"Your code will run directly in the page once it's ready.\n",
1821
":::\n",
1922
"\n",
2023
"## 2.2.1 Getting started with LLMs\n",
@@ -27,16 +30,18 @@
2730
"\n",
2831
"These APIs are set as *secrets* because we do not want to expose these private keys to the public. \n",
2932
"\n",
30-
"**1) Set your API key for this notebook**\n",
31-
"Let's start by opening this notebook as a `Google Colab notebook`.\n",
33+
"**1) Set your API key**\n",
34+
"If you're using this notebook as a `Google Colab notebook`, follow the instruction below.\n",
3235
"\n",
3336
"- Once you have received a unique API key from OpenAI (or another provider), setup the API keys by clicking key icon on the left tab. More info [here](https://colab.research.google.com/github/google-gemini/cookbook/blob/main/quickstarts/Authentication.ipynb)\n",
3437
"\n",
3538
"- Alternatively, you can add a key to your environment. For example add a `.env` file to the root directory and add all the api keys. Or do `export OPENAI_API_KEY='your-key-here'`\n",
3639
"\n",
40+
"If you're using the **Live Coding** option, make sure to input your API when prompted.\n",
41+
"\n",
3742
"This notebook is written to work with all above cases. \n",
3843
"\n",
39-
"**2) Install the requirements to run examples in this notebook.**\n"
44+
"**2) If you're using Google Colab install the requirements by running the cell below.**\n"
4045
]
4146
},
4247
{
@@ -53,7 +58,7 @@
5358
},
5459
"outputs": [],
5560
"source": [
56-
"!pip install openai pandas matplotlib requests datasets trl peft nltk rank_bm25"
61+
"!pip install openai pandas matplotlib requests datasets trl peft nltk rank_bm25 ipywidgets"
5762
]
5863
},
5964
{
@@ -94,29 +99,57 @@
9499
"import os\n",
95100
"\n",
96101
"def get_api_key():\n",
97-
" \"\"\"Load OpenAI API key from Colab secrets or environment variable.\"\"\"\n",
102+
" \"\"\"Load API key from Colab secrets, environment variable, or user input.\"\"\"\n",
103+
" \n",
104+
" # 1. Try Colab secrets\n",
98105
" try:\n",
99106
" from google.colab import userdata\n",
100107
" return userdata.get('OPENAI_API_KEY')\n",
101108
" except ImportError:\n",
102-
" # Not in Colab — fall back to environment variable\n",
109+
" pass\n",
110+
"\n",
111+
" # 2. Try environment variable / .env file\n",
112+
" try:\n",
103113
" from dotenv import load_dotenv\n",
104114
" load_dotenv()\n",
105115
" api_key = os.environ.get('OPENAI_API_KEY')\n",
106-
" if not api_key:\n",
107-
" raise ValueError(\n",
108-
" \"API key not found. Please set the OPENAI_API_KEY environment variable.\\n\"\n",
109-
" \"You can do this by running the following in your terminal:\\n\"\n",
110-
" \" export OPENAI_API_KEY='your-key-here'\\n\"\n",
111-
" \"Or add it to a .env file in your project root.\"\n",
112-
" )\n",
113-
" return api_key\n",
116+
" if api_key:\n",
117+
" return api_key\n",
118+
" except ImportError:\n",
119+
" pass\n",
114120
"\n",
115-
"# Access the OpenAI API key\n",
116-
"openai_api_key = get_api_key()\n",
121+
" # 3. For live code in Binder/Thebe — ask user to input it\n",
122+
" try:\n",
123+
" import ipywidgets as widgets\n",
124+
" from IPython.display import display\n",
125+
"\n",
126+
" key_input = widgets.Password(\n",
127+
" placeholder='Paste your OpenAI API key here',\n",
128+
" description='API Key:',\n",
129+
" layout=widgets.Layout(width='400px')\n",
130+
" )\n",
131+
" submit = widgets.Button(description='Submit', button_style='primary')\n",
132+
" output = widgets.Output()\n",
133+
"\n",
134+
" result = {'key': None}\n",
135+
"\n",
136+
" def on_submit(b):\n",
137+
" result['key'] = key_input.value\n",
138+
" os.environ['OPENAI_API_KEY'] = key_input.value\n",
139+
" with output:\n",
140+
" print(\"✅ API key set successfully!\")\n",
117141
"\n",
118-
"# Print the API key\n",
119-
"print(f\"Your OpenAI API Key: {openai_api_key}\")"
142+
" submit.on_click(on_submit)\n",
143+
" display(widgets.VBox([key_input, submit, output]))\n",
144+
"\n",
145+
" # wait for user to submit\n",
146+
" return result\n",
147+
"\n",
148+
" except ImportError:\n",
149+
" raise ValueError(\n",
150+
" \"API key not found. Please set OPENAI_API_KEY:\\n\"\n",
151+
" \" export OPENAI_API_KEY='your-key-here'\"\n",
152+
" )"
120153
]
121154
},
122155
{

chapter_2/uniprot_example.ipynb

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@
99
"The goal of this section is to show you how LLMs can easily be integrated into research workflows to accelerate scientific discovery. On top of everything, AI can take care of the most mundane trivial tasks.\n",
1010
"\n",
1111
":::{note}\n",
12-
"To run the code snippets, you should click the 🚀 icon at the top of the page to launch the page as an interactive Google Colab notebook.\n",
12+
"To run the code snippets, you can click the **Live Code** button OR the 🚀 icon at the top of the page to launch the page as an interactive Google Colab notebook.\n",
13+
"\n",
14+
"Clicking **Live Code** will launch a Binder environment (~1-2 min). \n",
15+
"Your code will run directly in the page once it's ready.\n",
1316
":::\n",
1417
"\n",
1518
"## 2.3.1 Example 1: Uniprot integration\n",
@@ -20,7 +23,13 @@
2023
"\n",
2124
"### Step 1: Query the UniProt REST API\n",
2225
"\n",
23-
"UniProt offers a free, no-authentication REST API. You can fetch data for p53 (human) using its UniProt accession ID `P04637`:"
26+
"UniProt offers a free, no-authentication REST API. You can fetch data for p53 (human) using its UniProt accession ID `P04637`.\n",
27+
"\n",
28+
"\n",
29+
"Let's begin!\n",
30+
"\n",
31+
"If you're using Google Colab to run the notebook, make sure to install the requirements using the cell below. If you're using the \"Live Code\" option, you don't have to do anything.\n",
32+
"\n"
2433
]
2534
},
2635
{

chapter_3/agent_implementation.ipynb

Lines changed: 73 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,15 @@
1919
"- `analyze_protein_sequence` — computes basic biophysical properties\n",
2020
"- `summarize_protein_role` — asks the AI to summarize biological context\n",
2121
"\n",
22-
"Let's start with installing dependencies and loading API keys below. As we're using the Anthropic native tool use in this example, make sure you have an Anthropic API key."
22+
"\n",
23+
":::{note}\n",
24+
"To run the code snippets, you can click the **Live Code** button OR the 🚀 icon at the top of the page to launch the page as an interactive Google Colab notebook.\n",
25+
"\n",
26+
"Clicking **Live Code** will launch a Binder environment (~1-2 min). \n",
27+
"Your code will run directly in the page once it's ready.\n",
28+
":::\n",
29+
"\n",
30+
"If you're using Google Colab to run the notebook, make sure to install the requirements using the cell below. If you're using the \"Live Code\" option, you don't have to do anything."
2331
]
2432
},
2533
{
@@ -29,7 +37,19 @@
2937
"metadata": {},
3038
"outputs": [],
3139
"source": [
32-
"!uv pip install anthropic biopython"
40+
"!pip install anthropic biopython"
41+
]
42+
},
43+
{
44+
"cell_type": "markdown",
45+
"id": "9199abee",
46+
"metadata": {},
47+
"source": [
48+
"Next, you have to setup an Anthropic API key. Your options are as follows:\n",
49+
"\n",
50+
"- If you're using the **Live Coding** option, you can input the API key when prompted. No need to add any environment variables.\n",
51+
"\n",
52+
"- If you're using **Google Colab** you can either set up the API key as a *colab secret* or in the `.env` file."
3353
]
3454
},
3555
{
@@ -40,25 +60,59 @@
4060
"outputs": [],
4161
"source": [
4262
"import os\n",
43-
"from dotenv import load_dotenv\n",
4463
"\n",
45-
"def get_api_key(provider: str = \"anthropic\"):\n",
46-
" \"\"\"Load Anthropic API key from Colab secrets or environment variable.\"\"\"\n",
64+
"def get_api_key():\n",
65+
" \"\"\"Load API key from Colab secrets, environment variable, or user input.\"\"\"\n",
66+
" \n",
67+
" # 1. Try Colab secrets\n",
4768
" try:\n",
4869
" from google.colab import userdata\n",
49-
" return userdata.get(\"ANTHROPIC_API_KEY\")\n",
70+
" return userdata.get('ANTHROPIC_API_KEY')\n",
5071
" except ImportError:\n",
51-
" # Not in Colab — fall back to environment variable\n",
52-
" load_dotenv() \n",
53-
" api_key = os.environ.get(\"ANTHROPIC_API_KEY\")\n",
54-
" if not api_key:\n",
55-
" raise ValueError(\n",
56-
" \"API key not found. Please set the ANTHROPIC_API_KEY environment variable.\\n\"\n",
57-
" \"You can do this by running the following in your terminal. Example:\\n\"\n",
58-
" \" export ANTHROPIC_API_KEY='your-key-here'\\n\"\n",
59-
" \"Or add it to a .env file in your project root.\"\n",
60-
" )\n",
61-
" return api_key\n"
72+
" pass\n",
73+
"\n",
74+
" # 2. Try environment variable / .env file\n",
75+
" try:\n",
76+
" from dotenv import load_dotenv\n",
77+
" load_dotenv()\n",
78+
" api_key = os.environ.get('ANTHROPIC_API_KEY')\n",
79+
" if api_key:\n",
80+
" return api_key\n",
81+
" except ImportError:\n",
82+
" pass\n",
83+
"\n",
84+
" # 3. Try Binder/Thebe — ask user to input it\n",
85+
" try:\n",
86+
" import ipywidgets as widgets\n",
87+
" from IPython.display import display\n",
88+
"\n",
89+
" key_input = widgets.Password(\n",
90+
" placeholder='Paste your Anthropic API key here',\n",
91+
" description='API Key:',\n",
92+
" layout=widgets.Layout(width='400px')\n",
93+
" )\n",
94+
" submit = widgets.Button(description='Submit', button_style='primary')\n",
95+
" output = widgets.Output()\n",
96+
"\n",
97+
" result = {'key': None}\n",
98+
"\n",
99+
" def on_submit(b):\n",
100+
" result['key'] = key_input.value\n",
101+
" os.environ['ANTHROPIC_API_KEY'] = key_input.value\n",
102+
" with output:\n",
103+
" print(\"✅ API key set successfully!\")\n",
104+
"\n",
105+
" submit.on_click(on_submit)\n",
106+
" display(widgets.VBox([key_input, submit, output]))\n",
107+
"\n",
108+
" # wait for user to submit\n",
109+
" return result # caller checks result['key']\n",
110+
"\n",
111+
" except ImportError:\n",
112+
" raise ValueError(\n",
113+
" \"API key not found. Please set ANTHROPIC_API_KEY:\\n\"\n",
114+
" \" export ANTHROPIC_API_KEY='your-key-here'\"\n",
115+
" )"
62116
]
63117
},
64118
{
@@ -84,7 +138,8 @@
84138
"from Bio.SeqUtils.ProtParam import ProteinAnalysis \n",
85139
"\n",
86140
"# Connect to the Claude AI model.\n",
87-
"# Make sure you have set your API key as an environment variable\n",
141+
"# Make sure you have set your API key as an environment variable.\n",
142+
"# Or set up the API key when prompted.\n",
88143
"client = anthropic.Anthropic(api_key=get_api_key())\n",
89144
"\n",
90145
"print(\"Libraries loaded and client ready.\")"

0 commit comments

Comments
 (0)