⚡ Advanced Grid & Layout Architecture
Structuring complex web applications requires precise alignment control. Gradio's layout components allow you to build multi-column sidebars, tabbed application suites, responsive form grids, and collapsible panels without writing custom CSS.
Example 1: Equal-Width Two-Column Layout (`gr.Row` & `gr.Column`)
Splits the application viewport into two symmetrical side-by-side work areas.
Python (layout_ex1.py)
import gradio as gr
with gr.Blocks() as demo:
gr.Markdown("## Two-Column Comparison Tool")
with gr.Row():
with gr.Column():
gr.Markdown("### Original Content")
txt1 = gr.Textbox(label="Source Text", lines=5)
with gr.Column():
gr.Markdown("### Processed Output")
txt2 = gr.Textbox(label="Result Text", lines=5)
if __name__ == "__main__":
demo.launch()
🖥️ Live Web UI Visual Output Preview
## Two-Column Comparison Tool
### Original Content
Source Text Box (5 lines high)
### Processed Output
Result Text Box (5 lines high)
Example 2: Weighted Column Scaling (`scale` parameter)
Allocates asymmetrical widths (e.g., 1:3 ratio) for sidebars and main content panels.
Python (layout_ex2.py)
import gradio as gr
with gr.Blocks() as demo:
gr.Markdown("## Application with Sidebar")
with gr.Row():
with gr.Column(scale=1):
gr.Markdown("### Sidebar Controls")
slider = gr.Slider(1, 10, label="Parameter")
btn = gr.Button("Apply", variant="primary")
with gr.Column(scale=3):
gr.Markdown("### Main Workspace Canvas")
output_plot = gr.Plot(label="Visualization Preview")
if __name__ == "__main__":
demo.launch()
🖥️ Live Web UI Visual Output Preview
## Application with Sidebar
### Sidebar Controls
Slider: [---●-----] (scale=1)
### Main Workspace Canvas
📊 Visualization Preview Canvas (scale=3)
Example 3: Multi-Tabbed Application Suite (`gr.Tabs` & `gr.Tab`)
Organizes distinct AI tools (Vision, Audio, Text) into isolated navigation tabs.
Python (layout_ex3.py)
import gradio as gr
with gr.Blocks() as demo:
gr.Markdown("# Nikita-Infotech Multi-Tool Suite")
with gr.Tabs():
with gr.Tab("🖼️ Computer Vision"):
gr.Image(label="Upload Image")
gr.Button("Detect Objects")
with gr.Tab("🎙️ Audio Processing"):
gr.Audio(label="Record Speech")
gr.Button("Transcribe Audio")
with gr.Tab("💬 LLM Chat"):
gr.Chatbot(label="Chat Window")
if __name__ == "__main__":
demo.launch()
🖥️ Live Web UI Visual Output Preview
# Nikita-Infotech Multi-Tool Suite
🖼️ Computer Vision
🎙️ Audio Processing
💬 LLM Chat
Upload Image
Drag and Drop Image Here
Example 4: Nested Layouts (Rows Inside Columns)
Combines vertical columns with internal horizontal rows for complex grid alignment.
Python (layout_ex4.py)
import gradio as gr
with gr.Blocks() as demo:
gr.Markdown("## Nested Grid Layout")
with gr.Row():
with gr.Column():
gr.Textbox(label="Left Column Top")
with gr.Row():
gr.Button("Action A")
gr.Button("Action B")
with gr.Column():
gr.Textbox(label="Right Column Full Height", lines=4)
if __name__ == "__main__":
demo.launch()
🖥️ Live Web UI Visual Output Preview
## Nested Grid Layout
Left Column Top
Input Text
Right Column Full Height
Spanning full column height box
Example 5: Collapsible Accordion Panels (`gr.Accordion`)
Creates toggleable collapsible sections to keep advanced configuration options organized.
Python (layout_ex5.py)
import gradio as gr
with gr.Blocks() as demo:
gr.Markdown("### Model Configuration Panel")
prompt = gr.Textbox(label="Prompt Input")
with gr.Accordion("Advanced Hyperparameters", open=False):
temperature = gr.Slider(0.0, 1.0, value=0.7, label="Temperature")
top_p = gr.Slider(0.0, 1.0, value=0.9, label="Top-p Sampling")
max_tokens = gr.Number(value=512, label="Max Tokens")
gr.Button("Run Inference", variant="primary")
if __name__ == "__main__":
demo.launch()
🖥️ Live Web UI Visual Output Preview
### Model Configuration Panel
Prompt Input Box
▼ Advanced Hyperparameters [Collapsed by Default]
Example 6: Fixed-Width Compact Layout (`min_width`)
Forces specific column sizing constraints for compact input forms.
Python (layout_ex6.py)
import gradio as gr
with gr.Blocks() as demo:
gr.Markdown("### Compact Login Form")
with gr.Row():
with gr.Column(min_width=200):
user = gr.Textbox(label="Username")
with gr.Column(min_width=200):
pwd = gr.Textbox(label="Password", type="password")
with gr.Column(min_width=100):
btn = gr.Button("Login")
if __name__ == "__main__":
demo.launch()
🖥️ Live Web UI Visual Output Preview
### Compact Login Form
Username Box
Password Box
Example 7: Full-Height Chat Interface Layout
Structures an immersive chat layout with a fixed header, scrollable chat window, and bottom input bar.
Python (layout_ex7.py)
import gradio as gr
with gr.Blocks() as demo:
gr.Markdown("🤖 Nikita AI Chatbot Suite
")
chatbot = gr.Chatbot(label="Chat History", height=400)
with gr.Row():
txt = gr.Textbox(show_label=False, placeholder="Type a message...", container=False)
submit_btn = gr.Button("Send", scale=0)
if __name__ == "__main__":
demo.launch()
🖥️ Live Web UI Visual Output Preview
🤖 Nikita AI Chatbot Suite
Chat History Display Area (400px height)
Type a message...
Example 8: Responsive Grid of Cards (`gr.Row` wrapping multiple columns)
Displays multiple preview cards or statistical metrics side-by-side in a responsive grid.
Python (layout_ex8.py)
import gradio as gr
with gr.Blocks() as demo:
gr.Markdown("### System Performance Metrics")
with gr.Row():
with gr.Column():
gr.Number(value=99.9, label="Uptime (%)")
with gr.Column():
gr.Number(value=45, label="Active Users")
with gr.Column():
gr.Number(value=12, label="GPU Load (%)")
if __name__ == "__main__":
demo.launch()
🖥️ Live Web UI Visual Output Preview
### System Performance Metrics
Uptime (%)
99.9
Active Users
45
GPU Load (%)
12
Example 9: Sticky Footer & Header Layout Structure
Applies professional branding headers and footers wrapping the main workspace blocks.
Python (layout_ex9.py)
import gradio as gr
with gr.Blocks() as demo:
gr.Markdown("Nikita Infotech Portal Header
")
with gr.Column():
gr.Textbox(label="Search Database")
gr.Button("Execute Query", variant="primary")
gr.Markdown("
© 2026 Nikita Infotech | All Rights Reserved
")
if __name__ == "__main__":
demo.launch()
🖥️ Live Web UI Visual Output Preview
Nikita Infotech Portal Header Banner
Search Database
© 2026 Nikita Infotech | All Rights Reserved
Example 10: Multi-Panel Master-Detail Layout
Implements a master-detail dashboard with a list selector panel on the left and detail view on the right.
Python (layout_ex10.py)
import gradio as gr
with gr.Blocks() as demo:
gr.Markdown("## Master-Detail Record Inspector")
with gr.Row():
with gr.Column(scale=1):
gr.Markdown("### Record List")
record_list = gr.Radio(["Record #001", "Record #002", "Record #003"], label="Select Item", value="Record #001")
with gr.Column(scale=3):
gr.Markdown("### Detail Inspection View")
detail_box = gr.Textbox(label="Record Metadata & History", lines=6, value="Details for Record #001...")
record_list.change(lambda x: f"Detailed inspection data loaded for {x}.", record_list, detail_box)
if __name__ == "__main__":
demo.launch()
🖥️ Live Web UI Visual Output Preview
## Master-Detail Record Inspector
### Record List
◉ Record #001
○ Record #002
○ Record #003
○ Record #002
○ Record #003
### Detail Inspection View
Details for Record #001 loaded successfully...