Browse Source

gemini-codes-week2

pull/69/head
Gore Shardul 4 months ago
parent
commit
fbb5569ba1
  1. 27
      week2/community-contributions/Gemini-api.ipynb
  2. 118
      week2/community-contributions/day2-gemini.ipynb
  3. 172
      week2/community-contributions/day3-gemini.ipynb

27
week2/community-contributions/Gemini-api.ipynb

@ -28,18 +28,10 @@
},
{
"cell_type": "code",
"execution_count": 15,
"execution_count": null,
"id": "5fb5b749-d84b-4f8c-bfb9-2f5c4e8a2daa",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Google API Key exists and begins AIzaSyDU\n"
]
}
],
"outputs": [],
"source": [
"load_dotenv()\n",
"# openai_api_key = os.getenv('OPENAI_API_KEY')\n",
@ -88,21 +80,10 @@
},
{
"cell_type": "code",
"execution_count": 19,
"execution_count": null,
"id": "6d331aaf-162b-499e-af7e-5e097e84f1bd",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Why was the Data Scientist sad? \n",
"\n",
"Because they didn't get any arrays!\n",
"\n"
]
}
],
"outputs": [],
"source": [
"# The API for Gemini has a slightly different structure.\n",
"# I've heard that on some PCs, this Gemini code causes the Kernel to crash.\n",

118
week2/community-contributions/day2-gemini.ipynb

@ -94,21 +94,10 @@
},
{
"cell_type": "code",
"execution_count": 16,
"execution_count": null,
"id": "8fe3c66c-d25d-4627-a401-d84c7d6613e7",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'Today is October 26, 2023.\\n'"
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"message_gemini(\"What is today's date?\")\n",
"# message_gemini(\"tell me a funny machine learning joke\")"
@ -116,53 +105,10 @@
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": null,
"id": "b27027ed-4bff-493c-a41e-8318003e0387",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"models/chat-bison-001\n",
"models/text-bison-001\n",
"models/embedding-gecko-001\n",
"models/gemini-1.0-pro-latest\n",
"models/gemini-1.0-pro\n",
"models/gemini-pro\n",
"models/gemini-1.0-pro-001\n",
"models/gemini-1.0-pro-vision-latest\n",
"models/gemini-pro-vision\n",
"models/gemini-1.5-pro-latest\n",
"models/gemini-1.5-pro-001\n",
"models/gemini-1.5-pro-002\n",
"models/gemini-1.5-pro\n",
"models/gemini-1.5-pro-exp-0801\n",
"models/gemini-1.5-pro-exp-0827\n",
"models/gemini-1.5-flash-latest\n",
"models/gemini-1.5-flash-001\n",
"models/gemini-1.5-flash-001-tuning\n",
"models/gemini-1.5-flash\n",
"models/gemini-1.5-flash-exp-0827\n",
"models/gemini-1.5-flash-002\n",
"models/gemini-1.5-flash-8b\n",
"models/gemini-1.5-flash-8b-001\n",
"models/gemini-1.5-flash-8b-latest\n",
"models/gemini-1.5-flash-8b-exp-0827\n",
"models/gemini-1.5-flash-8b-exp-0924\n",
"models/gemini-2.0-flash-exp\n",
"models/gemini-exp-1206\n",
"models/gemini-exp-1121\n",
"models/gemini-exp-1114\n",
"models/gemini-2.0-flash-thinking-exp\n",
"models/gemini-2.0-flash-thinking-exp-1219\n",
"models/learnlm-1.5-pro-experimental\n",
"models/embedding-001\n",
"models/text-embedding-004\n",
"models/aqa\n"
]
}
],
"outputs": [],
"source": [
"import google.generativeai as genai\n",
"for model in genai.list_models():\n",
@ -185,28 +131,10 @@
},
{
"cell_type": "code",
"execution_count": 18,
"execution_count": null,
"id": "5941fe3f-aab9-47ba-b29f-d99aa3b40aed",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Shout has been called with input hello\n"
]
},
{
"data": {
"text/plain": [
"'HELLO'"
]
},
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"shout(\"hello\")"
]
@ -414,40 +342,10 @@
},
{
"cell_type": "code",
"execution_count": 35,
"execution_count": null,
"id": "d9554211-c832-4558-90c8-fceab95fd23c",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"* Running on local URL: http://127.0.0.1:7871\n",
"\n",
"To create a public link, set `share=True` in `launch()`.\n"
]
},
{
"data": {
"text/html": [
"<div><iframe src=\"http://127.0.0.1:7871/\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": []
},
"execution_count": 35,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"view = gr.Interface(\n",
" fn=stream_brochure,\n",

172
week2/community-contributions/day3-gemini.ipynb

@ -63,21 +63,10 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": null,
"id": "ba2123e7-77ed-43b4-8c37-03658fb42b78",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Why was the Data Scientist sad? \n",
"\n",
"Because they didn't get any arrays!\n",
"\n"
]
}
],
"outputs": [],
"source": [
"system_message = \"You are an assistant that is great at telling jokes\"\n",
"user_prompt = \"Tell a light-hearted joke for an audience of Data Scientists\"\n",
@ -113,19 +102,10 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": null,
"id": "91578b16",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Hello Shardul! It's nice to meet you. How can I help you today?\n",
"\n"
]
}
],
"outputs": [],
"source": [
"chat = model.start_chat(history=[])\n",
"response = chat.send_message('Hello! My name is Shardul.')\n",
@ -134,19 +114,10 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": null,
"id": "7c4bc38f",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Did you know that the iconic lightsaber fight choreography in Star Wars was heavily influenced by Japanese samurai sword fighting styles? Specifically, the movements and stances of the Jedi and Sith were inspired by kendo and other forms of Japanese martial arts. This gives the lightsaber battles a unique elegance and deadly precision that sets them apart from typical sword fights in other films.\n",
"\n"
]
}
],
"outputs": [],
"source": [
"response = chat.send_message('Can you tell something interesting about star wars?')\n",
"print(response.text)"
@ -154,19 +125,10 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": null,
"id": "337bee91",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Yes, your name is Shardul.\n",
"\n"
]
}
],
"outputs": [],
"source": [
"response = chat.send_message('Do you remember what my name is?')\n",
"print(response.text)"
@ -174,44 +136,10 @@
},
{
"cell_type": "code",
"execution_count": 34,
"execution_count": null,
"id": "bcaf4d95",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[parts {\n",
" text: \"Hello! My name is Shardul.\"\n",
" }\n",
" role: \"user\",\n",
" parts {\n",
" text: \"Hello Shardul! It\\'s nice to meet you. How can I help you today?\\n\"\n",
" }\n",
" role: \"model\",\n",
" parts {\n",
" text: \"Can you tell something interesting about star wars?\"\n",
" }\n",
" role: \"user\",\n",
" parts {\n",
" text: \"One interesting fact about Star Wars is that the iconic lightsaber sound effect was created by recording the hum of a broken-down projector. The sound designer, Ben Burtt, combined that with the sound of a television\\'s static to create the distinctive whoosh and hum we all know and love. It\\'s a perfect example of how seemingly mundane sounds can be creatively repurposed to create iconic elements of a beloved franchise.\\n\"\n",
" }\n",
" role: \"model\",\n",
" parts {\n",
" text: \"Do you remember what my name is?\"\n",
" }\n",
" role: \"user\",\n",
" parts {\n",
" text: \"Yes, your name is Shardul.\\n\"\n",
" }\n",
" role: \"model\"]"
]
},
"execution_count": 34,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"chat.history"
]
@ -279,37 +207,10 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": null,
"id": "f6e745e1",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Gen\n",
" AI, short for **Generative AI**, refers to a type of artificial intelligence\n",
" that can create new content, rather than just analyzing or classifying existing data. \n",
"This content can take many forms, including:\n",
"\n",
"* **Text:** Writing stories, articles, summaries, poems, code, scripts, etc. Examples\n",
" include ChatGPT, Bard, and Jasper.\n",
"* **Images:** Generating realistic or stylized images from text descriptions (prompts). Examples include DALL-E \n",
"2, Midjourney, and Stable Diffusion.\n",
"* **Audio:** Creating music, sound effects, and voiceovers. Examples include Amper Music and Jukebox.\n",
"* **Video:** Generating short video clips. This is a\n",
" rapidly developing area.\n",
"* **3D models:** Creating three-dimensional objects and scenes.\n",
"\n",
"Gen AI achieves this by learning patterns and structures from massive datasets and then using this knowledge to generate new, similar but unique outputs. The\n",
" underlying techniques often involve deep learning models, particularly those based on neural networks like transformers, autoencoders, and generative adversarial networks (GANs).\n",
"\n",
"In essence, Gen AI moves beyond simply processing information to actively *producing* it, opening up exciting possibilities in various fields, but also raising ethical and societal concerns about misinformation\n",
", copyright, and job displacement.\n",
"\n"
]
}
],
"outputs": [],
"source": [
"chat_model = genai.GenerativeModel('gemini-1.5-flash')\n",
"chat = chat_model.start_chat()\n",
@ -323,55 +224,10 @@
},
{
"cell_type": "code",
"execution_count": 44,
"execution_count": null,
"id": "dce941ee",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/opt/homebrew/Caskroom/miniconda/base/envs/llms/lib/python3.11/site-packages/gradio/components/chatbot.py:248: UserWarning: The 'tuples' format for chatbot messages is deprecated and will be removed in a future version of Gradio. Please set type='messages' instead, which uses openai-style 'role' and 'content' keys.\n",
" warnings.warn(\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"* Running on local URL: http://127.0.0.1:7870\n",
"\n",
"To create a public link, set `share=True` in `launch()`.\n"
]
},
{
"data": {
"text/html": [
"<div><iframe src=\"http://127.0.0.1:7870/\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Keyboard interruption in main thread... closing server.\n"
]
},
{
"data": {
"text/plain": []
},
"execution_count": 44,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"import time\n",
"\n",

Loading…
Cancel
Save