@ -14,7 +14,7 @@
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": null ,
"execution_count": 2 ,
"id": "c44c5494-950d-4d2f-8d4f-b87b57c5b330",
"id": "c44c5494-950d-4d2f-8d4f-b87b57c5b330",
"metadata": {},
"metadata": {},
"outputs": [],
"outputs": [],
@ -33,7 +33,7 @@
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": null ,
"execution_count": 3 ,
"id": "d1715421-cead-400b-99af-986388a97aff",
"id": "d1715421-cead-400b-99af-986388a97aff",
"metadata": {},
"metadata": {},
"outputs": [],
"outputs": [],
@ -43,7 +43,7 @@
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": null ,
"execution_count": 4 ,
"id": "337d5dfc-0181-4e3b-8ab9-e78e0c3f657b",
"id": "337d5dfc-0181-4e3b-8ab9-e78e0c3f657b",
"metadata": {},
"metadata": {},
"outputs": [],
"outputs": [],
@ -58,7 +58,7 @@
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": null ,
"execution_count": 5 ,
"id": "22586021-1795-4929-8079-63f5bb4edd4c",
"id": "22586021-1795-4929-8079-63f5bb4edd4c",
"metadata": {},
"metadata": {},
"outputs": [],
"outputs": [],
@ -74,19 +74,19 @@
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": null ,
"execution_count": 7 ,
"id": "b16e6021-6dc4-4397-985a-6679d6c8ffd5",
"id": "b16e6021-6dc4-4397-985a-6679d6c8ffd5",
"metadata": {},
"metadata": {},
"outputs": [],
"outputs": [],
"source": [
"source": [
"# A generic system message - no more snarky adversarial AIs!\n",
"# A generic system message - no more snarky adversarial AIs!\n",
"\n",
"\n",
"system_message = \"You are a helpful assistant\""
"system_message = \"You are a helpful assistant that responds in markdown \""
]
]
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": null ,
"execution_count": 7 ,
"id": "02ef9b69-ef31-427d-86d0-b8c799e1c1b1",
"id": "02ef9b69-ef31-427d-86d0-b8c799e1c1b1",
"metadata": {},
"metadata": {},
"outputs": [],
"outputs": [],
@ -107,10 +107,21 @@
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": null ,
"execution_count": 8 ,
"id": "aef7d314-2b13-436b-b02d-8de3b72b193f",
"id": "aef7d314-2b13-436b-b02d-8de3b72b193f",
"metadata": {},
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"\"Today's date is October 3, 2023.\""
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"source": [
"message_gpt(\"What is today's date?\")"
"message_gpt(\"What is today's date?\")"
]
]
@ -125,7 +136,7 @@
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": null ,
"execution_count": 9 ,
"id": "bc664b7a-c01d-4fea-a1de-ae22cdd5141a",
"id": "bc664b7a-c01d-4fea-a1de-ae22cdd5141a",
"metadata": {},
"metadata": {},
"outputs": [],
"outputs": [],
@ -139,72 +150,265 @@
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": null ,
"execution_count": 10 ,
"id": "083ea451-d3a0-4d13-b599-93ed49b975e4",
"id": "083ea451-d3a0-4d13-b599-93ed49b975e4",
"metadata": {},
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Shout has been called with input hello\n"
]
},
{
"data": {
"text/plain": [
"'HELLO'"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"source": [
"shout(\"hello\")"
"shout(\"hello\")"
]
]
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": null,
"execution_count": 11 ,
"id": "08f1f15a-122e-4502-b112-6ee2817dda32",
"id": "08f1f15a-122e-4502-b112-6ee2817dda32",
"metadata": {},
"metadata": {
"outputs": [],
"scrolled": true
},
"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": [
"<div><iframe src=\"http://127.0.0.1:7860/\" 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": 11,
"metadata": {},
"output_type": "execute_result"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Shout has been called with input hello\n",
"Created dataset file at: .gradio\\flagged\\dataset1.csv\n"
]
}
],
"source": [
"source": [
"gr.Interface(fn=shout, inputs=\"textbox\", outputs=\"textbox\").launch()"
"gr.Interface(fn=shout, inputs=\"textbox\", outputs=\"textbox\").launch()"
]
]
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": null,
"execution_count": 14 ,
"id": "c9a359a4-685c-4c99-891c-bb4d1cb7f426",
"id": "c9a359a4-685c-4c99-891c-bb4d1cb7f426",
"metadata": {},
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"* Running on local URL: http://127.0.0.1:7863\n",
"* Running on public URL: https://1b149f8be167f11821.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": [
"<div><iframe src=\"https://1b149f8be167f11821.gradio.live\" 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": 14,
"metadata": {},
"output_type": "execute_result"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Shout has been called with input wow, this is cool! \n"
]
}
],
"source": [
"source": [
"gr.Interface(fn=shout, inputs=\"textbox\", outputs=\"textbox\", allow_flagging=\"never\").launch(share=True)"
"gr.Interface(fn=shout, inputs=\"textbox\", outputs=\"textbox\", flagging_mode =\"never\").launch(share=True)"
]
]
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": null,
"execution_count": 16 ,
"id": "3cc67b26-dd5f-406d-88f6-2306ee2950c0",
"id": "3cc67b26-dd5f-406d-88f6-2306ee2950c0",
"metadata": {},
"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": [
"<div><iframe src=\"http://127.0.0.1:7865/\" 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": 16,
"metadata": {},
"output_type": "execute_result"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Shout has been called with input hello again :)\n"
]
}
],
"source": [
"source": [
"view = gr.Interface(\n",
"view = gr.Interface(\n",
" fn=shout,\n",
" fn=shout,\n",
" inputs=[gr.Textbox(label=\"Your message:\", lines=6)],\n",
" inputs=[gr.Textbox(label=\"Your message:\", lines=6)],\n",
" outputs=[gr.Textbox(label=\"Response:\", lines=8)],\n",
" outputs=[gr.Textbox(label=\"Response:\", lines=8)],\n",
" allow_flagging=\"never\"\n",
" flagging_mode =\"never\"\n",
")\n",
")\n",
"view.launch()"
"view.launch()"
]
]
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": null,
"execution_count": 17 ,
"id": "f235288e-63a2-4341-935b-1441f9be969b",
"id": "f235288e-63a2-4341-935b-1441f9be969b",
"metadata": {},
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"* Running on local URL: http://127.0.0.1:7866\n",
"\n",
"To create a public link, set `share=True` in `launch()`.\n"
]
},
{
"data": {
"text/html": [
"<div><iframe src=\"http://127.0.0.1:7866/\" 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": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"source": [
"view = gr.Interface(\n",
"view = gr.Interface(\n",
" fn=message_gpt,\n",
" fn=message_gpt,\n",
" inputs=[gr.Textbox(label=\"Your message:\", lines=6)],\n",
" inputs=[gr.Textbox(label=\"Your message:\", lines=6)],\n",
" outputs=[gr.Textbox(label=\"Response:\", lines=8)],\n",
" outputs=[gr.Textbox(label=\"Response:\", lines=8)],\n",
" allow_flagging=\"never\"\n",
" flagging_mode =\"never\"\n",
")\n",
")\n",
"view.launch()"
"view.launch()"
]
]
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": null,
"execution_count": 18 ,
"id": "af9a3262-e626-4e4b-80b0-aca152405e63",
"id": "af9a3262-e626-4e4b-80b0-aca152405e63",
"metadata": {},
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"* Running on local URL: http://127.0.0.1:7867\n",
"\n",
"To create a public link, set `share=True` in `launch()`.\n"
]
},
{
"data": {
"text/html": [
"<div><iframe src=\"http://127.0.0.1:7867/\" 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": 18,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"source": [
"system_message = \"You are a helpful assistant that responds in markdown\"\n",
"system_message = \"You are a helpful assistant that responds in markdown\"\n",
"\n",
"\n",
@ -212,14 +416,14 @@
" fn=message_gpt,\n",
" fn=message_gpt,\n",
" inputs=[gr.Textbox(label=\"Your message:\")],\n",
" inputs=[gr.Textbox(label=\"Your message:\")],\n",
" outputs=[gr.Markdown(label=\"Response:\")],\n",
" outputs=[gr.Markdown(label=\"Response:\")],\n",
" allow_ flagging=\"never\"\n",
" flagging_mode =\"never\"\n",
")\n",
")\n",
"view.launch()"
"view.launch()"
]
]
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": null ,
"execution_count": 8 ,
"id": "88c04ebf-0671-4fea-95c9-bc1565d4bb4f",
"id": "88c04ebf-0671-4fea-95c9-bc1565d4bb4f",
"metadata": {},
"metadata": {},
"outputs": [],
"outputs": [],
@ -244,23 +448,53 @@
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": null ,
"execution_count": 20 ,
"id": "0bb1f789-ff11-4cba-ac67-11b815e29d09",
"id": "0bb1f789-ff11-4cba-ac67-11b815e29d09",
"metadata": {},
"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": [
"<div><iframe src=\"http://127.0.0.1:7868/\" 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": 20,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"source": [
"view = gr.Interface(\n",
"view = gr.Interface(\n",
" fn=stream_gpt,\n",
" fn=stream_gpt,\n",
" inputs=[gr.Textbox(label=\"Your message:\")],\n",
" inputs=[gr.Textbox(label=\"Your message:\")],\n",
" outputs=[gr.Markdown(label=\"Response:\")],\n",
" outputs=[gr.Markdown(label=\"Response:\")],\n",
" allow_flagging=\"never\"\n",
" flagging_mode =\"never\"\n",
")\n",
")\n",
"view.launch()"
"view.launch()"
]
]
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": null,
"execution_count": 9 ,
"id": "bbc8e930-ba2a-4194-8f7c-044659150626",
"id": "bbc8e930-ba2a-4194-8f7c-044659150626",
"metadata": {},
"metadata": {},
"outputs": [],
"outputs": [],
@ -284,23 +518,195 @@
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": null ,
"execution_count": 22 ,
"id": "a0066ffd-196e-4eaf-ad1e-d492958b62af",
"id": "a0066ffd-196e-4eaf-ad1e-d492958b62af",
"metadata": {},
"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": [
"<div><iframe src=\"http://127.0.0.1:7869/\" 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": 22,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"source": [
"view = gr.Interface(\n",
"view = gr.Interface(\n",
" fn=stream_claude,\n",
" fn=stream_claude,\n",
" inputs=[gr.Textbox(label=\"Your message:\")],\n",
" inputs=[gr.Textbox(label=\"Your message:\")],\n",
" outputs=[gr.Markdown(label=\"Response:\")],\n",
" outputs=[gr.Markdown(label=\"Response:\")],\n",
" allow_flagging=\"never\"\n",
" flagging_mode =\"never\"\n",
")\n",
")\n",
"view.launch()"
"view.launch()"
]
]
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": null,
"execution_count": 186,
"id": "1f3906c9-2bb2-40ca-acc9-c3e8a7c4c61c",
"metadata": {},
"outputs": [],
"source": [
"def chat_gemini(prompt):\n",
" gemini = google.generativeai.GenerativeModel(\n",
" model_name='gemini-1.5-flash',\n",
" system_instruction=system_message\n",
" )\n",
" response = gemini.generate_content(prompt)\n",
" return(response.text)"
]
},
{
"cell_type": "code",
"execution_count": 187,
"id": "a14cddc3-7a1e-4c09-98f4-ee6b33486922",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'Hello! 👋 How can I help you today? 😊 \\n'"
]
},
"execution_count": 187,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"chat_gemini(\"Hello\")"
]
},
{
"cell_type": "code",
"execution_count": 87,
"id": "6d74e2de-1fcd-49d4-9991-bffa7f5099ec",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"* Running on local URL: http://127.0.0.1:7879\n",
"\n",
"To create a public link, set `share=True` in `launch()`.\n"
]
},
{
"data": {
"text/html": [
"<div><iframe src=\"http://127.0.0.1:7879/\" 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": 87,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"gr.Interface(fn=chat_gemini, inputs=\"textbox\", outputs=\"textbox\").launch()"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "223465b1-6699-4d34-b1a9-38306edc4ca7",
"metadata": {},
"outputs": [],
"source": [
"def stream_gemini(prompt):\n",
" gemini = google.generativeai.GenerativeModel(\n",
" model_name='gemini-1.5-flash',\n",
" system_instruction=system_message\n",
" )\n",
" stream = gemini.generate_content(prompt, stream=True)\n",
" result = \"\"\n",
" for chunk in stream:\n",
" result += chunk.text or \"\"\n",
" yield result"
]
},
{
"cell_type": "code",
"execution_count": 223,
"id": "28dc9075-013b-43eb-a1ae-59097c781b86",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"* Running on local URL: http://127.0.0.1:7897\n",
"\n",
"To create a public link, set `share=True` in `launch()`.\n"
]
},
{
"data": {
"text/html": [
"<div><iframe src=\"http://127.0.0.1:7897/\" 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": 223,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"view = gr.Interface(\n",
" fn=stream_gemini,\n",
" inputs=[gr.Textbox(label=\"Your message:\")],\n",
" outputs=[gr.Markdown(label=\"Response:\")],\n",
" flagging_mode=\"never\"\n",
")\n",
"view.launch()"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "0087623a-4e31-470b-b2e6-d8d16fc7bcf5",
"id": "0087623a-4e31-470b-b2e6-d8d16fc7bcf5",
"metadata": {},
"metadata": {},
"outputs": [],
"outputs": [],
@ -308,26 +714,67 @@
"def stream_model(prompt, model):\n",
"def stream_model(prompt, model):\n",
" if model==\"GPT\":\n",
" if model==\"GPT\":\n",
" result = stream_gpt(prompt)\n",
" result = stream_gpt(prompt)\n",
" elif model==\"Gemini\":\n",
" result = stream_gemini(prompt)\n",
" elif model==\"Claude\":\n",
" elif model==\"Claude\":\n",
" result = stream_claude(prompt)\n",
" result = stream_claude(prompt)\n",
" else:\n",
" else:\n",
" raise ValueError(\"Unknown model\")\n",
" raise ValueError(\"Unknown model\")\n",
" for chunk in result:\n",
" for reply in result:\n",
" yield chunk "
" yield reply "
]
]
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": null ,
"execution_count": 12 ,
"id": "8d8ce810-997c-4b6a-bc4f-1fc847ac8855",
"id": "8d8ce810-997c-4b6a-bc4f-1fc847ac8855",
"metadata": {},
"metadata": {
"outputs": [],
"scrolled": true
},
"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": [
"<div><iframe src=\"http://127.0.0.1:7860/\" 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": 12,
"metadata": {},
"output_type": "execute_result"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Using existing dataset file at: .gradio\\flagged\\dataset2.csv\n"
]
}
],
"source": [
"source": [
"view = gr.Interface(\n",
"view = gr.Interface(\n",
" fn=stream_model,\n",
" fn=stream_model,\n",
" inputs=[gr.Textbox(label=\"Your message:\"), gr.Dropdown([\"GPT\", \"Claude\"], label=\"Select model\")],\n",
" inputs=[gr.Textbox(label=\"Your message:\"), gr.Dropdown([\"GPT\", \"Claude\", \"Gemini\" ], label=\"Select model\")],\n",
" outputs=[gr.Markdown(label=\"Response:\")],\n",
" outputs=[gr.Markdown(label=\"Response:\")],\n",
" allow_flagging=\"never\"\n",
" flagging_mode=\"auto \"\n",
")\n",
")\n",
"view.launch()"
"view.launch()"
]
]
@ -344,7 +791,7 @@
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": null ,
"execution_count": 18 ,
"id": "1626eb2e-eee8-4183-bda5-1591b58ae3cf",
"id": "1626eb2e-eee8-4183-bda5-1591b58ae3cf",
"metadata": {},
"metadata": {},
"outputs": [],
"outputs": [],
@ -372,50 +819,102 @@
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": null ,
"execution_count": 25 ,
"id": "c701ec17-ecd5-4000-9f68-34634c8ed49d",
"id": "c701ec17-ecd5-4000-9f68-34634c8ed49d",
"metadata": {},
"metadata": {},
"outputs": [],
"outputs": [],
"source": [
"source": [
"system_prompt = \"You are an assistant that analyzes the contents of a company website landing page \\\n",
"serious_system_prompt = \"You are an assistant that analyzes the contents of a company website landing page \\\n",
"and creates a short brochure about the company for prospective customers, investors and recruits. Respond in markdown.\""
"and creates a short brochure about the company for prospective customers, investors and recruits. Use a serious tone in your respose. \\\n",
"Respond in markdown.\""
]
]
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": null,
"execution_count": 26,
"id": "67969d54-2ab5-4133-8d3d-83f08e63755d",
"metadata": {},
"outputs": [],
"source": [
"funny_system_prompt = \"You are an assistant that analyzes the contents of a company website landing page \\\n",
"and creates a short brochure about the company for prospective customers, investors and recruits. Use a funny tone in your response. \\\n",
"Respond in markdown.\""
]
},
{
"cell_type": "code",
"execution_count": 27,
"id": "5def90e0-4343-4f58-9d4a-0e36e445efa4",
"id": "5def90e0-4343-4f58-9d4a-0e36e445efa4",
"metadata": {},
"metadata": {},
"outputs": [],
"outputs": [],
"source": [
"source": [
"def stream_brochure(company_name, url, model):\n",
"def stream_brochure(company_name, url, model, mode ):\n",
" prompt = f\"Please generate a company brochure for {company_name}. Here is their landing page:\\n\"\n",
" prompt = f\"Please generate a company brochure for {company_name}. Here is their landing page:\\n\"\n",
" prompt += Website(url).get_contents()\n",
" prompt += Website(url).get_contents()\n",
" if model==\"GPT\":\n",
" if model==\"GPT\":\n",
" result = stream_gpt(prompt)\n",
" result = stream_gpt(prompt)\n",
" elif model==\"Claude\":\n",
" elif model==\"Claude\":\n",
" result = stream_claude(prompt)\n",
" result = stream_claude(prompt)\n",
" elif model==\"Gemini\":\n",
" result = stream_gemini(prompt)\n",
" else:\n",
" raise ValueError(\"Unknown model\")\n",
" if mode==\"Funny\":\n",
" system_prompt = funny_system_prompt\n",
" elif mode==\"Serious\":\n",
" system_prompt = serious_system_prompt\n",
" else:\n",
" else:\n",
" raise ValueError(\"Unknown model\")\n",
" raise ValueError(\"Unknown model\")\n",
" for chunk in result:\n",
" for reply in result:\n",
" yield chunk"
" yield reply "
]
]
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": null ,
"execution_count": 28 ,
"id": "66399365-5d67-4984-9d47-93ed26c0bd3d",
"id": "66399365-5d67-4984-9d47-93ed26c0bd3d",
"metadata": {},
"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": [
"<div><iframe src=\"http://127.0.0.1:7864/\" 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": 28,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"source": [
"view = gr.Interface(\n",
"view = gr.Interface(\n",
" fn=stream_brochure,\n",
" fn=stream_brochure,\n",
" inputs=[\n",
" inputs=[\n",
" gr.Textbox(label=\"Company name:\"),\n",
" gr.Textbox(label=\"Company name:\"),\n",
" gr.Textbox(label=\"Landing page URL:\"),\n",
" gr.Textbox(label=\"Landing page URL:\"),\n",
" gr.Dropdown([\"GPT\", \"Claude\"], label=\"Select model\")],\n",
" gr.Dropdown([\"GPT\", \"Claude\", \"Gemini\"], label=\"Select model\"),\n",
" gr.Dropdown([\"Funny\", \"Serious\"], label=\"Select mode\")],\n",
" outputs=[gr.Markdown(label=\"Brochure:\")],\n",
" outputs=[gr.Markdown(label=\"Brochure:\")],\n",
" allow_flagging=\"never\"\n",
" flagging_mode =\"never\"\n",
")\n",
")\n",
"view.launch()"
"view.launch()"
]
]
@ -445,7 +944,7 @@
"name": "python",
"name": "python",
"nbconvert_exporter": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"pygments_lexer": "ipython3",
"version": "3.11.1 0"
"version": "3.12. 0"
}
}
},
},
"nbformat": 4,
"nbformat": 4,