
AirLLM is a library, not an application, so it does not include a graphical interface. That surprises people who arrive expecting a chat window. Fortunately, building an AirLLM UI takes only a few dozen lines of Python. This guide shows a complete, practical interface built with Gradio, explains each design decision and adds features that matter specifically for large, slow models.
Why build a UI at all?
Scripts are perfect for batch jobs, but a chat page is more comfortable for exploring a model, sharing a demonstration with colleagues or letting a non-programmer use a private model running on your workstation. A web interface also makes it easy to adjust settings such as response length without editing code.
Choosing a framework
| Option | Strength | Consideration |
|---|---|---|
| Gradio | Ready-made chat component, minimal code | Styling is somewhat fixed |
| Streamlit | Flexible dashboards | Reruns the script on each interaction |
| FastAPI + custom page | Full control, API for other tools | More code to maintain |
For a first AirLLM UI, Gradio offers the best balance, so the example below uses it.
Step 1: install the pieces
pip install airllm gradio
Step 2: load the model once
Load the model at the top of the script, outside any function, so it is prepared a single time when the server starts rather than on every message.
import gradio as gr
from airllm import AutoModel
model = AutoModel.from_pretrained(
"Qwen/Qwen2.5-14B-Instruct",
compression="4bit",
layer_shards_saving_path="./shards",
)
tok = model.tokenizer
Step 3: write the reply function
def reply(message, history, max_tokens):
msgs = [{"role": "system", "content": "You are a helpful, concise assistant."}]
for turn in history:
msgs.append({"role": turn["role"], "content": turn["content"]})
msgs.append({"role": "user", "content": message})
text = tok.apply_chat_template(msgs, tokenize=False, add_generation_prompt=True)
ids = tok([text], return_tensors="pt", truncation=True,
max_length=2048)["input_ids"].cuda()
out = model.generate(ids, max_new_tokens=int(max_tokens),
use_cache=True, return_dict_in_generate=True)
return tok.decode(out.sequences[0][ids.shape[1]:], skip_special_tokens=True)
The function rebuilds the conversation from Gradio's history, formats it with the model's chat template and returns only the new text.
Step 4: create the interface
demo = gr.ChatInterface(
fn=reply,
type="messages",
title="airllm local assistant",
description="Runs entirely on this computer. Large models reply slowly.",
additional_inputs=[gr.Slider(16, 400, value=120, step=8,
label="Maximum new tokens")],
)
demo.queue(default_concurrency_limit=1).launch(server_name="127.0.0.1")
Open the address printed in the terminal, usually http://127.0.0.1:7860, and you have a working AirLLM UI.
Design choices that matter for AirLLM
One request at a time
AirLLM streams layers through a single GPU, so two simultaneous generations would compete for the same disk and memory. The queue with a concurrency limit of one ensures requests wait their turn instead of failing.
Set expectations clearly
A short description explaining that replies may take minutes prevents users from assuming the page has frozen. Gradio shows a progress indicator while the function runs.
Expose the token limit
The response length slider gives users direct control over waiting time. A default of around 120 tokens keeps replies useful without long delays.
Trim long histories
Every previous message is processed again on each turn. For long conversations, keep only the most recent exchanges or summarise older ones to keep prompts manageable.
Optional: an API for other tools
If you want other applications to use your model, wrap the same reply logic in a FastAPI endpoint. A minimal route that accepts a list of messages and returns the generated text is enough for scripts, automation tools and custom front ends. Bind it to 127.0.0.1 unless you deliberately want other devices on your network to reach it, and add authentication if you do.
Keeping your interface secure
- Leave Gradio's public share option disabled for private data.
- Do not bind to
0.0.0.0on untrusted networks. - Set
HF_HUB_OFFLINE=1after the first download so the server makes no outbound calls. - Keep the Python environment updated to receive security fixes.
Ideas for improvement
- Add a dropdown to switch between several pre-split models.
- Provide a file upload field to summarise local documents.
- Save conversations to a local folder for later review.
- Display elapsed time per reply to help users plan longer requests.
Adding a document summariser tab
A chat window is only one way to present a model. Many people get more value from a focused tool, such as a page where they paste or upload a document and receive a summary. Gradio's Blocks layout lets you combine both. Create one tab containing the chat interface and another containing a file input, a dropdown for summary length and an output box. The second tab's function reads the uploaded text, trims it to a manageable size, builds a clear instruction such as "Summarise the following in five bullet points" and returns the model's answer.
with gr.Blocks(title="airllm workspace") as app:
with gr.Tab("Chat"):
gr.ChatInterface(fn=reply, type="messages")
with gr.Tab("Summarise"):
doc = gr.Textbox(lines=12, label="Paste text")
btn = gr.Button("Summarise")
out = gr.Markdown()
btn.click(lambda t: ask("Summarise in five bullet points:\n" + t[:6000]),
inputs=doc, outputs=out)
app.queue(default_concurrency_limit=1).launch(server_name="127.0.0.1")
Showing progress during long generations
With large models, a reply can take several minutes. Users are far more patient when they can see that work is happening. Gradio displays a running timer automatically, and you can add a short status message above the output explaining the expected wait. Another useful technique is to log each completed request with its duration, then display the average time in the page description so users know what to expect before they submit.
Running the interface as a background service
If you want the interface available whenever the computer is on, run it as a service rather than from a terminal you must keep open. On Linux, a simple systemd unit can start the script at boot and restart it if it stops. On Windows, Task Scheduler can launch the script at log-on. In both cases, point the service at the Python executable inside your virtual environment so it uses the correct packages, and write logs to a file for troubleshooting.
Handle slow requests in an AirLLM interface
A local chat interface needs to tell the user when a request has been accepted. Show a short status message while the model prepares or generates. If the backend returns text only after generation completes, describe the work as in progress. A typed animation of a completed answer changes the presentation without making the first token available sooner. Measure the delay with a cold model as well as a model that has already responded.
Start with one active inference request per model instance. Two users clicking at once can create unexpected device and disk pressure. Give queued requests a visible state and prevent a double click from submitting the same message twice. When you add cancellation, test what happens while a request is waiting and while the backend is generating. Keep the current request marked as active until the backend has actually finished or stopped its work.
Choose an explicit history policy. A long conversation can consume a growing input budget, particularly when messages include documents or code. Count the formatted input with the tokenizer used by the model. Preserve the system instruction and recent turns, and make it clear when earlier turns are omitted. When a user starts a new conversation, clear that session's state and verify that previous messages are absent from the next request.
Give errors a short explanation and a specific recovery action. For a context limit, ask the user to shorten the request or start a fresh conversation. For a model loading error, surface the stage and put a diagnostic identifier in the application log. Keep private text and credentials out of logs by default. If the interface is intended for the same computer only, verify the listening address and disable public sharing. A convenient browser view can still expose data if it binds to the wrong interface.
Test the interface with a small checkpoint before connecting a larger model. Submit a message, clear it, retry a failed request and reload the browser. Then submit two requests from different sessions and check that their histories remain isolated. Measure the entire time from button click to completion, alongside the generation time reported by the backend. Their difference helps explain startup or queuing delays.
A compact set of generation controls is usually sufficient for the first version. Give the output budget a practical default and validate values before passing them to airllm. Save the application configuration and checkpoint revision together so a change in output is easier to investigate. If you introduce streaming later, rerun the same tests to confirm that incomplete responses are handled correctly and that a stopped request does not remain in the conversation as a completed answer. Keep the input available for an intentional retry.
Frequently asked questions
No. AirLLM is a Python library without an official graphical interface. You interact with it through scripts or notebooks, or you build a small web interface with a framework such as Gradio or Streamlit.
Gradio is usually the quickest. Its ChatInterface component turns a single Python function into a complete chat page with message history, and it runs locally in your browser.
Yes, as long as you keep the server bound to your own machine. Gradio listens on 127.0.0.1 by default, and the share link option should stay disabled if you want nothing exposed to the internet.
Not out of the box, because Open WebUI expects an API server. You can wrap AirLLM in a small FastAPI service that mimics an OpenAI-style endpoint, though slow generation makes this best for occasional use.
Conclusion
Although AirLLM ships without an interface, a polished AirLLM UI is only a short script away. Load the model once, use the chat template, queue requests one at a time and make waiting times clear. The result is a private, browser-based assistant powered by a model far larger than your graphics card would normally allow. To learn the underlying calls in more depth, read how to use AirLLM.


