Spaces:
Runtime error
Runtime error
A newer version of the Gradio SDK is available:
5.49.1
π Hugging Face Spaces Deployment Guide
β Step 1: Repository is Ready!
Your code has been successfully pushed to GitHub with all the modular architecture and automatic fine-tuning features.
π Step 2: Create Hugging Face Space
Option A: Web Interface (Recommended)
- Go to https://huggingface.co/new-space
- Space Settings:
- Name:
vietnamese-sentiment-analysis(or your choice) - License: MIT (or your preferred license)
- Hardware: CPU Basic (free) or GPU T4 (for faster fine-tuning)
- Visibility: Public (free) or Private
- SDK: Gradio
- Name:
Option B: Using Git
# Clone your Hugging Face Space (replace with your space URL)
git clone https://huggingface.co/spaces/your-username/your-space-name
cd your-space-name
# Add your repository as remote
git remote add upstream https://github.com/your-username/SentimentAnalysis.git
git pull upstream main
git push origin main
π Step 3: Files to Upload
Make sure these files are in your Space:
SentimentAnalysis/
βββ app.py # β
Main application
βββ requirements.txt # β
Dependencies
βββ py/
β βββ __init__.py # β
Package
β βββ api_controller.py # β
API controller
β βββ fine_tune_sentiment.py # β
Fine-tuning script
β βββ pages/ # β
UI pages
β βββ __init__.py
β βββ single_analysis.py
β βββ batch_analysis.py
β βββ model_info.py
β βββ api_endpoints.py
βοΈ Step 4: Space Configuration
Requirements.txt Check:
Ensure your requirements.txt includes:
torch>=2.0.0
transformers>=4.21.0
datasets>=2.0.0
gradio>=4.44.1
fastapi>=0.104.0
uvicorn>=0.24.0
pydantic>=2.5.0
psutil>=5.9.0
accelerate>=0.21.0
Hardware Selection:
- CPU Basic: Free, but fine-tuning will be slow (30-60 minutes)
- GPU T4: Paid, but fine-tuning will be fast (5-10 minutes)
- GPU A10G: More expensive, best performance
π Step 5: Deployment Process
What Happens Automatically:
- Environment Detection: App detects it's running on Hugging Face Spaces
- Model Loading: Tries to load fine-tuned model, runs fine-tuning if needed
- API Server: Starts REST API on port 7861 automatically
- Gradio Interface: Launches with all 4 tabs
Expected Timeline:
- Initial Build: 2-5 minutes (installing dependencies)
- First Run: 10-30 minutes (fine-tuning, depends on hardware)
- Subsequent Runs: 1-2 minutes (model already created)
π± Step 6: Testing Your Space
Once deployed, your Space will have:
Main Interface (Main URL):
- π Single Text Analysis - Analyze individual Vietnamese texts
- π Batch Analysis - Process multiple texts
- βΉοΈ Model Information - View model details and memory usage
- π REST API Endpoints - API documentation and examples
REST API (Your Space URL + :7861):
- Interactive Docs:
https://your-space.hf.space:7861/docs - Health Check:
GET /health - Analysis:
POST /analyze - Batch:
POST /analyze/batch
π― Step 7: API Usage Examples
Python Example:
import requests
response = requests.post(
"https://your-space.hf.space:7861/analyze",
json={"text": "GiαΊ£ng viΓͺn dαΊ‘y rαΊ₯t hay vΓ tΓ’m huyαΊΏt."}
)
result = response.json()
print(f"Sentiment: {result['sentiment']}")
print(f"Confidence: {result['confidence']:.2%}")
cURL Example:
curl -X POST "https://your-space.hf.space:7861/analyze" \
-H "Content-Type: application/json" \
-d '{"text": "GiαΊ£ng viΓͺn dαΊ‘y rαΊ₯t hay vΓ tΓ’m huyαΊΏt."}'
β οΈ Step 8: Troubleshooting
Common Issues:
Build Fails:
- Check requirements.txt has all dependencies
- Ensure no syntax errors in Python files
- Check Space logs for specific error messages
Fine-Tuning Takes Too Long:
- Consider upgrading to GPU hardware
- The process will complete eventually on CPU
API Not Working:
- API runs on port 7861 (different from main Gradio port)
- Check if CORS is enabled (included in our setup)
Memory Issues:
- The app includes automatic memory cleanup
- Batch size is limited to 10 texts
- GPU spaces have more memory available
π§ Step 9: Advanced Configuration
Custom Fine-Tuned Model:
If you have your own fine-tuned model on Hugging Face Hub:
- Update line 32 in
app.py:self.finetuned_model = "your-username/your-model-name"
Custom Fine-Tuning Parameters:
Modify py/fine_tune_sentiment.py to adjust:
- Learning rate
- Number of epochs
- Batch size
- Dataset
π Step 10: Monitoring
Space Metrics:
- Usage statistics in your Space dashboard
- API endpoint performance
- Model loading time
- Memory usage (shown in Model Info tab)
π Success Indicators:
Your deployment is successful when you see:
- β Gradio interface loads with all 4 tabs
- β Model information shows "vietnamese_sentiment_finetuned"
- β
API documentation is accessible at
/docs - β Test analysis returns correct sentiment predictions
- β Health check endpoint returns status "healthy"
π Support
If you encounter issues:
- Check the Space logs for error messages
- Verify all files are uploaded correctly
- Test locally with
python app.pyfirst - Review the fine-tuning process in the logs
Your modular Vietnamese Sentiment Analysis app is now ready for production deployment! π