Spaces:
Running
Running
File size: 1,849 Bytes
adc9dea |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
{
"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
} |