$ show gradio-app/gradio
Gradio is a full-stack Python library and web framework for rapidly creating interactive web UIs for machine learning models, APIs, or any Python function. It provides a high-level Interface class for simple demos, a flexible Blocks API for custom layouts and event-driven apps, and a ChatInterface for chatbot applications. The backend is built on FastAPI and Uvicorn, serving both a REST API and WebSocket-based streaming. The frontend is a Svelte 5 / TypeScript application with per-component packages, a SvelteKit SSR app, and a standalone SPA that can be embedded via a custom HTML element. The library includes a rich component library (30+ input/output widgets), layout primitives (Row, Column, Tabs, Accordion, Sidebar), theming support, internationalization, and a CLI for development, deployment, and custom component creation. It also provides official Python and JavaScript client libraries for programmatic access to Gradio apps, and supports MCP (Model Context Protocol) for tool/resource integration. The repository contains over 100 runnable demos covering a wide range of ML use cases (image classification, text generation, speech recognition, object detection, chatbots, etc.), many of which integrate with Hugging Face models and datasets. While primarily an application framework, the extensive demo collection and focus on ML model visualization give it a secondary data/research character.
The LLM identified 5 files worth highlighting for reuse:
Provides a robust caching system with a @cache decorator that supports synchronous and asynchronous functions, generators, and per-session caches. The Cache class manages memory/entry eviction, hashing of complex objects (numpy arrays, PIL images, pandas DataFrames), and manual cache control. This is a self-contained, well-documented utility that could be extracted and reused in any Python project requiring deterministic function caching.
Implements per-session state management with configurable TTL (time-to-live), delete callbacks, and deep-copy semantics. The StateHolder class stores arbitrary Python objects keyed by session ID and automatically evicts stale entries. This pattern is reusable for any web application needing server-side session state with expiration.
A defensive iframe auto-resizer that implements a state machine with circuit breakers to prevent feedback loops when resizing embedded Gradio apps. It handles edge cases like scrollbar-induced growth and uses exponential backoff. This is a well-crafted, isolated utility that could be reused in any project requiring responsive iframe embedding.
Implements Server-Sent Events (SSE) streaming with JSON-diff application for incremental output updates. It handles connection management, reconnection, and efficient partial updates. This pattern is reusable for any JavaScript client that needs to consume streaming API responses with minimal overhead.
The base theme class that defines a design token system with parameters for hue, spacing, radius, text scale, and font. It generates CSS custom properties and supports inheritance for creating custom themes. This is a clean, extensible theming pattern that could be adapted for any web framework needing a token-based design system.