|

How to Host Your AI App for Free: Deploying Gradio to Hugging Face Spaces

3D isometric illustration of a small Gradio app being deployed via a rocket path to the Hugging Face Spaces cloud platform, symbolizing free hosting.

We built a Gradio app to demo our AI models. But it only ran on your local computer (localhost) so How do you show it to a client, a friend, or a recruiter? To make your app accessible online, you’ll need to learn about Hugging Face Spaces Deployment.

Hugging Face Spaces Is a free hosting platform specifically for machine learning demos.

Step 1: Create a Space

  1. Go to huggingface.co/spaces.
  2. Click “Create new Space”.
  3. Name: my-sentiment-analyzer.
  4. SDK: Select Gradio.
  5. Hardware: Select CPU basic (free).
  6. Click “Create Space”.

Step 2: The Files

You need to upload two files to this new Space (you can do this via the web interface or Git).

File 1: requirements.txt Tell Hugging Face what libraries to install.

transformers
torch

File 2: app.py This is your standard Gradio code.

import gradio as gr
from transformers import pipeline

# Load the pipeline
classifier = pipeline("sentiment-analysis")

def analyze(text):
    return classifier(text)[0]['label']

# Create the interface
iface = gr.Interface(fn=analyze, inputs="text", outputs="text")

# Important: Do NOT use iface.launch(). Just define the variable.
iface.launch()

Step 3: Commit and Run

Once you “Commit” these files, Hugging Face will automatically:

  1. Build a container.
  2. Install your requirements.
  3. Launch your app.

In about 2 minutes, your app will be live at https://huggingface.co/spaces/YourUsername/my-sentiment-analyzer!


Key Takeaways

  • You can showcase your Gradio app using Hugging Face Spaces, a free platform for machine learning demos.
  • To create a Space, visit huggingface.co/spaces and click ‘Create new Space’.
  • Name your Space ‘my-sentiment-analyzer’, choose Gradio SDK, and select ‘CPU basic (free)’.
  • Upload two essential files: ‘requirements.txt’ for libraries and ‘app.py’ for your Gradio code.
  • Once you commit the files, Hugging Face will build the container, install dependencies, and launch your app live.

Similar Posts

Leave a Reply