Code
import gradio as gr
def greet(name):
return f"Hello {name}!"
gr.Interface(greet, "textbox", "textbox").launch()Each launch cell closes one source segment and creates one embedded app. A launch cell contains the literal .launch( pattern. Two .launch() calls in one cell still create one embedded app. The filter clears the collected Python source after that cell, so the next app must define or import everything it uses.
two-apps.qmd
---
title: Two apps
filters:
- gradio
execute:
enabled: false
---
## Greeting
::: {#08adc50d .cell}
``` {.python .cell-code}
import gradio as gr
def greet(name):
return f"Hello {name}!"
gr.Interface(greet, "textbox", "textbox").launch()
```
:::
## Uppercase
::: {#990db6db .cell}
``` {.python .cell-code}
import gradio as gr
def emphasize(text):
return text.upper()
gr.Interface(emphasize, "textbox", "textbox").launch()
```
:::
Render the document and wait for both apps to start. Enter a name in the first app and text in the second. Each app responds independently because the default gives it a dedicated worker.
The live page uses shared-worker: true so both examples can reuse one Pyodide interpreter and installed package environment. Each app still receives a separate app ID, working directory, and __main__ module.
import gradio as gr
def greet(name):
return f"Hello {name}!"
gr.Interface(greet, "textbox", "textbox").launch()import gradio as gr
def emphasize(text):
return text.upper()
gr.Interface(emphasize, "textbox", "textbox").launch()Python source can span several cells before the launch cell:
split-app.qmd
::: {#b937245e .cell}
``` {.python .cell-code}
import gradio as gr
def greet(name):
return f"Hello {name}!"
```
:::
::: {#e0d7ca6a .cell}
``` {.python .cell-code}
demo = gr.Interface(greet, "textbox", "textbox")
demo.launch()
```
:::
The first cell does not create an app. Its source becomes part of the app closed by the second cell.
Put #| gr-* options on each launch cell:
#| gr-theme: light
#| gr-playground: true
#| gr-layout: vertical
demo.launch()These options apply to that app and override matching values under document-wide gradio.attributes. App requirements and runtime URLs remain document-wide.
The default worker isolation repeats Python startup for each app. Read Runtime and Trust before using shared-worker: true to share one Python environment.