diff --git a/week2/day2.ipynb b/week2/day2.ipynb index bf5367f..363ca6d 100644 --- a/week2/day2.ipynb +++ b/week2/day2.ipynb @@ -16,7 +16,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "id": "c44c5494-950d-4d2f-8d4f-b87b57c5b330", "metadata": {}, "outputs": [], @@ -35,7 +35,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "id": "d1715421-cead-400b-99af-986388a97aff", "metadata": {}, "outputs": [], @@ -45,10 +45,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "id": "337d5dfc-0181-4e3b-8ab9-e78e0c3f657b", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "OpenAI API Key exists and begins sk-proj-\n", + "Anthropic API Key exists and begins sk-ant-\n", + "Google API Key exists and begins AIzaSyDY\n" + ] + } + ], "source": [ "# Load environment variables in a file called .env\n", "# Print the key prefixes to help with any debugging\n", @@ -76,7 +86,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "id": "22586021-1795-4929-8079-63f5bb4edd4c", "metadata": {}, "outputs": [], @@ -92,7 +102,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "id": "b16e6021-6dc4-4397-985a-6679d6c8ffd5", "metadata": {}, "outputs": [], @@ -104,7 +114,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "id": "02ef9b69-ef31-427d-86d0-b8c799e1c1b1", "metadata": {}, "outputs": [], @@ -125,10 +135,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "id": "aef7d314-2b13-436b-b02d-8de3b72b193f", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "\"Today's date is October 18, 2023.\"" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "message_gpt(\"What is today's date?\")" ] @@ -143,7 +164,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "id": "bc664b7a-c01d-4fea-a1de-ae22cdd5141a", "metadata": {}, "outputs": [], @@ -157,20 +178,68 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 9, "id": "083ea451-d3a0-4d13-b599-93ed49b975e4", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Shout has been called with input hello\n" + ] + }, + { + "data": { + "text/plain": [ + "'HELLO'" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "shout(\"hello\")" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 10, "id": "08f1f15a-122e-4502-b112-6ee2817dda32", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "* Running on local URL: http://127.0.0.1:7860\n", + "\n", + "To create a public link, set `share=True` in `launch()`.\n" + ] + }, + { + "data": { + "text/html": [ + "
" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# The simplicty of gradio. This might appear in \"light mode\" - I'll show you how to make this in dark mode later.\n", "\n", @@ -179,10 +248,41 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 11, "id": "c9a359a4-685c-4c99-891c-bb4d1cb7f426", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "* Running on local URL: http://127.0.0.1:7861\n", + "* Running on public URL: https://2de7e99a4de25a4c27.gradio.live\n", + "\n", + "This share link expires in 72 hours. For free permanent hosting and GPU upgrades, run `gradio deploy` from the terminal in the working directory to deploy to Hugging Face Spaces (https://huggingface.co/spaces)\n" + ] + }, + { + "data": { + "text/html": [ + "
" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# Adding share=True means that it can be accessed publically\n", "# A more permanent hosting is available using a platform called Spaces from HuggingFace, which we will touch on next week\n", @@ -193,10 +293,40 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 12, "id": "cd87533a-ff3a-4188-8998-5bedd5ba2da3", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "* Running on local URL: http://127.0.0.1:7862\n", + "\n", + "To create a public link, set `share=True` in `launch()`.\n" + ] + }, + { + "data": { + "text/html": [ + "
" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# Adding inbrowser=True opens up a new browser window automatically\n", "\n", @@ -215,10 +345,47 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 19, "id": "e8129afa-532b-4b15-b93c-aa9cca23a546", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "* Running on local URL: http://127.0.0.1:7868\n", + "\n", + "To create a public link, set `share=True` in `launch()`.\n" + ] + }, + { + "data": { + "text/html": [ + "
" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [] + }, + "execution_count": 19, + "metadata": {}, + "output_type": "execute_result" + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Shout has been called with input Hello\n" + ] + } + ], "source": [ "# Define this variable and then pass js=force_dark_mode when creating the Interface\n", "\n", @@ -236,10 +403,40 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 14, "id": "3cc67b26-dd5f-406d-88f6-2306ee2950c0", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "* Running on local URL: http://127.0.0.1:7864\n", + "\n", + "To create a public link, set `share=True` in `launch()`.\n" + ] + }, + { + "data": { + "text/html": [ + "
" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [] + }, + "execution_count": 14, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# Inputs and Outputs\n", "\n", @@ -254,10 +451,40 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 15, "id": "f235288e-63a2-4341-935b-1441f9be969b", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "* Running on local URL: http://127.0.0.1:7865\n", + "\n", + "To create a public link, set `share=True` in `launch()`.\n" + ] + }, + { + "data": { + "text/html": [ + "
" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [] + }, + "execution_count": 15, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# And now - changing the function from \"shout\" to \"message_gpt\"\n", "\n", @@ -272,10 +499,40 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 20, "id": "af9a3262-e626-4e4b-80b0-aca152405e63", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "* Running on local URL: http://127.0.0.1:7869\n", + "\n", + "To create a public link, set `share=True` in `launch()`.\n" + ] + }, + { + "data": { + "text/html": [ + "
" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [] + }, + "execution_count": 20, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# Let's use Markdown\n", "# Are you wondering why it makes any difference to set system_message when it's not referred to in the code below it?\n", @@ -295,7 +552,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 28, "id": "88c04ebf-0671-4fea-95c9-bc1565d4bb4f", "metadata": {}, "outputs": [], @@ -322,10 +579,40 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 29, "id": "0bb1f789-ff11-4cba-ac67-11b815e29d09", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "* Running on local URL: http://127.0.0.1:7874\n", + "\n", + "To create a public link, set `share=True` in `launch()`.\n" + ] + }, + { + "data": { + "text/html": [ + "
" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [] + }, + "execution_count": 29, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "view = gr.Interface(\n", " fn=stream_gpt,\n", @@ -338,7 +625,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 22, "id": "bbc8e930-ba2a-4194-8f7c-044659150626", "metadata": {}, "outputs": [], @@ -362,10 +649,40 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 23, "id": "a0066ffd-196e-4eaf-ad1e-d492958b62af", "metadata": {}, - "outputs": [], + "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": [ + "
" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [] + }, + "execution_count": 23, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "view = gr.Interface(\n", " fn=stream_claude,\n", @@ -401,7 +718,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 24, "id": "0087623a-4e31-470b-b2e6-d8d16fc7bcf5", "metadata": {}, "outputs": [], @@ -418,14 +735,44 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 30, "id": "8d8ce810-997c-4b6a-bc4f-1fc847ac8855", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "* Running on local URL: http://127.0.0.1:7875\n", + "\n", + "To create a public link, set `share=True` in `launch()`.\n" + ] + }, + { + "data": { + "text/html": [ + "
" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [] + }, + "execution_count": 30, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "view = gr.Interface(\n", " fn=stream_model,\n", - " inputs=[gr.Textbox(label=\"Your message:\"), gr.Dropdown([\"GPT\", \"Claude\"], label=\"Select model\", value=\"GPT\")],\n", + " inputs=[gr.Textbox(label=\"Your message:\"), gr.Dropdown([\"GPT\", \"Claude\"], label=\"Select model\", value=\"Claude\")],\n", " outputs=[gr.Markdown(label=\"Response:\")],\n", " flagging_mode=\"never\"\n", ")\n", @@ -464,7 +811,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 31, "id": "1626eb2e-eee8-4183-bda5-1591b58ae3cf", "metadata": {}, "outputs": [], @@ -492,7 +839,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 32, "id": "c701ec17-ecd5-4000-9f68-34634c8ed49d", "metadata": {}, "outputs": [], @@ -505,13 +852,13 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 35, "id": "5def90e0-4343-4f58-9d4a-0e36e445efa4", "metadata": {}, "outputs": [], "source": [ - "def stream_brochure(company_name, url, model):\n", - " prompt = f\"Please generate a company brochure for {company_name}. Here is their landing page:\\n\"\n", + "def stream_brochure(company_name, url, model, tone):\n", + " prompt = f\"Please generate a company brochure for {company_name}. Write the brochure in the following tone: {tone}.Here is their landing page:\\n\"\n", " prompt += Website(url).get_contents()\n", " if model==\"GPT\":\n", " result = stream_gpt(prompt)\n", @@ -524,17 +871,48 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 39, "id": "66399365-5d67-4984-9d47-93ed26c0bd3d", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "* Running on local URL: http://127.0.0.1:7877\n", + "\n", + "To create a public link, set `share=True` in `launch()`.\n" + ] + }, + { + "data": { + "text/html": [ + "
" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [] + }, + "execution_count": 39, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "view = gr.Interface(\n", " fn=stream_brochure,\n", " inputs=[\n", " gr.Textbox(label=\"Company name:\"),\n", " gr.Textbox(label=\"Landing page URL including http:// or https://\"),\n", - " gr.Dropdown([\"GPT\", \"Claude\"], label=\"Select model\")],\n", + " gr.Dropdown([\"GPT\", \"Claude\"], label=\"Select model\"),\n", + " gr.Dropdown([\"Formal\", \"Casual\", \"Academic\", \"Funny\", \"Snarky\"], label=\"Select tone\", value=\"Formal\"),],\n", " outputs=[gr.Markdown(label=\"Brochure:\")],\n", " flagging_mode=\"never\"\n", ")\n",