From ae1e5dcaf77f6fd871f93e97b79e05f1fb86e69a Mon Sep 17 00:00:00 2001
From: wolfjos1 <wolfjos1@msu.edu>
Date: Fri, 3 Feb 2023 15:28:53 -0500
Subject: [PATCH] Added Gradio example w/ multiple inputs

---
 GUI_Tutorial.ipynb | 99 +++++++++++++++++++++++++++++++++++-----------
 1 file changed, 75 insertions(+), 24 deletions(-)

diff --git a/GUI_Tutorial.ipynb b/GUI_Tutorial.ipynb
index fa8b1c5..2643f6e 100644
--- a/GUI_Tutorial.ipynb
+++ b/GUI_Tutorial.ipynb
@@ -22,7 +22,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 7,
+   "execution_count": 1,
    "id": "cdfdbb3e",
    "metadata": {},
    "outputs": [
@@ -30,7 +30,7 @@
      "name": "stdout",
      "output_type": "stream",
      "text": [
-      "Python 3.9.7\r\n"
+      "Python 3.8.2\r\n"
      ]
     }
    ],
@@ -40,7 +40,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 3,
+   "execution_count": 2,
    "id": "8f5edb3b",
    "metadata": {},
    "outputs": [],
@@ -58,7 +58,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 1,
+   "execution_count": 3,
    "id": "227461d8",
    "metadata": {
     "scrolled": false
@@ -80,7 +80,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 2,
+   "execution_count": 4,
    "id": "92c83d6b",
    "metadata": {
     "scrolled": true
@@ -90,7 +90,7 @@
      "name": "stdout",
      "output_type": "stream",
      "text": [
-      "Running on local URL:  http://127.0.0.1:7860/\n",
+      "Running on local URL:  http://127.0.0.1:7860\n",
       "\n",
       "To create a public link, set `share=True` in `launch()`.\n"
      ]
@@ -98,19 +98,10 @@
     {
      "data": {
       "text/html": [
-       "\n",
-       "        <iframe\n",
-       "            width=\"900\"\n",
-       "            height=\"500\"\n",
-       "            src=\"http://127.0.0.1:7860/\"\n",
-       "            frameborder=\"0\"\n",
-       "            allowfullscreen\n",
-       "            \n",
-       "        ></iframe>\n",
-       "        "
+       "<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.lib.display.IFrame at 0x7fcaf03ab5b0>"
+       "<IPython.core.display.HTML object>"
       ]
      },
      "metadata": {},
@@ -118,13 +109,9 @@
     },
     {
      "data": {
-      "text/plain": [
-       "(<fastapi.applications.FastAPI at 0x7fcac199eee0>,\n",
-       " 'http://127.0.0.1:7860/',\n",
-       " None)"
-      ]
+      "text/plain": []
      },
-     "execution_count": 2,
+     "execution_count": 4,
      "metadata": {},
      "output_type": "execute_result"
     }
@@ -152,6 +139,70 @@
     "With these components, you can quickly create and launch an interface."
    ]
   },
+  {
+   "cell_type": "markdown",
+   "id": "d4bd4273",
+   "metadata": {},
+   "source": [
+    "### Adding additional Inputs:\n",
+    "\n",
+    "Suppose you had a more complex function, with multiple inputs and outputs. In the example below, we define a function that takes a string, boolean, and number, and returns a string and number. Take a look how you pass a list of input and output components.\n",
+    "\n",
+    "\n",
+    "Source: https://gradio.app/quickstart/"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 5,
+   "id": "dcc87cd1",
+   "metadata": {},
+   "outputs": [
+    {
+     "name": "stdout",
+     "output_type": "stream",
+     "text": [
+      "Running on local URL:  http://127.0.0.1:7861\n",
+      "\n",
+      "To create a public link, set `share=True` in `launch()`.\n"
+     ]
+    },
+    {
+     "data": {
+      "text/html": [
+       "<div><iframe src=\"http://127.0.0.1:7861/\" 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": 5,
+     "metadata": {},
+     "output_type": "execute_result"
+    }
+   ],
+   "source": [
+    "def greet(name, is_morning, temperature):\n",
+    "    salutation = \"Good morning\" if is_morning else \"Good evening\"\n",
+    "    greeting = f\"{salutation} {name}. It is {temperature} degrees today\"\n",
+    "    celsius = (temperature - 32) * 5 / 9\n",
+    "    return greeting, round(celsius, 2)\n",
+    "\n",
+    "demo = gr.Interface(\n",
+    "    fn=greet,\n",
+    "    inputs=[\"text\", \"checkbox\", gr.Slider(0, 100)],\n",
+    "    outputs=[\"text\", \"number\"],\n",
+    ")\n",
+    "demo.launch()"
+   ]
+  },
   {
    "cell_type": "markdown",
    "id": "46e5071f",
@@ -242,7 +293,7 @@
    "name": "python",
    "nbconvert_exporter": "python",
    "pygments_lexer": "ipython3",
-   "version": "3.9.7"
+   "version": "3.8.2"
   }
  },
  "nbformat": 4,
-- 
GitLab