Skip to main content
The File component allows users to upload files or display files for download.

Basic usage

import gradio as gr

def process_file(file):
    return file.name

gr.Interface(
    fn=process_file,
    inputs=gr.File(),
    outputs=gr.Textbox()
).launch()

Constructor

value
str | list[str] | Callable | None
default:"None"
Default file(s) as filepath(s) or URL(s)
file_count
Literal['single', 'multiple', 'directory']
default:"'single'"
Upload mode:
  • "single" - One file
  • "multiple" - Multiple files
  • "directory" - All files in directory
file_types
list[str] | None
default:"None"
Allowed file types. Examples:
  • ["image"] - Only images
  • [".pdf", ".docx"] - Specific extensions
  • ["video"] - Only videos
type
Literal['filepath', 'binary']
default:"'filepath'"
Return format:
  • "filepath" - String path to temporary file
  • "binary" - Bytes object
label
str | None
default:"None"
Label displayed above component
height
int | str | float | None
default:"None"
Component height (with scrollbar if needed)
interactive
bool | None
default:"None"
Whether file upload is enabled

Events

  • change - Triggered when file selection changes
  • select - Triggered when file is selected
  • clear - Triggered when files are cleared
  • upload - Triggered when file upload completes
  • delete - Triggered when file is deleted
  • download - Triggered when file is downloaded

Examples

PDF files only

import gradio as gr

def read_pdf(file):
    return f"Uploaded: {file.name}"

gr.Interface(
    fn=read_pdf,
    inputs=gr.File(file_types=[".pdf"]),
    outputs=gr.Textbox()
).launch()

Multiple files

import gradio as gr

def process_files(files):
    return [f.name for f in files]

gr.Interface(
    fn=process_files,
    inputs=gr.File(file_count="multiple"),
    outputs=gr.Textbox()
).launch()

Binary mode

import gradio as gr

def get_file_size(file_bytes):
    return f"File size: {len(file_bytes)} bytes"

gr.Interface(
    fn=get_file_size,
    inputs=gr.File(type="binary"),
    outputs=gr.Textbox()
).launch()