Spaces:
Runtime error
Runtime error
tabito12345678910
commited on
Commit
·
11dd0dd
1
Parent(s):
df2aef5
Fix README.md with proper Hugging Face Spaces YAML configuration
Browse files
README.md
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: Gohan Product Recommendation API
|
| 3 |
+
emoji: 🍚
|
| 4 |
+
colorFrom: yellow
|
| 5 |
+
colorTo: orange
|
| 6 |
+
sdk: docker
|
| 7 |
+
sdk_version: "0.2.0"
|
| 8 |
+
app_file: app.py
|
| 9 |
+
pinned: false
|
| 10 |
+
---
|
| 11 |
+
|
| 12 |
+
# Gohan FastAPI
|
| 13 |
+
|
| 14 |
+
This is a FastAPI-based product recommendation API deployed on Hugging Face Spaces.
|
| 15 |
+
|
| 16 |
+
## Endpoints
|
| 17 |
+
|
| 18 |
+
- `GET /` - Root endpoint with API information
|
| 19 |
+
- `GET /status` - Health check and model status
|
| 20 |
+
- `POST /predict` - Main prediction endpoint with topK parameter
|
| 21 |
+
- `POST /predict_simple` - Simple prediction endpoint
|
| 22 |
+
|
| 23 |
+
## Usage
|
| 24 |
+
|
| 25 |
+
### Check API Status
|
| 26 |
+
```bash
|
| 27 |
+
curl "https://tabito123-gohan-api-light.hf.space/status"
|
| 28 |
+
```
|
| 29 |
+
|
| 30 |
+
### Make Predictions
|
| 31 |
+
```bash
|
| 32 |
+
curl -X POST "https://tabito123-gohan-api-light.hf.space/predict" \
|
| 33 |
+
-H "Content-Type: application/json" \
|
| 34 |
+
-d '{"company_data_json": "{\"INDUSTRY\": \"IT\"}", "topK": 10}'
|
| 35 |
+
```
|
| 36 |
+
|
| 37 |
+
## Model Loading
|
| 38 |
+
|
| 39 |
+
The API uses FastAPI's lifespan events to load models only once during startup, providing efficient cold start handling.
|
| 40 |
+
|
| 41 |
+
## Required Model Files
|
| 42 |
+
|
| 43 |
+
- `model/gohan/epoch_*.pt` (PyTorch model)
|
| 44 |
+
- `model/gohan/*.json` (encoder files)
|
| 45 |
+
- `model/gohan/gohan_pm.csv` (product master data)
|
| 46 |
+
|
| 47 |
+
## API Response Format
|
| 48 |
+
|
| 49 |
+
```json
|
| 50 |
+
{
|
| 51 |
+
"status": "success",
|
| 52 |
+
"model": "gohan",
|
| 53 |
+
"recommendations": [
|
| 54 |
+
{
|
| 55 |
+
"category_id": 123,
|
| 56 |
+
"category_name": "栄養豊富な雑穀米",
|
| 57 |
+
"score": 0.95
|
| 58 |
+
}
|
| 59 |
+
],
|
| 60 |
+
"metadata": {
|
| 61 |
+
"model_version": "gohan_cid_v1.0",
|
| 62 |
+
"total_categories": 30,
|
| 63 |
+
"requested_k": 10
|
| 64 |
+
}
|
| 65 |
+
}
|
| 66 |
+
```
|
| 67 |
+
|
| 68 |
+
## Cold Start Handling
|
| 69 |
+
|
| 70 |
+
The API automatically handles cold starts by:
|
| 71 |
+
1. Loading models during startup
|
| 72 |
+
2. Providing `/status` endpoint to check readiness
|
| 73 |
+
3. Returning appropriate HTTP status codes during loading
|
| 74 |
+
4. Graceful error handling for unready states
|