File size: 3,063 Bytes
e6453d3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# Deploy API Server to Hugging Face Space

## Problem
The current Hugging Face Space deployment is running in `--hfdemo` mode, which provides a Gradio UI but does NOT expose the API endpoints like `/api/ping`, `/api/health`, etc.

## Solution
The Dockerfile has been updated to:
1. Run in `--api` mode instead of `--hfdemo` mode
2. Use port 7860 (required by Hugging Face Spaces) instead of the default port 8000

## Deployment Steps

### 1. Commit and Push Changes
```bash
cd sci-image
git add Dockerfile
git commit -m "Switch to API server mode for Hugging Face Space"
git push
```

### 2. Push to Hugging Face Space
If you have the Hugging Face Space connected as a remote:
```bash
git push hf main
```

Or manually upload the updated Dockerfile to your Hugging Face Space at:
https://huggingface.co/spaces/gsstec/sci-image/tree/main

### 3. Wait for Rebuild
The Hugging Face Space will automatically rebuild with the new Dockerfile. This may take 5-10 minutes.

### 4. Verify API Endpoints
Once deployed, test the endpoints:

**Ping Endpoint:**
```bash
curl https://gsstec-sci-image.hf.space/api/ping
```

Expected response:
```json
{
  "status": "ok",
  "service": "AEGIS Bio-Digital Lab 10 - Visual System",
  "version": "1.0.0",
  "device": "cpu"
}
```

**Health Endpoint:**
```bash
curl https://gsstec-sci-image.hf.space/api/health
```

**System Info:**
```bash
curl https://gsstec-sci-image.hf.space/api/info
```

## Available API Endpoints After Deployment

### Health & Monitoring
- `GET /api/` - Welcome message
- `GET /api/ping` - Health check for UptimeRobot
- `GET /api/health` - Detailed health status
- `GET /api/info` - System information
- `GET /api/config` - Current configuration
- `GET /api/models` - Available models

### Image Generation
- `POST /api/generate` - General image generation
- `POST /api/window7/generate-pathogen` - Pathogen visualization
- `POST /api/window7/generate-disease-visualization` - Disease visualization
- `POST /api/window9/generate-molecule` - Molecular structure
- `POST /api/window9/generate-drug-visualization` - Drug visualization
- `POST /api/aegis/generate-scientific` - Scientific visualization

### API Documentation
- `/api/docs` - Swagger UI documentation
- `/api/redoc` - ReDoc documentation
- `/api/openapi.json` - OpenAPI specification

## UptimeRobot Configuration

After deployment, configure UptimeRobot:
- **Monitor Type**: HTTP(s)
- **URL**: `https://gsstec-sci-image.hf.space/api/ping`
- **Interval**: 5 minutes
- **Expected Response**: `200 OK` with `"status": "ok"`

## Testing Locally

To test the API server locally before deploying:
```bash
cd sci-image
python src/app.py --api
```

Then test:
```bash
curl http://localhost:8000/api/ping
```

## Reverting to UI Mode

If you need to revert to the Gradio UI:
```dockerfile
CMD ["python", "src/app.py","--hfdemo"]
```

## Notes

- The API server runs on port 7860 (as configured in Dockerfile EXPOSE)
- CORS is enabled for all origins
- The server uses FastAPI with automatic OpenAPI documentation
- All endpoints are prefixed with `/api/`