corrections
Browse files- .gitignore +37 -40
- DEPLOYMENT.md +204 -0
- Dockerfile +8 -7
- index/jersey_index.faiss +3 -0
- requirements.txt +8 -4
- test_server.py +110 -0
- upload_to_hf.py +85 -0
.gitignore
CHANGED
|
@@ -1,54 +1,51 @@
|
|
| 1 |
-
# Logs
|
| 2 |
-
logs
|
| 3 |
-
*.log
|
| 4 |
-
npm-debug.log*
|
| 5 |
-
yarn-debug.log*
|
| 6 |
-
yarn-error.log*
|
| 7 |
-
pnpm-debug.log*
|
| 8 |
-
lerna-debug.log*
|
| 9 |
-
|
| 10 |
-
node_modules
|
| 11 |
-
dist
|
| 12 |
-
dist-ssr
|
| 13 |
-
*.local
|
| 14 |
-
|
| 15 |
-
# Editor directories and files
|
| 16 |
-
.vscode/*
|
| 17 |
-
!.vscode/extensions.json
|
| 18 |
-
.idea
|
| 19 |
-
.DS_Store
|
| 20 |
-
*.suo
|
| 21 |
-
*.ntvs*
|
| 22 |
-
*.njsproj
|
| 23 |
-
*.sln
|
| 24 |
-
*.sw?
|
| 25 |
-
|
| 26 |
# Python
|
| 27 |
__pycache__/
|
| 28 |
*.py[cod]
|
| 29 |
*$py.class
|
| 30 |
*.so
|
| 31 |
.Python
|
| 32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
venv/
|
|
|
|
| 34 |
ENV/
|
| 35 |
-
env.bak/
|
| 36 |
-
venv.bak/
|
| 37 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
|
| 39 |
-
#
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
*.temp
|
| 43 |
|
|
|
|
|
|
|
| 44 |
|
|
|
|
|
|
|
| 45 |
|
| 46 |
-
#
|
| 47 |
-
|
|
|
|
| 48 |
|
| 49 |
-
#
|
| 50 |
-
.
|
| 51 |
-
.
|
| 52 |
-
.env.development.local
|
| 53 |
-
.env.test.local
|
| 54 |
-
.env.production.local
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
# Python
|
| 2 |
__pycache__/
|
| 3 |
*.py[cod]
|
| 4 |
*$py.class
|
| 5 |
*.so
|
| 6 |
.Python
|
| 7 |
+
build/
|
| 8 |
+
develop-eggs/
|
| 9 |
+
dist/
|
| 10 |
+
downloads/
|
| 11 |
+
eggs/
|
| 12 |
+
.eggs/
|
| 13 |
+
lib/
|
| 14 |
+
lib64/
|
| 15 |
+
parts/
|
| 16 |
+
sdist/
|
| 17 |
+
var/
|
| 18 |
+
wheels/
|
| 19 |
+
*.egg-info/
|
| 20 |
+
.installed.cfg
|
| 21 |
+
*.egg
|
| 22 |
+
MANIFEST
|
| 23 |
+
|
| 24 |
+
# Virtual environments
|
| 25 |
venv/
|
| 26 |
+
env/
|
| 27 |
ENV/
|
|
|
|
|
|
|
| 28 |
|
| 29 |
+
# IDE
|
| 30 |
+
.vscode/
|
| 31 |
+
.idea/
|
| 32 |
+
*.swp
|
| 33 |
+
*.swo
|
| 34 |
|
| 35 |
+
# OS
|
| 36 |
+
.DS_Store
|
| 37 |
+
Thumbs.db
|
|
|
|
| 38 |
|
| 39 |
+
# Logs
|
| 40 |
+
*.log
|
| 41 |
|
| 42 |
+
# Model files (if too large)
|
| 43 |
+
# models/*.pt
|
| 44 |
|
| 45 |
+
# Data files (if too large)
|
| 46 |
+
# index/*.faiss
|
| 47 |
+
# index/*.npy
|
| 48 |
|
| 49 |
+
# Temporary files
|
| 50 |
+
*.tmp
|
| 51 |
+
*.temp
|
|
|
|
|
|
|
|
|
DEPLOYMENT.md
ADDED
|
@@ -0,0 +1,204 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# π Deploying Devam Jersey Server to Hugging Face Spaces
|
| 2 |
+
|
| 3 |
+
This guide will help you deploy your jersey similarity detection server to Hugging Face Spaces.
|
| 4 |
+
|
| 5 |
+
## π Prerequisites
|
| 6 |
+
|
| 7 |
+
1. **Hugging Face Account**: Sign up at [huggingface.co](https://huggingface.co)
|
| 8 |
+
2. **Git**: Ensure git is installed and configured
|
| 9 |
+
3. **Python Environment**: Python 3.9+ with pip
|
| 10 |
+
|
| 11 |
+
## π― Quick Start
|
| 12 |
+
|
| 13 |
+
### Option 1: Web Interface (Recommended)
|
| 14 |
+
|
| 15 |
+
1. **Go to Hugging Face Spaces**
|
| 16 |
+
- Visit [https://huggingface.co/spaces](https://huggingface.co/spaces)
|
| 17 |
+
- Click "Create new Space"
|
| 18 |
+
|
| 19 |
+
2. **Configure Your Space**
|
| 20 |
+
- **Owner**: Your username
|
| 21 |
+
- **Space name**: `devam-jersey-server` (or your preferred name)
|
| 22 |
+
- **SDK**: Select **Docker**
|
| 23 |
+
- **License**: Choose appropriate license
|
| 24 |
+
- **Visibility**: Public or Private
|
| 25 |
+
- Click "Create Space"
|
| 26 |
+
|
| 27 |
+
3. **Upload Your Files**
|
| 28 |
+
- In your new space, click "Files and versions"
|
| 29 |
+
- Upload all project files:
|
| 30 |
+
- `inference_server.py`
|
| 31 |
+
- `requirements.txt`
|
| 32 |
+
- `Dockerfile`
|
| 33 |
+
- `README.md`
|
| 34 |
+
- `models/deepfashion2_yolov8s-seg.pt`
|
| 35 |
+
- `index/jersey_metadata.npy`
|
| 36 |
+
- Any other necessary files
|
| 37 |
+
|
| 38 |
+
4. **Monitor Build**
|
| 39 |
+
- Go to "Settings" β "Build logs"
|
| 40 |
+
- Wait for the Docker build to complete
|
| 41 |
+
- Your API will be available at `https://YOUR_USERNAME-devam-jersey-server.hf.space`
|
| 42 |
+
|
| 43 |
+
### Option 2: Git Clone Method
|
| 44 |
+
|
| 45 |
+
1. **Clone the Created Space**
|
| 46 |
+
```bash
|
| 47 |
+
git clone https://huggingface.co/spaces/YOUR_USERNAME/devam-jersey-server
|
| 48 |
+
cd devam-jersey-server
|
| 49 |
+
```
|
| 50 |
+
|
| 51 |
+
2. **Copy Your Project Files**
|
| 52 |
+
```bash
|
| 53 |
+
# Copy all your project files to this directory
|
| 54 |
+
cp -r /path/to/your/project/* .
|
| 55 |
+
```
|
| 56 |
+
|
| 57 |
+
3. **Commit and Push**
|
| 58 |
+
```bash
|
| 59 |
+
git add .
|
| 60 |
+
git commit -m "Initial upload of Devam Jersey Server"
|
| 61 |
+
git push
|
| 62 |
+
```
|
| 63 |
+
|
| 64 |
+
### Option 3: CLI Method
|
| 65 |
+
|
| 66 |
+
1. **Install huggingface_hub**
|
| 67 |
+
```bash
|
| 68 |
+
pip install huggingface_hub
|
| 69 |
+
```
|
| 70 |
+
|
| 71 |
+
2. **Create Space via CLI**
|
| 72 |
+
```bash
|
| 73 |
+
huggingface-cli repo create devam-jersey-server --type space --space-sdk docker
|
| 74 |
+
```
|
| 75 |
+
|
| 76 |
+
3. **Clone and Upload**
|
| 77 |
+
```bash
|
| 78 |
+
git clone https://huggingface.co/spaces/YOUR_USERNAME/devam-jersey-server
|
| 79 |
+
cd devam-jersey-server
|
| 80 |
+
# Copy files and push as in Option 2
|
| 81 |
+
```
|
| 82 |
+
|
| 83 |
+
## π§ Configuration
|
| 84 |
+
|
| 85 |
+
### Environment Variables (Optional)
|
| 86 |
+
|
| 87 |
+
In your Space settings, you can add environment variables:
|
| 88 |
+
|
| 89 |
+
- `MODEL_PATH`: Path to your YOLO model
|
| 90 |
+
- `INDEX_PATH`: Path to your FAISS index
|
| 91 |
+
- `DEVICE`: `cuda` or `cpu`
|
| 92 |
+
|
| 93 |
+
### Hardware Requirements
|
| 94 |
+
|
| 95 |
+
- **CPU**: Basic CPU is sufficient for testing
|
| 96 |
+
- **GPU**: For production use, consider upgrading to GPU-enabled space
|
| 97 |
+
- **Memory**: At least 4GB RAM recommended
|
| 98 |
+
|
| 99 |
+
## π§ͺ Testing Your Deployment
|
| 100 |
+
|
| 101 |
+
### 1. Check Space Status
|
| 102 |
+
- Visit your space URL
|
| 103 |
+
- Check the "Logs" tab for any errors
|
| 104 |
+
- Verify the API is responding
|
| 105 |
+
|
| 106 |
+
### 2. Test Endpoints
|
| 107 |
+
```bash
|
| 108 |
+
# Test root endpoint
|
| 109 |
+
curl https://YOUR_USERNAME-devam-jersey-server.hf.space/
|
| 110 |
+
|
| 111 |
+
# Test DINO endpoint (upload an image)
|
| 112 |
+
curl -X POST https://YOUR_USERNAME-devam-jersey-server.hf.space/dino \
|
| 113 |
+
-F "file=@test_image.jpg"
|
| 114 |
+
|
| 115 |
+
# Test FAISS endpoint
|
| 116 |
+
curl -X POST https://YOUR_USERNAME-devam-jersey-server.hf.space/faiss \
|
| 117 |
+
-H "Content-Type: application/json" \
|
| 118 |
+
-d '{"features": [0.1, 0.2, ...]}'
|
| 119 |
+
```
|
| 120 |
+
|
| 121 |
+
### 3. Use the Test Script
|
| 122 |
+
```bash
|
| 123 |
+
# Update the base_url in test_server.py
|
| 124 |
+
python test_server.py
|
| 125 |
+
```
|
| 126 |
+
|
| 127 |
+
## π¨ Troubleshooting
|
| 128 |
+
|
| 129 |
+
### Common Issues
|
| 130 |
+
|
| 131 |
+
1. **Build Fails**
|
| 132 |
+
- Check Dockerfile syntax
|
| 133 |
+
- Verify all files are uploaded
|
| 134 |
+
- Check build logs for specific errors
|
| 135 |
+
|
| 136 |
+
2. **Model Loading Errors**
|
| 137 |
+
- Ensure model files are properly uploaded
|
| 138 |
+
- Check file paths in code
|
| 139 |
+
- Verify model file integrity
|
| 140 |
+
|
| 141 |
+
3. **Memory Issues**
|
| 142 |
+
- Consider using smaller models
|
| 143 |
+
- Optimize Docker image
|
| 144 |
+
- Upgrade to GPU space if needed
|
| 145 |
+
|
| 146 |
+
4. **API Not Responding**
|
| 147 |
+
- Check space status
|
| 148 |
+
- Verify port configuration (should be 7860)
|
| 149 |
+
- Check logs for runtime errors
|
| 150 |
+
|
| 151 |
+
### Debug Commands
|
| 152 |
+
|
| 153 |
+
```bash
|
| 154 |
+
# Check space logs
|
| 155 |
+
# Go to Settings β Logs in your HF Space
|
| 156 |
+
|
| 157 |
+
# Test locally first
|
| 158 |
+
python inference_server.py
|
| 159 |
+
python test_server.py
|
| 160 |
+
|
| 161 |
+
# Check Docker build locally
|
| 162 |
+
docker build -t devam-jersey .
|
| 163 |
+
docker run -p 7860:7860 devam-jersey
|
| 164 |
+
```
|
| 165 |
+
|
| 166 |
+
## π Monitoring
|
| 167 |
+
|
| 168 |
+
- **Build Logs**: Check after each push
|
| 169 |
+
- **Runtime Logs**: Monitor for errors during operation
|
| 170 |
+
- **Space Analytics**: Track usage and performance
|
| 171 |
+
- **API Status**: Verify endpoints are responding
|
| 172 |
+
|
| 173 |
+
## π Updates
|
| 174 |
+
|
| 175 |
+
To update your deployed space:
|
| 176 |
+
|
| 177 |
+
1. **Make Changes Locally**
|
| 178 |
+
2. **Push to Git**
|
| 179 |
+
```bash
|
| 180 |
+
git add .
|
| 181 |
+
git commit -m "Update description"
|
| 182 |
+
git push
|
| 183 |
+
```
|
| 184 |
+
3. **Monitor Build**: Check build logs for success
|
| 185 |
+
4. **Test**: Verify changes work as expected
|
| 186 |
+
|
| 187 |
+
## π Additional Resources
|
| 188 |
+
|
| 189 |
+
- [Hugging Face Spaces Documentation](https://huggingface.co/docs/hub/spaces)
|
| 190 |
+
- [Docker on HF Spaces](https://huggingface.co/docs/hub/spaces-sdks-docker)
|
| 191 |
+
- [FastAPI Documentation](https://fastapi.tiangolo.com/)
|
| 192 |
+
|
| 193 |
+
## π Success!
|
| 194 |
+
|
| 195 |
+
Once deployed, your jersey similarity server will be available at:
|
| 196 |
+
```
|
| 197 |
+
https://YOUR_USERNAME-devam-jersey-server.hf.space
|
| 198 |
+
```
|
| 199 |
+
|
| 200 |
+
Share this URL with others to use your API!
|
| 201 |
+
|
| 202 |
+
---
|
| 203 |
+
|
| 204 |
+
**Need Help?** Check the [Hugging Face Community](https://huggingface.co/forums) for support.
|
Dockerfile
CHANGED
|
@@ -1,20 +1,21 @@
|
|
| 1 |
# Base image
|
| 2 |
-
FROM python:3.9
|
| 3 |
-
|
| 4 |
-
# Create non-root user
|
| 5 |
-
RUN useradd -m -u 1000 user
|
| 6 |
-
USER user
|
| 7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
# Set working directory
|
| 10 |
WORKDIR /app
|
| 11 |
|
| 12 |
# Copy and install dependencies
|
| 13 |
-
COPY
|
| 14 |
RUN pip install --no-cache-dir --upgrade -r requirements.txt
|
| 15 |
|
| 16 |
# Copy project files
|
| 17 |
-
COPY
|
| 18 |
|
| 19 |
# Expose Hugging Face Space port
|
| 20 |
EXPOSE 7860
|
|
|
|
| 1 |
# Base image
|
| 2 |
+
FROM python:3.9-slim
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
+
# Install system dependencies
|
| 5 |
+
RUN apt-get update && apt-get install -y \
|
| 6 |
+
libgl1-mesa-glx \
|
| 7 |
+
libglib2.0-0 \
|
| 8 |
+
&& rm -rf /var/lib/apt/lists/*
|
| 9 |
|
| 10 |
# Set working directory
|
| 11 |
WORKDIR /app
|
| 12 |
|
| 13 |
# Copy and install dependencies
|
| 14 |
+
COPY requirements.txt .
|
| 15 |
RUN pip install --no-cache-dir --upgrade -r requirements.txt
|
| 16 |
|
| 17 |
# Copy project files
|
| 18 |
+
COPY . .
|
| 19 |
|
| 20 |
# Expose Hugging Face Space port
|
| 21 |
EXPOSE 7860
|
index/jersey_index.faiss
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:318f96897d724c9b9927533a10e099f959da68f4caf900379485bc6e9c4d85f2
|
| 3 |
+
size 930861
|
requirements.txt
CHANGED
|
@@ -17,9 +17,13 @@ numpy>=1.24.0
|
|
| 17 |
scikit-image>=0.20.0
|
| 18 |
tqdm>=4.65.0
|
| 19 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
# Optional: For better performance
|
| 21 |
# tensorrt # Only if you have NVIDIA GPU
|
| 22 |
-
# onnxruntime-gpu # Only if you have NVIDIA GPU
|
| 23 |
-
|
| 24 |
-
fastapi
|
| 25 |
-
uvicorn
|
|
|
|
| 17 |
scikit-image>=0.20.0
|
| 18 |
tqdm>=4.65.0
|
| 19 |
|
| 20 |
+
# FastAPI and server
|
| 21 |
+
fastapi>=0.100.0
|
| 22 |
+
uvicorn>=0.20.0
|
| 23 |
+
|
| 24 |
+
# HTTP client for testing
|
| 25 |
+
requests>=2.28.0
|
| 26 |
+
|
| 27 |
# Optional: For better performance
|
| 28 |
# tensorrt # Only if you have NVIDIA GPU
|
| 29 |
+
# onnxruntime-gpu # Only if you have NVIDIA GPU
|
|
|
|
|
|
|
|
|
test_server.py
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""
|
| 3 |
+
Test script for Devam Jersey Server
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
import requests
|
| 7 |
+
import json
|
| 8 |
+
from PIL import Image
|
| 9 |
+
import numpy as np
|
| 10 |
+
import io
|
| 11 |
+
|
| 12 |
+
def create_test_image():
|
| 13 |
+
"""Create a simple test image"""
|
| 14 |
+
# Create a 224x224 RGB test image
|
| 15 |
+
img_array = np.random.randint(0, 255, (224, 224, 3), dtype=np.uint8)
|
| 16 |
+
img = Image.fromarray(img_array)
|
| 17 |
+
|
| 18 |
+
# Convert to bytes
|
| 19 |
+
img_byte_arr = io.BytesIO()
|
| 20 |
+
img.save(img_byte_arr, format='PNG')
|
| 21 |
+
img_byte_arr = img_byte_arr.getvalue()
|
| 22 |
+
|
| 23 |
+
return img_byte_arr
|
| 24 |
+
|
| 25 |
+
def test_endpoints(base_url="http://localhost:7860"):
|
| 26 |
+
"""Test all endpoints of the server"""
|
| 27 |
+
print(f"π§ͺ Testing server at {base_url}")
|
| 28 |
+
print("=" * 50)
|
| 29 |
+
|
| 30 |
+
# Test root endpoint
|
| 31 |
+
try:
|
| 32 |
+
response = requests.get(f"{base_url}/")
|
| 33 |
+
if response.status_code == 200:
|
| 34 |
+
print("β
Root endpoint working")
|
| 35 |
+
data = response.json()
|
| 36 |
+
print(f" Status: {data.get('status')}")
|
| 37 |
+
print(f" Models loaded: {data.get('models_loaded')}")
|
| 38 |
+
else:
|
| 39 |
+
print(f"β Root endpoint failed: {response.status_code}")
|
| 40 |
+
except Exception as e:
|
| 41 |
+
print(f"β Root endpoint error: {e}")
|
| 42 |
+
|
| 43 |
+
# Test DINO endpoint
|
| 44 |
+
try:
|
| 45 |
+
test_image = create_test_image()
|
| 46 |
+
files = {'file': ('test.png', test_image, 'image/png')}
|
| 47 |
+
response = requests.post(f"{base_url}/dino", files=files)
|
| 48 |
+
if response.status_code == 200:
|
| 49 |
+
print("β
DINO endpoint working")
|
| 50 |
+
data = response.json()
|
| 51 |
+
print(f" Features length: {len(data.get('features', []))}")
|
| 52 |
+
else:
|
| 53 |
+
print(f"β DINO endpoint failed: {response.status_code}")
|
| 54 |
+
print(f" Response: {response.text}")
|
| 55 |
+
except Exception as e:
|
| 56 |
+
print(f"β DINO endpoint error: {e}")
|
| 57 |
+
|
| 58 |
+
# Test FAISS endpoint
|
| 59 |
+
try:
|
| 60 |
+
# Create dummy features (768-dimensional for DINOv2 base)
|
| 61 |
+
dummy_features = np.random.random(768).tolist()
|
| 62 |
+
payload = {"features": dummy_features}
|
| 63 |
+
response = requests.post(f"{base_url}/faiss", json=payload)
|
| 64 |
+
if response.status_code == 200:
|
| 65 |
+
print("β
FAISS endpoint working")
|
| 66 |
+
data = response.json()
|
| 67 |
+
results = data.get('results', [])
|
| 68 |
+
print(f" Results count: {len(results)}")
|
| 69 |
+
else:
|
| 70 |
+
print(f"β FAISS endpoint failed: {response.status_code}")
|
| 71 |
+
print(f" Response: {response.text}")
|
| 72 |
+
except Exception as e:
|
| 73 |
+
print(f"β FAISS endpoint error: {e}")
|
| 74 |
+
|
| 75 |
+
# Test YOLO endpoint
|
| 76 |
+
try:
|
| 77 |
+
test_image = create_test_image()
|
| 78 |
+
files = {'file': ('test.png', test_image, 'image/png')}
|
| 79 |
+
response = requests.post(f"{base_url}/yolo", files=files)
|
| 80 |
+
if response.status_code == 200:
|
| 81 |
+
print("β
YOLO endpoint working")
|
| 82 |
+
data = response.json()
|
| 83 |
+
polygons = data.get('polygons', [])
|
| 84 |
+
print(f" Polygons found: {len(polygons)}")
|
| 85 |
+
else:
|
| 86 |
+
print(f"β YOLO endpoint failed: {response.status_code}")
|
| 87 |
+
print(f" Response: {response.text}")
|
| 88 |
+
except Exception as e:
|
| 89 |
+
print(f"β YOLO endpoint error: {e}")
|
| 90 |
+
|
| 91 |
+
def main():
|
| 92 |
+
print("π Devam Jersey Server - Local Test")
|
| 93 |
+
print("=" * 50)
|
| 94 |
+
|
| 95 |
+
# Check if server is running
|
| 96 |
+
try:
|
| 97 |
+
response = requests.get("http://localhost:7860/", timeout=5)
|
| 98 |
+
print("β
Server is running locally")
|
| 99 |
+
test_endpoints()
|
| 100 |
+
except requests.exceptions.ConnectionError:
|
| 101 |
+
print("β Server is not running locally")
|
| 102 |
+
print("\nπ To start the server locally:")
|
| 103 |
+
print("1. Install dependencies: pip install -r requirements.txt")
|
| 104 |
+
print("2. Start server: python inference_server.py")
|
| 105 |
+
print("3. Run this test again")
|
| 106 |
+
except Exception as e:
|
| 107 |
+
print(f"β Error testing server: {e}")
|
| 108 |
+
|
| 109 |
+
if __name__ == "__main__":
|
| 110 |
+
main()
|
upload_to_hf.py
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""
|
| 3 |
+
Helper script to upload Devam Jersey Server to Hugging Face Spaces
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
import os
|
| 7 |
+
import subprocess
|
| 8 |
+
import sys
|
| 9 |
+
|
| 10 |
+
def run_command(command, description):
|
| 11 |
+
"""Run a command and handle errors"""
|
| 12 |
+
print(f"π {description}...")
|
| 13 |
+
try:
|
| 14 |
+
result = subprocess.run(command, shell=True, check=True, capture_output=True, text=True)
|
| 15 |
+
print(f"β
{description} completed successfully")
|
| 16 |
+
return result.stdout
|
| 17 |
+
except subprocess.CalledProcessError as e:
|
| 18 |
+
print(f"β {description} failed:")
|
| 19 |
+
print(f"Error: {e.stderr}")
|
| 20 |
+
return None
|
| 21 |
+
|
| 22 |
+
def check_git_status():
|
| 23 |
+
"""Check if we're in a git repository and if it's clean"""
|
| 24 |
+
if not os.path.exists('.git'):
|
| 25 |
+
print("β Not in a git repository. Please initialize git first:")
|
| 26 |
+
print(" git init")
|
| 27 |
+
print(" git add .")
|
| 28 |
+
print(" git commit -m 'Initial commit'")
|
| 29 |
+
return False
|
| 30 |
+
|
| 31 |
+
# Check if there are uncommitted changes
|
| 32 |
+
result = subprocess.run("git status --porcelain", shell=True, capture_output=True, text=True)
|
| 33 |
+
if result.stdout.strip():
|
| 34 |
+
print("β οΈ There are uncommitted changes. Please commit them first:")
|
| 35 |
+
print(" git add .")
|
| 36 |
+
print(" git commit -m 'Update before HF upload'")
|
| 37 |
+
return False
|
| 38 |
+
|
| 39 |
+
return True
|
| 40 |
+
|
| 41 |
+
def main():
|
| 42 |
+
print("π Devam Jersey Server - Hugging Face Upload Helper")
|
| 43 |
+
print("=" * 50)
|
| 44 |
+
|
| 45 |
+
# Check prerequisites
|
| 46 |
+
if not check_git_status():
|
| 47 |
+
return
|
| 48 |
+
|
| 49 |
+
# Check if huggingface_hub is installed
|
| 50 |
+
try:
|
| 51 |
+
import huggingface_hub
|
| 52 |
+
print("β
huggingface_hub is installed")
|
| 53 |
+
except ImportError:
|
| 54 |
+
print("β huggingface_hub not found. Installing...")
|
| 55 |
+
run_command("pip install huggingface_hub", "Installing huggingface_hub")
|
| 56 |
+
|
| 57 |
+
print("\nπ Next steps to upload to Hugging Face:")
|
| 58 |
+
print("1. Go to https://huggingface.co/spaces")
|
| 59 |
+
print("2. Click 'Create new Space'")
|
| 60 |
+
print("3. Choose 'Docker' as the SDK")
|
| 61 |
+
print("4. Set Space name (e.g., 'devam-jersey-server')")
|
| 62 |
+
print("5. Set visibility (Public or Private)")
|
| 63 |
+
print("6. Click 'Create Space'")
|
| 64 |
+
print("\n7. Clone the created space:")
|
| 65 |
+
print(" git clone https://huggingface.co/spaces/YOUR_USERNAME/devam-jersey-server")
|
| 66 |
+
print(" cd devam-jersey-server")
|
| 67 |
+
print("\n8. Copy your project files to the cloned directory")
|
| 68 |
+
print("9. Push to Hugging Face:")
|
| 69 |
+
print(" git add .")
|
| 70 |
+
print(" git commit -m 'Initial upload'")
|
| 71 |
+
print(" git push")
|
| 72 |
+
|
| 73 |
+
print("\nπ§ Alternative: Use huggingface_hub CLI")
|
| 74 |
+
print(" huggingface-cli repo create devam-jersey-server --type space --space-sdk docker")
|
| 75 |
+
print(" cd devam-jersey-server")
|
| 76 |
+
print(" # Copy files and push as above")
|
| 77 |
+
|
| 78 |
+
print("\nπ Important notes:")
|
| 79 |
+
print("- Make sure your model files are not too large (>5GB total)")
|
| 80 |
+
print("- The space will automatically build and deploy your Docker container")
|
| 81 |
+
print("- Check the 'Settings' tab in your space for environment variables if needed")
|
| 82 |
+
print("- Monitor the build logs in the 'Logs' tab")
|
| 83 |
+
|
| 84 |
+
if __name__ == "__main__":
|
| 85 |
+
main()
|