Deploy your sentiment analysis model as an interactive demo on HuggingFace Spaces using Gradio.
Live Demo: HuggingFace Spaces
These files must be in your Space's root directory:
- app.py - Gradio application
- requirements.txt - All dependencies
- README.md - Space description (optional)
- Fork this repository
- Create a new Space on HuggingFace
- Connect your GitHub repository
- The Space auto-deploys on every push
- Go to your Space on HuggingFace
- Click "Files and versions" → "Add file"
- Upload
app.pyandrequirements.txt - The Space builds automatically
Your requirements.txt must include:
gradio==4.19.0
plotly==5.18.0
transformers==4.53.0
torch==2.8.0
sentencepiece==0.1.99Set these in Space Settings → Variables and secrets:
- HF_TOKEN (optional): Required for private models
- MODEL_NAME (optional): Defaults to
IberaSoft/customer-sentiment-analyzer
If you encounter "model not recognized" errors, the model repository is missing model_type in config.json.
# Get HuggingFace token from: https://huggingface.co/settings/tokens
export HF_TOKEN="your_token_here"
python scripts/fix_model_repo.py \
--model-id IberaSoft/customer-sentiment-analyzerThis adds the missing model_type and tokenizer files to your model repository.
Cause: Missing dependency in requirements.txt
Fix: Verify all required packages are listed and restart the Space
Cause: Missing model_type or tokenizer files
Fix: Run the fix_model_repo.py script (see above)
Cause: Using deprecated Gradio decorator
Fix: Remove @gr.cache from your code (not available in Gradio 4.x)
git push origin mainThe Space auto-updates within a few minutes.
- Go to your Space → "Files and versions"
- Click on the file to edit
- Make changes and commit
- Space rebuilds automatically
Before deploying, test your Gradio app locally:
pip install -r requirements.txt
python app.pyVisit http://localhost:7860 to test the interface.
After deployment:
- Space loads without errors
- Model loads successfully (check build logs)
- Can input text and receive predictions
- Confidence scores display correctly
Space stuck building: Check logs for missing dependencies or syntax errors
Model not found: Verify model is public or HF_TOKEN is set correctly
Gradio version conflicts: Ensure you're using Gradio 4.19.0 or newer