Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions AWS/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,20 @@ Make sure that after you are done with the module, close the tab that appeared w
- If you are unable to interact with your s3 bucket using the `aws s3` command, check your `nextflow-service-account` roles. Make sure that you have `Storage Admin` added.
- If you are trying to execute a terminal command in a Jupyter code cell and it is not working, make sure that you have an `!` before the command.
- e.g., `mkdir example-1` -> `!mkdir example-1`

## AWS Bedrock (Optional)

Generative AI is available for this tutorial if you would like to use it. To run it, please reference Submodule 1, or run the following code within a submodule notebook.

```!pip install -q ipywidgets
import sys
import os
util_path = os.path.join(os.getcwd(), 'util')
if util_path not in sys.path:
sys.path.append(util_path)

# Import the display_widgets function from your Python file
from genai import display_widgets

# Call the function to display the widgets
display_widgets()
58 changes: 56 additions & 2 deletions AWS/Submodule_1_background.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,12 @@
"\n",
"6. **Introduce the AWS Batch API:** Learners are introduced to the AWS Batch API and its advantages for managing and executing workflows on cloud computing resources.\n",
"\n",
"7. **Familiarize learners with Jupyter Notebooks:** The notebook provides instructions on how to navigate and use Jupyter Notebooks, including cell types and execution order."
"7. **Familiarize learners with Jupyter Notebooks:** The notebook provides instructions on how to navigate and use Jupyter Notebooks, including cell types and execution order.\n",
"\n",
"<div class=\"alert alert-block alert-success\">\n",
" <i class=\"fa fa-hand-paper-o\" aria-hidden=\"true\"></i>\n",
" <b>Tip: </b> If you're having trouble with any part of this tutorial, feel free to leverage AWS Bedrock (Amazon's advanced generative AI tool) at the bottom of this module.\n",
"</div> "
]
},
{
Expand Down Expand Up @@ -508,11 +513,60 @@
"\n",
"Remember to proceed to the next notebook [`Submodule_2_annotation_only.ipynb`](./Submodule_2_annotation_only.ipynb) or shut down your instance if you are finished."
]
},
{
"cell_type": "markdown",
"id": "fc886b9b-518c-446d-a703-363b98e72db7",
"metadata": {},
"source": [
"## Bedrock (Optional)\n",
"--------\n",
"\n",
"If you're having trouble with this submodule (or others within this tutorial), feel free to leverage Bedrock by running the cell below. Bedrock is a fully managed service that simplifies building and scaling generative AI applications. It provides access to various foundation models (FMs) from Amazon and other AI companies.\n",
"\n",
"Before being able to use the chatbot you must request **Llama 3 8B Instruct** model access through AWS Bedrock. In order to do this follow the instructions to request model access provided in [AWS Bedrock Intro Notebook](https://github.com/STRIDES/NIHCloudLabAWS/blob/main/notebooks/GenAI/AWS_Bedrock_Intro.ipynb). After requesting the Llama 3 8B Instruct access it should only take a minute to get approved. While waiting for model approval, attach the **AmazonBedrockFullAccess** permission to your notebook service role. Once approved run the following code cell to use the model within the notebook. "
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "2d9781c2-85b1-40de-a1f0-9cacaf5a7ff7",
"metadata": {},
"outputs": [],
"source": [
"# Ensure you have the necessary libraries installed\n",
"!pip install -q ipywidgets\n",
"import sys\n",
"import os\n",
"util_path = os.path.join(os.getcwd(), 'util')\n",
"if util_path not in sys.path:\n",
" sys.path.append(util_path)\n",
"\n",
"# Import the display_widgets function from your Python file\n",
"from genai import display_widgets\n",
"\n",
"# Call the function to display the widgets\n",
"display_widgets()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "conda_python3",
"language": "python",
"name": "conda_python3"
},
"language_info": {
"name": "python"
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.17"
}
},
"nbformat": 4,
Expand Down
56 changes: 56 additions & 0 deletions AWS/util/genai.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import boto3
import json
import ipywidgets as widgets
from IPython.display import display

# Setup Model
my_session = boto3.session.Session()
my_region = my_session.region_name
bedrock = boto3.client(
service_name='bedrock-runtime',
region_name=my_region,
)
def genai(prompt):
# Define model ID
model_id = "meta.llama3-8b-instruct-v1:0"

# Create request body
body = json.dumps({
"prompt": prompt,
})

# Send request to Bedrock
response = bedrock.invoke_model(
modelId=model_id,
body=body
)

# Process the response
response_body = json.loads(response['body'].read())
generated_text = response_body['generation']
generated_text = generated_text.lstrip('?').strip()
return generated_text

# Create widgets
prompt_input = widgets.Text(description="Prompt:")
submit_button = widgets.Button(description="Submit")
output_area = widgets.Output()

# Define button click event
def on_button_click(b):
with output_area:
output_area.clear_output()
print("Generating response...")
response = genai(prompt_input.value)
print("Response:")
print(response)

# Attach the event to the button
submit_button.on_click(on_button_click)

def display_widgets():
"""
Function to display the widgets in the notebook.
Call this function to show the interactive prompt interface.
"""
display(prompt_input, submit_button, output_area)
Loading