Spaces:
No application file
No application file
Hugging Face Deployment Guide
Quick Start Deployment Steps
1. Create a Hugging Face Account
- Go to huggingface.co and sign up if you haven't already
2. Create a New Space
- Click on your profile picture β "New Space"
- Give your Space a name (e.g., "springboot-demo")
- Select Docker as the SDK (important!)
- Choose the hardware (free CPU Basic is fine for this demo)
- Set visibility (public or private)
- Click "Create Space"
3. Upload Your Files
You have two options:
Option A: Using Git
# Clone your Space repository
git clone https://huggingface.co/spaces/YOUR_USERNAME/YOUR_SPACE_NAME
# Copy all the Spring Boot files to the cloned repository
cp -r springboot-app/* YOUR_SPACE_NAME/
# Navigate to the repository
cd YOUR_SPACE_NAME
# Add, commit, and push
git add .
git commit -m "Initial Spring Boot application"
git push
Option B: Using Web Interface
- Go to your Space's "Files" tab
- Click "Add file" β "Upload files"
- Upload the following structure:
Dockerfile pom.xml src/ βββ main/ β βββ java/com/example/demo/ β β βββ DemoApplication.java β β βββ controller/GreetingController.java β βββ resources/ β βββ application.properties βββ test/java/com/example/demo/ βββ DemoApplicationTests.java
4. Wait for Build and Deployment
- Hugging Face will automatically detect the Dockerfile and start building
- You can monitor the build logs in the "Logs" tab
- The build typically takes 3-5 minutes
5. Access Your Application
Once deployed, your application will be available at:
https://YOUR_USERNAME-YOUR_SPACE_NAME.hf.space/api/
Testing Your Endpoints
Once deployed, you can test your API endpoints:
# Test the home endpoint
curl https://YOUR_USERNAME-YOUR_SPACE_NAME.hf.space/api/
# Test the greeting endpoint
curl https://YOUR_USERNAME-YOUR_SPACE_NAME.hf.space/api/greeting?name=HuggingFace
# Test the health endpoint
curl https://YOUR_USERNAME-YOUR_SPACE_NAME.hf.space/api/health
# Test the echo endpoint
curl -X POST https://YOUR_USERNAME-YOUR_SPACE_NAME.hf.space/api/echo \
-H "Content-Type: application/json" \
-d '{"message":"Hello from Hugging Face!"}'
Troubleshooting
Common Issues and Solutions
Port Configuration Error
- Ensure
server.port=7860in application.properties - Hugging Face requires port 7860
- Ensure
Build Fails
- Check the Dockerfile syntax
- Ensure all file paths are correct
- Verify Java version compatibility
Application Doesn't Start
- Check logs in the "Logs" tab
- Verify the JAR file name in Dockerfile matches the build output
- Ensure proper permissions (running as non-root user)
Slow Response Times
- Free tier hardware has limited resources
- Consider upgrading to better hardware if needed
Environment Variables (Optional)
You can add environment variables in the Space settings:
- Go to Settings β "Repository secrets"
- Add variables like:
SPRING_PROFILES_ACTIVE=productionJAVA_OPTS=-Xmx512m
Updating Your Application
To update your deployed application:
- Make changes to your code locally
- Push updates to the Space repository
- Hugging Face will automatically rebuild and redeploy
Additional Resources
Support
If you encounter issues:
- Check the Space logs first
- Visit Hugging Face forums
- Check Spring Boot community resources