From d9f3c899690d30aac78d193f25f6478abab4b323 Mon Sep 17 00:00:00 2001 From: f-trycua Date: Thu, 3 Apr 2025 18:37:16 +0100 Subject: [PATCH] Add ai-gradio notebook --- notebooks/gradio_agent_nb.ipynb | 136 ++++++++++++++++++++++++++++++++ 1 file changed, 136 insertions(+) create mode 100644 notebooks/gradio_agent_nb.ipynb diff --git a/notebooks/gradio_agent_nb.ipynb b/notebooks/gradio_agent_nb.ipynb new file mode 100644 index 00000000..034861b1 --- /dev/null +++ b/notebooks/gradio_agent_nb.ipynb @@ -0,0 +1,136 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Gradio UI for Agent\n", + "\n", + "This notebook demonstrates how to use Cua's Agent using a Gradio frontend.\n", + "\n", + "Credits to AK391 for [github.com/AK391/ai-gradio](https://github.com/AK391/ai-gradio)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Installation" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "!pip install 'ai-gradio[cua]'" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Start the Gradio App" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "import os\n", + "\n", + "# Get API keys from environment or prompt user\n", + "openai_key = os.getenv(\"OPENAI_API_KEY\") or input(\"Enter your OpenAI API key: \")\n", + "os.environ[\"OPENAI_API_KEY\"] = openai_key" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "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", + "INFO:httpx:HTTP Request: GET http://127.0.0.1:7862/gradio_api/startup-events \"HTTP/1.1 200 OK\"\n", + "INFO:httpx:HTTP Request: HEAD http://127.0.0.1:7862/ \"HTTP/1.1 200 OK\"\n" + ] + }, + { + "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": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import gradio as gr\n", + "import ai_gradio\n", + "\n", + "gr.load(\n", + " name='cua:gpt-4', # currently ignored\n", + " src=ai_gradio.registry,\n", + " title=\"Cua - AI Agent\"\n", + ").launch()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Available Agent Loop & LLM Providers\n", + "\n", + "Refer to: https://github.com/trycua/cua/tree/main/libs/agent#agent-loops" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "cua", + "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.11.11" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +}