File size: 3,055 Bytes
b190b45 |
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 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# π Starting the FastAPI Server
This guide explains how to run the Crypto Intelligence Hub FastAPI server using uvicorn on port 7860.
## Quick Start
### Method 1: Using Python directly (Recommended)
```bash
python main.py
```
### Method 2: Using the run script
```bash
python run_server.py
```
### Method 3: Using uvicorn directly
```bash
uvicorn main:app --host 0.0.0.0 --port 7860
```
## Configuration
### Port Configuration
The server runs on **port 7860** by default (Hugging Face Spaces standard).
You can change the port using environment variables:
```bash
# Windows
set PORT=8000
python main.py
# Linux/Mac
export PORT=8000
python main.py
```
Or for Hugging Face Spaces:
```bash
export HF_PORT=7860
python main.py
```
### Host Configuration
Default host is `0.0.0.0` (listens on all interfaces).
Change it with:
```bash
export HOST=127.0.0.1 # Only localhost
python main.py
```
### Development Mode (Auto-reload)
Enable auto-reload for development:
```bash
export DEBUG=true
python main.py
```
## Access Points
Once the server is running, you can access:
- **Main Dashboard**: http://localhost:7860/
- **API Documentation**: http://localhost:7860/docs
- **System Monitor**: http://localhost:7860/system-monitor
- **OpenAPI Schema**: http://localhost:7860/openapi.json
## Production Deployment
### Hugging Face Spaces
The server is configured to work with Hugging Face Spaces automatically:
- Port 7860 is the default
- Host 0.0.0.0 allows external access
- All optimizations are enabled
### Using Gunicorn (Alternative)
For production with multiple workers:
```bash
gunicorn main:app -w 4 -k uvicorn.workers.UvicornWorker --bind 0.0.0.0:7860
```
## Troubleshooting
### Port Already in Use
If port 7860 is already in use:
```bash
# Find what's using the port
# Windows
netstat -ano | findstr :7860
# Linux/Mac
lsof -i :7860
# Then use a different port
export PORT=8000
python main.py
```
### Module Not Found Errors
Make sure all dependencies are installed:
```bash
pip install -r requirements.txt
```
### Database Connection Issues
The server will continue to run even if database connections fail. Check logs for specific errors.
## Environment Variables
| Variable | Default | Description |
|----------|---------|-------------|
| `PORT` | `7860` | Server port |
| `HF_PORT` | `7860` | Hugging Face Spaces port (fallback) |
| `HOST` | `0.0.0.0` | Server host |
| `DEBUG` | `false` | Enable auto-reload |
## Logs
The server logs to console with INFO level by default. You'll see:
- Server startup messages
- Router loading status
- Request logs (if access_log=True)
- Error messages
## Stopping the Server
Press `Ctrl+C` to gracefully stop the server.
## Next Steps
1. β
Server is running on port 7860
2. π Open the dashboard at http://localhost:7860/
3. π Check API docs at http://localhost:7860/docs
4. π Monitor system at http://localhost:7860/system-monitor
|