or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

components.mdcore-applications.mdevents.mdexternal-integration.mdindex.mdlayouts.mdthemes.mdutilities.md

core-applications.mddocs/

0

# Core Applications

1

2

Foundation classes for building different types of Gradio applications, from simple function wrappers to complex multi-component interfaces with custom layouts and interactions.

3

4

## Capabilities

5

6

### Interface

7

8

High-level wrapper that automatically creates a web interface for a single Python function, handling input/output types, validation, and UI generation.

9

10

```python { .api }

11

class Interface:

12

def __init__(

13

self,

14

fn,

15

inputs,

16

outputs,

17

examples=None,

18

*,

19

cache_examples=None,

20

cache_mode=None,

21

examples_per_page=10,

22

example_labels=None,

23

preload_example=False,

24

live=False,

25

title=None,

26

description=None,

27

article=None,

28

theme=None,

29

flagging_mode=None,

30

flagging_options=None,

31

flagging_dir=".gradio/flagged",

32

flagging_callback=None,

33

analytics_enabled=None,

34

batch=False,

35

max_batch_size=4,

36

show_api=True,

37

api_name="predict",

38

api_description=None,

39

_api_mode=False,

40

allow_duplication=False,

41

concurrency_limit="default",

42

css=None,

43

css_paths=None,

44

js=None,

45

head=None,

46

head_paths=None,

47

additional_inputs=None,

48

additional_inputs_accordion=None,

49

submit_btn="Submit",

50

stop_btn="Stop",

51

clear_btn="Clear",

52

delete_cache=None,

53

show_progress="full",

54

fill_width=False,

55

allow_flagging=None,

56

time_limit=30,

57

stream_every=0.5,

58

deep_link=None,

59

**kwargs

60

):

61

"""

62

Create an interface for a function.

63

64

Parameters:

65

- fn: The function to create an interface for

66

- inputs: List of input components or strings

67

- outputs: List of output components or strings

68

- examples: Example inputs for the interface

69

- cache_examples: Whether to cache examples for fast runtime

70

- cache_mode: When to cache examples ("eager" or "lazy")

71

- examples_per_page: Number of examples to display per page

72

- example_labels: Custom labels for examples

73

- preload_example: Index of example to preload on startup

74

- live: Whether to run function on every input change

75

- title: Title displayed at the top of the interface

76

- description: Description displayed below the title

77

- article: Extended article content below interface

78

- theme: Theme object or string name for styling

79

- flagging_mode: Flagging behavior ("never", "auto", "manual")

80

- flagging_options: List of flagging options

81

- flagging_dir: Directory to save flagged data

82

- flagging_callback: Custom flagging callback

83

- analytics_enabled: Whether to enable analytics

84

- batch: Whether to batch process multiple inputs

85

- max_batch_size: Maximum batch size for processing

86

- show_api: Whether to show API in documentation

87

- api_name: Name for the API endpoint

88

- api_description: Description for API endpoint

89

- allow_duplication: Whether to allow duplication on HF Spaces

90

- concurrency_limit: Maximum concurrent executions

91

- css: Custom CSS string for styling

92

- css_paths: Paths to CSS files for styling

93

- js: Custom JavaScript string for functionality

94

- head: Custom HTML head content

95

- head_paths: Paths to HTML head files

96

- additional_inputs: Extra input components in accordion

97

- additional_inputs_accordion: Accordion for additional inputs

98

- submit_btn: Submit button configuration

99

- stop_btn: Stop button configuration

100

- clear_btn: Clear button configuration

101

- delete_cache: Cache deletion settings

102

- show_progress: Progress display mode ("full", "minimal", "hidden")

103

- fill_width: Whether to expand horizontally

104

- allow_flagging: Deprecated - use flagging_mode instead

105

- time_limit: Stream time limit in seconds

106

- stream_every: Stream chunk frequency in seconds

107

- deep_link: Deep linking configuration

108

"""

109

110

def launch(

111

self,

112

inline=None,

113

inbrowser=None,

114

share=None,

115

debug=None,

116

max_threads=40,

117

auth=None,

118

auth_message=None,

119

prevent_thread_lock=False,

120

show_error=False,

121

server_name=None,

122

server_port=None,

123

height=500,

124

width="100%",

125

favicon_path=None,

126

ssl_keyfile=None,

127

ssl_certfile=None,

128

ssl_keyfile_password=None,

129

ssl_verify=True,

130

quiet=False,

131

show_api=True,

132

allowed_paths=None,

133

blocked_paths=None,

134

root_path=None,

135

app_kwargs=None,

136

**kwargs

137

):

138

"""

139

Launch the interface.

140

141

Parameters:

142

- share: Whether to create a public link

143

- debug: Whether to run in debug mode

144

- auth: Authentication credentials (tuple or callable)

145

- server_name: Server hostname

146

- server_port: Server port number

147

- inbrowser: Whether to open in browser automatically

148

- show_api: Whether to show API documentation

149

- quiet: Whether to suppress output

150

"""

151

152

def integrate(self, comet_ml=None, wandb=None, mlflow=None): ...

153

def predict(self, *args, **kwargs): ...

154

def close(self): ...

155

```

156

157

Usage example:

158

159

```python

160

import gradio as gr

161

162

def classify_image(image):

163

# Image classification logic

164

return {"cat": 0.8, "dog": 0.2}

165

166

interface = gr.Interface(

167

fn=classify_image,

168

inputs=gr.Image(type="pil"),

169

outputs=gr.Label(num_top_classes=3),

170

title="Pet Classifier",

171

description="Upload an image to classify pets"

172

)

173

174

interface.launch()

175

```

176

177

### Blocks

178

179

Core application framework for creating multi-component interfaces with custom layouts, complex interactions, and full control over the user interface design.

180

181

```python { .api }

182

class Blocks:

183

def __init__(

184

self,

185

theme=None,

186

analytics_enabled=None,

187

mode="blocks",

188

title="Gradio",

189

css=None,

190

js=None,

191

head=None,

192

fill_height=False,

193

delete_cache=None,

194

**kwargs

195

):

196

"""

197

Create a Blocks interface.

198

199

Parameters:

200

- theme: Theme object or string name for styling

201

- analytics_enabled: Whether to enable analytics

202

- mode: Interface mode ("blocks" or "interface")

203

- title: Page title displayed in browser tab

204

- css: Custom CSS string for styling

205

- js: Custom JavaScript string for functionality

206

- head: Custom HTML head content

207

- fill_height: Whether to fill viewport height

208

- delete_cache: Cache deletion settings

209

"""

210

211

def __enter__(self):

212

"""Enter context manager for component definition."""

213

214

def __exit__(self, exc_type, exc_val, exc_tb):

215

"""Exit context manager."""

216

217

def launch(self, **kwargs):

218

"""Launch the Blocks interface with same parameters as Interface.launch()."""

219

220

def load(self, fn, inputs=None, outputs=None, **kwargs): ...

221

def queue(self, **kwargs): ...

222

def integrate(self, comet_ml=None, wandb=None, mlflow=None): ...

223

def close(self): ...

224

```

225

226

Usage example:

227

228

```python

229

import gradio as gr

230

231

def process_data(text, number):

232

return f"Processed: {text} x {number}"

233

234

with gr.Blocks() as demo:

235

gr.Markdown("# Data Processor")

236

237

with gr.Row():

238

with gr.Column():

239

text_input = gr.Textbox(label="Text Input")

240

num_input = gr.Number(label="Number Input")

241

submit_btn = gr.Button("Process")

242

243

with gr.Column():

244

output = gr.Textbox(label="Result")

245

246

submit_btn.click(

247

fn=process_data,

248

inputs=[text_input, num_input],

249

outputs=output

250

)

251

252

demo.launch()

253

```

254

255

### ChatInterface

256

257

Specialized interface for chat and conversation applications with built-in message history, user input handling, and conversational UI patterns.

258

259

```python { .api }

260

class ChatInterface:

261

def __init__(

262

self,

263

fn,

264

*,

265

multimodal=False,

266

type=None,

267

chatbot=None,

268

textbox=None,

269

additional_inputs=None,

270

additional_inputs_accordion=None,

271

additional_outputs=None,

272

editable=False,

273

examples=None,

274

example_labels=None,

275

example_icons=None,

276

run_examples_on_click=True,

277

cache_examples=None,

278

cache_mode=None,

279

title=None,

280

description=None,

281

theme=None,

282

flagging_mode=None,

283

flagging_options=("Like", "Dislike"),

284

flagging_dir=".gradio/flagged",

285

css=None,

286

css_paths=None,

287

js=None,

288

head=None,

289

head_paths=None,

290

analytics_enabled=None,

291

autofocus=True,

292

autoscroll=True,

293

submit_btn=True,

294

stop_btn=True,

295

concurrency_limit="default",

296

delete_cache=None,

297

show_progress="minimal",

298

fill_height=True,

299

fill_width=False,

300

api_name="chat",

301

api_description=None,

302

show_api=True,

303

save_history=False,

304

**kwargs

305

):

306

"""

307

Create a ChatInterface for conversational applications.

308

309

Parameters:

310

- fn: Function that processes messages and chat history

311

- multimodal: Whether to support text + file inputs

312

- type: Message format ("messages" or "tuples")

313

- chatbot: Custom Chatbot component instance

314

- textbox: Custom Textbox/MultimodalTextbox instance

315

- additional_inputs: Extra input components

316

- additional_inputs_accordion: Accordion for additional inputs

317

- additional_outputs: Extra output components

318

- editable: Whether users can edit past messages

319

- examples: Example messages or multimodal inputs

320

- example_labels: Labels for examples

321

- example_icons: Icons for examples

322

- run_examples_on_click: Whether examples run immediately

323

- cache_examples: Whether to cache examples

324

- cache_mode: When to cache ("eager" or "lazy")

325

- title: Interface title

326

- description: Interface description

327

- theme: Theme object or string

328

- flagging_mode: Flagging behavior ("never" or "manual")

329

- flagging_options: Available flagging options

330

- flagging_dir: Directory for flagged data

331

- css: Custom CSS string

332

- css_paths: Paths to CSS files

333

- js: Custom JavaScript

334

- head: Custom HTML head content

335

- head_paths: Paths to HTML head files

336

- analytics_enabled: Whether to enable analytics

337

- autofocus: Whether to auto-focus input

338

- autoscroll: Whether to auto-scroll to bottom

339

- submit_btn: Submit button configuration

340

- stop_btn: Stop button configuration

341

- concurrency_limit: Maximum concurrent executions

342

- delete_cache: Cache deletion settings

343

- show_progress: Progress display mode

344

- fill_height: Whether to expand vertically

345

- fill_width: Whether to expand horizontally

346

- api_name: API endpoint name

347

- api_description: API endpoint description

348

- show_api: Whether to show in API docs

349

- save_history: Whether to persist chat history

350

"""

351

352

def launch(self, **kwargs):

353

"""Launch the chat interface with same parameters as Interface.launch()."""

354

355

def queue(self, **kwargs): ...

356

def close(self): ...

357

```

358

359

The chat function should have this signature:

360

361

```python { .api }

362

def chat_fn(message: str, history: list) -> str:

363

"""

364

Chat function for ChatInterface.

365

366

Parameters:

367

- message: Current user message

368

- history: List of [user_message, bot_response] pairs

369

370

Returns:

371

- response: Bot response string

372

"""

373

```

374

375

Usage example:

376

377

```python

378

import gradio as gr

379

380

def simple_chat(message, history):

381

return f"You said: {message}"

382

383

chat = gr.ChatInterface(

384

fn=simple_chat,

385

title="Simple Chatbot",

386

description="A basic echo chatbot"

387

)

388

389

chat.launch()

390

```

391

392

### TabbedInterface

393

394

Multi-tab interface container for organizing multiple Interface instances into a single application with tabbed navigation.

395

396

```python { .api }

397

class TabbedInterface:

398

def __init__(

399

self,

400

interface_list,

401

tab_names,

402

title=None,

403

theme=None,

404

analytics_enabled=None,

405

css=None,

406

js=None,

407

**kwargs

408

):

409

"""

410

Create a tabbed interface from multiple interfaces.

411

412

Parameters:

413

- interface_list: List of Interface objects

414

- tab_names: List of strings for tab labels

415

- title: Overall title for the tabbed interface

416

- theme: Theme object or string name

417

- analytics_enabled: Whether to enable analytics

418

- css: Custom CSS string

419

- js: Custom JavaScript string

420

"""

421

422

def launch(self, **kwargs):

423

"""Launch the tabbed interface with same parameters as Interface.launch()."""

424

425

def close(self): ...

426

```

427

428

Usage example:

429

430

```python

431

import gradio as gr

432

433

def text_analyzer(text):

434

return len(text)

435

436

def image_classifier(image):

437

return "cat"

438

439

text_interface = gr.Interface(

440

fn=text_analyzer,

441

inputs="text",

442

outputs="number"

443

)

444

445

image_interface = gr.Interface(

446

fn=image_classifier,

447

inputs="image",

448

outputs="text"

449

)

450

451

tabbed = gr.TabbedInterface(

452

[text_interface, image_interface],

453

["Text Analysis", "Image Classification"],

454

title="Multi-Tool App"

455

)

456

457

tabbed.launch()

458

```

459

460

## Utility Functions

461

462

### close_all

463

464

```python { .api }

465

def close_all():

466

"""Close all running Gradio interfaces."""

467

```

468

469

## Types

470

471

```python { .api }

472

class Component:

473

"""Base class for all Gradio components."""

474

475

def __init__(self, **kwargs): ...

476

def change(self, fn, inputs=None, outputs=None, **kwargs): ...

477

def select(self, fn, inputs=None, outputs=None, **kwargs): ...

478

```