☁️ Lesson 9.2: Deploying on Cloud (Render, Streamlit Cloud, Hugging Face Spaces)
🎯 Learning Objectives
By the end of this lesson, learners will be able to:
-
Understand the benefits of deploying AI agents on the cloud
-
Choose the right platform (Render, Streamlit Cloud, or Hugging Face Spaces) based on project needs
-
Deploy their AI application on at least one platform
-
Share a live, accessible URL with others for testing or usage
☁️ Why Deploy on the Cloud?
While local development is great for testing, cloud deployment allows you to:
-
Access your app from anywhere
-
Share your agent publicly with a link
-
Scale to handle more users
-
Avoid dependency issues across systems
Cloud platforms simplify deployment without needing your own server.
🛠️ Platforms We’ll Cover
| Platform | Best For | Free Tier Available? |
|---|---|---|
| Render | FastAPI, Flask, Node apps, APIs | ✅ Yes |
| Streamlit Cloud | Streamlit web apps (UI-based agents) | ✅ Yes |
| Hugging Face Spaces | ML demos (Gradio, Streamlit apps) | ✅ Yes |
🔷 1. Deploying on Render (for FastAPI / Flask / API apps)
✅ Step-by-Step
-
Push your code to GitHub
-
Go to https://render.com and create an account
-
Click “New Web Service”
-
Connect your GitHub repo
-
Fill in deployment settings:
| Setting | Example Value |
|---|---|
| Build Command | pip install -r requirements.txt |
| Start Command | uvicorn app:app --host 0.0.0.0 --port 10000 |
| Runtime | Python 3.x |
-
Click Deploy
🌍 Output
You’ll get a public URL like:https://my-ai-agent.onrender.com
🔶 2. Deploying on Streamlit Cloud (for Streamlit apps)
✅ Step-by-Step
-
Build your app using
streamlit(e.g.,streamlit_app.py) -
Push code to GitHub
-
Go to https://streamlit.io/cloud
(Sign in with GitHub) -
Click “New app”
-
Select the GitHub repo and specify:
| Setting | Example |
|---|---|
| Main file path | streamlit_app.py |
| Branch | main |
| App name | ai-chat-agent |
-
Click Deploy
🌍 Output
You’ll get a live app link like:https://ai-chat-agent.streamlit.app
🟪 3. Deploying on Hugging Face Spaces (for Gradio or Streamlit apps)
✅ Step-by-Step
-
Click “Create New Space”
-
Choose:
-
Gradio or Streamlit as the SDK
-
Name your space (e.g.,
my-ai-agent) -
Set visibility (Public/Private)
-
-
Click Create Space
-
Upload your files via GitHub clone or drag-and-drop:
Example app.py (Gradio):
import gradio as gr
def respond(msg):
return "You said: " + msg
iface = gr.Interface(fn=respond, inputs="text", outputs="text")
iface.launch()
-
Add
requirements.txt:
gradio
🌍 Output
You’ll get a hosted demo like:https://huggingface.co/spaces/yourname/my-ai-agent
🧠 Platform Comparison
| Feature | Render | Streamlit Cloud | Hugging Face Spaces |
|---|---|---|---|
| API support | ✅ Yes | ❌ Streamlit only | ❌ Streamlit/Gradio only |
| UI-based apps | ❌ | ✅ Yes | ✅ Yes |
| Custom domains | ✅ Paid only | ❌ | ✅ (Pro plans) |
| Community discovery | ❌ | ❌ | ✅ (Featured Spaces) |
| Model hosting | ❌ | ❌ | ✅ Yes (transformers) |
🧪 Tips & Troubleshooting
| Problem | Solution |
|---|---|
| App crashes on load | Check log panel or review dependencies |
| Port not working | Use the default port 8501 (Streamlit) or 7860 (Gradio) |
| App doesn’t respond | Ensure you’re not using localhost in code |
| Slow loading | Optimize large models or load lazily |
📝 Assignment
Deploy your AI agent on one of the three platforms. Share the link and a screenshot in the project submission area.
🧩 Summary
| Step | Description |
|---|---|
| Choose a platform | Based on your app type (API or UI) |
| Push to GitHub | Required by most cloud services |
| Set config and deploy | Define file paths, ports, and commands |
| Share the link | Celebrate! Your agent is live |
57
