{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# `nbgradio` Test Notebook\n", "\n", "This notebook demonstrates the `nbgradio` library with a simple Gradio app.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#nbgradio name=\"test_notebook\"\n", "# nbgradio name=\"greet\"\n", "import gradio as gr\n", "\n", "\n", "def greet(name):\n", " return f\"Hello {name}!\"\n", "\n", "\n", "demo = gr.Interface(\n", " fn=greet, inputs=gr.Textbox(label=\"Your name\"), outputs=gr.Textbox(label=\"Greeting\")\n", ")\n", "\n", "demo.launch()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Another Section\n", "\n", "The code block above used the `#nbgradio` syntax so that it is launched as a Gradio app. If you don't add that comment block, the `nbgradio` will treat it as \"regular\" code that should just be syntax highlighted:\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "def calculate_fibonacci(n):\n", " \"\"\"Calculate the nth Fibonacci number.\"\"\"\n", " if n <= 1:\n", " return n\n", " return calculate_fibonacci(n - 1) + calculate_fibonacci(n - 2)\n", "\n", "\n", "# Test the function\n", "for i in range(10):\n", " print(f\"F({i}) = {calculate_fibonacci(i)}\")" ] } ], "metadata": { "language_info": { "name": "python" } }, "nbformat": 4, "nbformat_minor": 2 }