Save your trained model, write a Streamlit app that loads it and shows the prediction, push the files to GitHub and deploy the repository on Streamlit Community Cloud, which is free. Keep large weights on the Hugging Face Hub. Hugging Face Spaces changed in 2026: static Spaces are free, but Gradio and Docker Spaces need a paid plan apart from up to two ZeroGPU Spaces.
Tools you need
The 10 steps
Save the model
For scikit-learn, joblib.dump(model, 'model.joblib'). For PyTorch, save the state dict and keep the model class in a file. GitHub rejects files over 100 MB, so larger weights go on the Hugging Face Hub (step 7).
Write the Streamlit app
Create app.py:
import streamlit as st, joblib
@st.cache_resource
def load():
return joblib.load('model.joblib')
model = load()
st.title('Spam classifier')
text = st.text_area('Message')
if st.button('Predict') and text:
proba = model.predict_proba([text])[0]
st.write('Prediction:', model.predict([text])[0])
st.write('Confidence:', round(float(max(proba)), 2))The cache keeps the model in memory instead of reloading it on every click.
List dependencies
Create requirements.txt with streamlit, scikit-learn, joblib and anything else you import, with versions pinned to match your machine.
Run it locally
pip install -r requirements.txt
streamlit run app.pyOpen the local address and test a few inputs, including an empty one.
Push to GitHub
Create a repository with app.py, requirements.txt, the model file (if small) and a README. Commit and push.
Deploy on Streamlit Community Cloud
Sign in at Streamlit Community Cloud with your GitHub account, choose Create app, pick the repository, branch and app.py, and deploy. Streamlit's documentation says Community Cloud is free and connects to public or private repositories. Check its limits page before you rely on it.
Keep large weights on the Hugging Face Hub
Upload big model files to a model repository on the Hugging Face Hub and download them when the app starts with huggingface_hub. Store any tokens in the app's secrets settings, never in the code.
Check the logs
If the app fails to start, open its logs. The cause is almost always a missing package, a version mismatch or a wrong file path.
Write the model card
In the README, explain what the model does, the data, the metric on a held-out set and known failure cases. Add a few example inputs people can paste.
Link it and keep it honest
Add the URL to your project README, portfolio and resume bullet. Show confidence, and state the limits; reviewers trust a demo that admits what it cannot do.
Make it yours
- An image classifier with
st.file_uploader. - A side-by-side comparison of two models.
- The same model as a Gradio app on a Hugging Face ZeroGPU Space: free personal accounts in good standing can host up to two.
- A free static Hugging Face Space that works as a portfolio page linking to your demos.
Troubleshooting
| Problem | Fix |
|---|---|
| Build fails on a package | Pin versions that match your local environment and check the Python version. |
| Model file is too large | Put it on the Hugging Face Hub and download it at start-up. |
| The app is slow on the first visit | Free apps can go to sleep when unused and take a moment to wake. That is normal. |
| Hugging Face asks me to pay when I create a Gradio Space | Gradio and Docker Spaces now need a paid plan (PRO) to create, apart from up to two ZeroGPU Spaces. Use Streamlit Community Cloud or a static Space instead. |
Frequently asked questions
Is Hugging Face Spaces free?
Static Spaces are free. Gradio and Docker Spaces need a paid plan to create, such as PRO, except that free personal accounts in good standing can host up to two Gradio Spaces on ZeroGPU.
Gradio or Streamlit?
Gradio is quicker for model input and output demos; Streamlit is better for dashboards and multi-step apps, and it deploys free on Streamlit Community Cloud.
Can I host an LLM app this way?
Yes, if it calls an API, with the key stored in secrets. Running a large model yourself needs GPU hardware, which is paid.
Learn this with mentors
AI and machine learning programmes with admissions open: live classes, mentors and project work.







