FastAPI backend service providing vision analysis API.
# Create virtual environment (recommended)
python -m venv venv
# Activate virtual environment
# Windows:
venv\Scripts\activate
# Linux/Mac:
source venv/bin/activate
# Install dependencies
pip install -r requirements.txtCopy .env.example to .env and fill in your OpenAI API Key:
cp .env.example .envEdit .env file:
OPENAI_API_KEY=sk-your-api-key-here
OPENAI_BASE_URL=https://api.openai.com/v1
OPENAI_MODEL=gpt-4opython start.pyOr run directly:
python main.pyOr use uvicorn:
uvicorn main:app --host 127.0.0.1 --port 8000 --reloadGET /health
POST /api/vision_query
Request body:
{
"image_base64": "base64_encoded_image_string",
"prompt": "Please analyze this image (optional)"
}Response:
{
"answer": "AI analysis result",
"success": true,
"error": ""
}After starting the service, visit the following addresses to view auto-generated API documentation:
- Swagger UI: http://127.0.0.1:8000/docs
- ReDoc: http://127.0.0.1:8000/redoc
- gpt-4o (recommended)
- gpt-4-turbo
- gpt-4-vision-preview
Ensure OPENAI_API_KEY in .env file is correctly configured.
Ensure all dependencies are installed:
pip install -r requirements.txtModify PORT configuration in .env file, or specify in command line:
PORT=8001 python start.pyAdd new route functions in main.py.
Edit vision.py file.