parthraninga commited on
Commit
dfa96a5
Β·
verified Β·
1 Parent(s): 95efa57

Delete README.md

Browse files
Files changed (1) hide show
  1. README.md +0 -295
README.md DELETED
@@ -1,295 +0,0 @@
1
- # ChatGPT Oasis Model Inference API - Hugging Face Spaces (Docker)
2
-
3
- A FastAPI-based inference server for vision models (Oasis 500M and ViT-L-20) deployed on Hugging Face Spaces using Docker SDK with local model files.
4
-
5
- ## πŸš€ Live Demo
6
-
7
- This API is deployed on Hugging Face Spaces and can be accessed at:
8
- ```
9
- https://your-username-chatgpt-oasis.hf.space
10
- ```
11
-
12
- ## πŸ“‹ API Endpoints
13
-
14
- ### Base URL
15
- ```
16
- https://your-username-chatgpt-oasis.hf.space
17
- ```
18
-
19
- ### Available Endpoints
20
-
21
- #### 1. API Information
22
- - **GET** `/`
23
- - Returns API information and usage instructions
24
-
25
- #### 2. Health Check
26
- - **GET** `/health`
27
- - Returns server health status, model loading status, and model file presence
28
-
29
- #### 3. List Models
30
- - **GET** `/models`
31
- - Returns information about available models and their file status
32
-
33
- #### 4. Inference (Base64)
34
- - **POST** `/inference`
35
- - Accepts base64 encoded images
36
- - Request body:
37
- ```json
38
- {
39
- "image": "base64_encoded_image_string",
40
- "model_name": "oasis500m" // or "vit-l-20"
41
- }
42
- ```
43
-
44
- #### 5. Inference (File Upload)
45
- - **POST** `/upload_inference`
46
- - Accepts image file uploads
47
- - Form data:
48
- - `file`: Image file
49
- - `model_name`: Model to use (optional, defaults to "oasis500m")
50
-
51
- #### 6. Simple Prediction (Gradio Compatible)
52
- - **POST** `/predict`
53
- - Simple file upload endpoint for easy integration
54
-
55
- ## πŸ”§ Usage Examples
56
-
57
- ### Using Python Requests
58
-
59
- ```python
60
- import requests
61
- import base64
62
- from PIL import Image
63
- import io
64
-
65
- # Your Hugging Face Spaces URL
66
- SPACE_URL = "https://your-username-chatgpt-oasis.hf.space"
67
-
68
- # Method 1: File Upload
69
- def predict_with_file_upload(image_path, model_name="oasis500m"):
70
- with open(image_path, 'rb') as f:
71
- files = {'file': f}
72
- data = {'model_name': model_name}
73
-
74
- response = requests.post(
75
- f"{SPACE_URL}/upload_inference",
76
- files=files,
77
- data=data,
78
- timeout=120
79
- )
80
- return response.json()
81
-
82
- # Method 2: Base64 Encoding
83
- def predict_with_base64(image_path, model_name="oasis500m"):
84
- # Load and encode image
85
- image = Image.open(image_path)
86
- buffer = io.BytesIO()
87
- image.save(buffer, format="JPEG")
88
- image_base64 = base64.b64encode(buffer.getvalue()).decode()
89
-
90
- # Make request
91
- response = requests.post(
92
- f"{SPACE_URL}/inference",
93
- json={
94
- "image": image_base64,
95
- "model_name": model_name
96
- },
97
- timeout=120
98
- )
99
- return response.json()
100
-
101
- # Example usage
102
- result = predict_with_file_upload("your_image.jpg", "oasis500m")
103
- print(result)
104
- ```
105
-
106
- ### Using cURL
107
-
108
- ```bash
109
- # File upload inference
110
- curl -X POST "https://your-username-chatgpt-oasis.hf.space/upload_inference" \
111
- -H "accept: application/json" \
112
- -F "file=@your_image.jpg" \
113
- -F "model_name=oasis500m"
114
-
115
- # Health check
116
- curl "https://your-username-chatgpt-oasis.hf.space/health"
117
-
118
- # API documentation
119
- curl "https://your-username-chatgpt-oasis.hf.space/docs"
120
- ```
121
-
122
- ### Using JavaScript/Fetch
123
-
124
- ```javascript
125
- // File upload inference
126
- async function predictImage(file, modelName = 'oasis500m') {
127
- const formData = new FormData();
128
- formData.append('file', file);
129
- formData.append('model_name', modelName);
130
-
131
- const response = await fetch('https://your-username-chatgpt-oasis.hf.space/upload_inference', {
132
- method: 'POST',
133
- body: formData
134
- });
135
-
136
- return await response.json();
137
- }
138
-
139
- // Base64 inference
140
- async function predictImageBase64(imageBase64, modelName = 'oasis500m') {
141
- const response = await fetch('https://your-username-chatgpt-oasis.hf.space/inference', {
142
- method: 'POST',
143
- headers: {
144
- 'Content-Type': 'application/json',
145
- },
146
- body: JSON.stringify({
147
- image: imageBase64,
148
- model_name: modelName
149
- })
150
- });
151
-
152
- return await response.json();
153
- }
154
- ```
155
-
156
- ## πŸ“Š Response Format
157
-
158
- All inference endpoints return the same response format:
159
-
160
- ```json
161
- {
162
- "predictions": [
163
- {
164
- "label": "predicted_class_name",
165
- "confidence": 0.95
166
- },
167
- {
168
- "label": "second_predicted_class",
169
- "confidence": 0.03
170
- }
171
- ],
172
- "model_used": "oasis500m",
173
- "confidence_scores": [0.95, 0.03, 0.01, 0.005, 0.005]
174
- }
175
- ```
176
-
177
- ## πŸ€– Available Models
178
-
179
- ### Oasis 500M
180
- - **Type**: Vision Transformer
181
- - **Size**: ~500M parameters
182
- - **File**: `oasis500m.safetensors`
183
- - **Use Case**: General image classification
184
- - **Performance**: High accuracy on ImageNet
185
-
186
- ### ViT-L-20
187
- - **Type**: Vision Transformer Large
188
- - **Size**: ~300M parameters
189
- - **File**: `vit-l-20.safetensors`
190
- - **Use Case**: High-performance image classification
191
- - **Performance**: State-of-the-art on many benchmarks
192
-
193
- ## πŸ” API Documentation
194
-
195
- Once deployed, you can access:
196
- - **Interactive API Docs**: `https://your-username-chatgpt-oasis.hf.space/docs`
197
- - **Alternative API Docs**: `https://your-username-chatgpt-oasis.hf.space/redoc`
198
-
199
- ## πŸš€ Deployment on Hugging Face Spaces (Docker SDK)
200
-
201
- ### Prerequisites
202
- 1. Hugging Face account
203
- 2. Local model files (`.safetensors`)
204
- 3. Git repository with your code
205
-
206
- ### Steps to Deploy
207
-
208
- 1. **Create a new Space on Hugging Face**
209
- - Go to [Hugging Face Spaces](https://huggingface.co/spaces)
210
- - Click "Create new Space"
211
- - Choose **"Docker"** as the SDK
212
- - Set visibility (public/private)
213
-
214
- 2. **Prepare your files**
215
- - `Dockerfile` - Container configuration
216
- - `app.py` - Main FastAPI application
217
- - `requirements.txt` - Python dependencies
218
- - `README.md` - This documentation
219
- - `oasis500m.safetensors` - Oasis model weights
220
- - `vit-l-20.safetensors` - ViT model weights
221
-
222
- 3. **Upload files to your Space**
223
- - Upload all files to the Space repository
224
- - The Dockerfile will copy the model files into the container
225
-
226
- 4. **Configure the Space**
227
- - Set appropriate hardware requirements (CPU/GPU)
228
- - Ensure sufficient memory for model loading
229
-
230
- 5. **Deploy**
231
- - Push your code to the Space repository
232
- - Hugging Face will automatically build the Docker image and deploy
233
-
234
- ### Space Configuration
235
-
236
- Your Space will need:
237
- - **Hardware**: CPU (or GPU for faster inference)
238
- - **Memory**: At least 8GB RAM (for both models)
239
- - **Storage**: Sufficient space for model files (~3GB)
240
-
241
- ## πŸ“ File Structure
242
-
243
- ```
244
- your-space/
245
- β”œβ”€β”€ Dockerfile # Container configuration
246
- β”œβ”€β”€ app.py # FastAPI application
247
- β”œβ”€β”€ requirements.txt # Python dependencies
248
- β”œβ”€β”€ README.md # Documentation
249
- β”œβ”€β”€ .dockerignore # Docker ignore file
250
- β”œβ”€β”€ oasis500m.safetensors # Oasis model weights
251
- └── vit-l-20.safetensors # ViT model weights
252
- ```
253
-
254
- ## ⚑ Performance Tips
255
-
256
- - **Model Loading**: Models are loaded once when the container starts
257
- - **Local Files**: Using local `.safetensors` files avoids download time
258
- - **Caching**: Consider implementing response caching for repeated requests
259
- - **Batch Processing**: For multiple images, send them sequentially
260
- - **Image Size**: Optimize image size before sending (models expect specific dimensions)
261
-
262
- ## πŸ”§ Troubleshooting
263
-
264
- ### Common Issues
265
-
266
- 1. **Model Loading Time**
267
- - First request may take longer as models load from local files
268
- - Check `/health` endpoint for model status
269
-
270
- 2. **Memory Issues**
271
- - Use smaller images
272
- - Process one image at a time
273
- - Consider using only one model at a time
274
-
275
- 3. **Model File Issues**
276
- - Ensure `.safetensors` files are uploaded to the Space
277
- - Check `/health` endpoint for file presence status
278
-
279
- 4. **Timeout Errors**
280
- - Increase timeout settings in your client
281
- - Check Space logs for errors
282
-
283
- ### Getting Help
284
-
285
- - Check the Space logs in Hugging Face dashboard
286
- - Use the `/health` endpoint to verify model and file status
287
- - Test with the `/docs` interactive interface
288
-
289
- ## πŸ“ License
290
-
291
- This project is for inference purposes. Please respect the licenses of the underlying models (Oasis and ViT).
292
-
293
- ## 🀝 Contributing
294
-
295
- Feel free to submit issues and enhancement requests!