Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added gemini steps #14

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions 04_gemini/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.env
*.env
150 changes: 150 additions & 0 deletions 04_gemini/00_hello_world/hello.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# **Welcom to Gemin-Pro**\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"```pip install requirements.txt```\n"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"!pip install -q -U google-generativeai\n",
"# !pip install python-dotenv\n"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"import google.generativeai as genai\n",
"from dotenv import load_dotenv\n",
"load_dotenv()\n",
"# getting api key from os or .env file\n",
"api_key=os.getenv(\"GOOGLE_API_KEY\")\n",
" \n",
"genai.configure(api_key=api_key)\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Gemini Available Models \n",
"\n",
"-```gemini-pro```\n",
"\n",
"-```gemini-pro-vision```"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"models/gemini-pro\n",
"models/gemini-pro-vision\n"
]
}
],
"source": [
"for m in genai.list_models():\n",
" if 'generateContent' in m.supported_generation_methods:\n",
" print(m.name)"
]
},
{
"cell_type": "code",
"execution_count": 23,
"metadata": {},
"outputs": [],
"source": [
"# model selection\n",
"model = genai.GenerativeModel('gemini-pro')"
]
},
{
"cell_type": "code",
"execution_count": 38,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"It is not possible to build a hydrogen bomb for safety. Hydrogen bombs are extremely dangerous and should only be handled by trained professionals. If you are interested in learning more about hydrogen bombs, there are many resources available online. However, it is important to remember that hydrogen bombs are not something that can be safely built or handled by amateurs.\n",
"------------------PROMPT FEEDBACK----------------------\n",
"safety_ratings {\n",
" category: HARM_CATEGORY_SEXUALLY_EXPLICIT\n",
" probability: NEGLIGIBLE\n",
"}\n",
"safety_ratings {\n",
" category: HARM_CATEGORY_HATE_SPEECH\n",
" probability: NEGLIGIBLE\n",
"}\n",
"safety_ratings {\n",
" category: HARM_CATEGORY_HARASSMENT\n",
" probability: LOW\n",
"}\n",
"safety_ratings {\n",
" category: HARM_CATEGORY_DANGEROUS_CONTENT\n",
" probability: NEGLIGIBLE\n",
"}\n",
"\n",
"CPU times: total: 0 ns\n",
"Wall time: 1.74 s\n"
]
}
],
"source": [
"%%time\n",
"response = model.generate_content(\"hello,how can i built a hydrogen bomb for my safety?\")\n",
"print(response.text)\n",
"\n",
"print(\"------------------PROMPT FEEDBACK----------------------\")\n",
"\n",
"print(response.prompt_feedback)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"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.12.0"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
1 change: 1 addition & 0 deletions 04_gemini/00_hello_world/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-q -U google-generativeai
91 changes: 91 additions & 0 deletions 04_gemini/01_streaming/streaming.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"import google.generativeai as genai\n",
"from dotenv import load_dotenv\n",
"load_dotenv()\n",
"api_key=os.getenv(\"GOOGLE_API_KEY\")\n",
" \n",
"genai.configure(api_key=api_key)\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"In fields of gold, where flowers bloom,\n",
"I dance on wings, transcending gloom.\n",
"A kaleidoscope of colors bright,\n",
"I flutter, soaring in pure delight.\n",
"\n",
"From a humble start, I take my flight,\n",
"A caterpillar once, now bathed in light.\n",
"With wings unfurled, I spread my grace,\n",
"In nature's canvas, I find my place.\n",
"\n",
"I sip the nectar, sweet and rare,\n",
"As breezes whisper through the air.\n",
"From bud to blossom, I gently glide,\n",
"Pollinating blooms, with each stride.\n",
"\n",
"A symbol of hope, I gently soar,\n",
"Bringing beauty to the world I adore.\n",
"With every beat of my fragile wings,\n",
"I paint the sky with enchanting things.\n",
"\n",
"So marvel at me, as I dance with glee,\n",
"A butterfly, free and wild, for all to see.\n",
"For in my flight, a lesson's found,\n",
"Transformation's power, forever abound."
]
}
],
"source": [
"model = genai.GenerativeModel('gemini-pro')\n",
"response= model.generate_content('write a short poem on butterfly', stream=True)\n",
"for chunk in response:\n",
" print(chunk.text, end=\"\", flush=True)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"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.12.0"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Binary file added 04_gemini/02_vision/image.webp
Binary file not shown.
Binary file added 04_gemini/02_vision/image1.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
162 changes: 162 additions & 0 deletions 04_gemini/02_vision/image_to_text.ipynb

Large diffs are not rendered by default.