The short answer
To deploy a Gradio app, give your coding agent the sentence below. Antideploy finds Gradio in your requirements, finds the file that imports it, and runs it with python. Unlike Streamlit, Gradio is not started with extra flags, so your code must launch on 0.0.0.0 and on the port in the PORT variable. Each app has 1 GB of memory.
Say this to your coding agent
Set this project up to deploy on Antideploy. Fetch https://antideploy.com/agent.md and follow it.
What Antideploy detects
-
Gradio. Detected from
gradioinrequirements.txtorpyproject.toml. -
The entry file. It looks for
streamlit_app.py,app.py,dashboard.py,main.pyandhome.py, in that order, in the folder of your requirements. The first one that containsimport gradiowins. Otherwise it uses any.pyfile that imports Gradio. -
The start command.
python <entry file>. Nothing is added, so the launch settings are yours. -
The port. Antideploy sets
PORTand sends traffic to it.
The launch line
By default Gradio listens on 127.0.0.1, which only your own computer can reach. On a server it must listen on 0.0.0.0 and on the port Antideploy gives it.
import os
import gradio as gr
def greet(name):
return "Hello " + name
demo = gr.Interface(fn=greet, inputs="text", outputs="text")
demo.launch(
server_name="0.0.0.0",
server_port=int(os.environ.get("PORT", 7860)),
)
If your app uses gr.Blocks, the same launch call applies. Without these two arguments the deploy builds but never starts listening, and fails with a message that names the port.
Memory
An app that loads a large model into memory when it starts can run out of 1 GB and be stopped before it listens. Two ways help.
- Call a hosted model instead of loading weights, for example through an AI key that your agent creates
- If you must load a model, load it the first time it is needed, not at import time
- Pin Python to 3.12 in a
.python-versionfile if a package such astorchhas no build for a newer version
Step by step
-
Add the launch arguments
Set
server_name="0.0.0.0"and read the port fromPORT. -
Paste the sentence and approve one link
Your agent creates the app and deploys it. Keys you need, such as a model key, are saved as write-only variables.
-
Open your link
Antideploy installs your requirements, runs your file, and checks that the app answers. Your agent tells you the address.