A robust, self-installing AI image processing server that intelligently routes requests through multiple AI providers with automatic fallback and best-answer selection, optimized for high-speed image streaming.
This server processes images through multiple AI services in sequence, intelligently asking each AI if it needs help before deciding whether to move to the next. It automatically selects the best response, leveraging a "judge" AI if multiple responses are gathered, and returns it to your application.
- GPT4FREE integration!!! (Thats right boys, we are NOT getting rate limited L0L)
AI Service Routing Logic:
- Gemini β Fast, good for general questions, math, directions.
- Confidence-based routing: If Gemini needs help, it passes to the next AI.
- DeepSeek β Smart but slower, good for complex reasoning.
- Confidence-based routing: If DeepSeek needs help, it passes to the next AI.
- Qwen β Translation and language tasks.
- Confidence-based routing: If Qwen needs help, it passes to the next AI.
- ChatGPT β Final fallback option.
If multiple AIs respond, Gemini (if available) acts as a "judge" to select the most accurate and helpful answer or combine them into a better response.
- Auto-installs all dependencies with intelligent fallbacks (e.g., trying older
pillowversions orurllibforhttpx). - Works out-of-the-box on Windows and Linux.
- Graceful degradation when packages fail to install.
- No manual configuration required.
- Custom authentication endpoints (
/auth-<your-key>). - IP blacklisting with automatic persistence.
- Rate limiting (5 auth/min, 10 profile updates/min, 3600 image processing/hour for 1 FPS streaming!).
- Request logging and activity monitoring.
- Multi-provider support (Gemini, DeepSeek, Qwen, ChatGPT).
- Confidence-based routing (AIs self-assess if they need help answering).
- Best-answer selection using Gemini as judge.
- Automatic failover when services are unavailable.
- Intelligent rate limiting with randomized jitter to prevent API overuse.
- Automatic cleanup (data older than 3 days or profiles exceeding 1GB).
- SQLite database for profiles, activity logs, and custom prompts.
- Image storage with organized file structure.
- Usage analytics and reporting.
- NEW: Real-time debug messages included in responses, cleaned of emojis for glasses display.
- NEW: Flutter app can now set and retrieve custom prompts remotely via dedicated API endpoints.
- Live server management while running.
- Profile management (
/addprofile,/deleteprofile,/listprofiles). - Activity reports with detailed analytics.
- IP blacklisting (
/blacklistip). - NEW: Custom prompt management (
/prompt <username> [new_prompt]).
- Python 3.7+
- Internet connection (for dependency installation)
-
Clone the repository:
git clone [https://github.com/jonhardwick-spec/Frame-Backend.git](https://github.com/jonhardwick-spec/Frame-Backend.git) cd Frame-BackendOr download directly:
wget [https://raw.githubusercontent.com/jonhardwick-spec/Frame-Backend/main/main.py](https://raw.githubusercontent.com/jonhardwick-spec/Frame-Backend/main/main.py) -O server.py # or curl -O [https://raw.githubusercontent.com/jonhardwick-spec/Frame-Backend/main/main.py](https://raw.githubusercontent.com/jonhardwick-spec/Frame-Backend/main/main.py) -o server.pyNote: The main file is now
main.pyin the repo, but renamed toserver.pyfor download convenience. -
Run it (that's it!):
python server.py
-
The server will:
- Auto-install all required dependencies.
- Start on
http://0.0.0.0:7175. - Initialize the database.
- Launch the command interface.
-
Add a profile via command interface:
> /addprofile myusername mysecretkey123 -
Test authentication:
curl -X POST "http://localhost:7175/auth-mysecretkey123" -
Configure your app with the API keys through your Flutter app settings.
POST /auth-{auth_key}Authenticate using your profile's auth key.
POST /profile
Content-Type: application/json
{
"username": "myusername",
"api_keys": {
"gemini_api_key": "AIza...",
"deepseek_api_key": "sk-...",
"qwen_api_key": "sk-...",
"chatgpt_api_key": "sk-..."
}
}Update a user's API keys. The user must already exist in the database (added via command interface).
Allows Flutter apps to set and retrieve custom prompts.
Set Custom Prompt:
POST /prompt-{username}
Content-Type: application/json
{
"prompt": "Analyze this image for potential security threats and vulnerabilities."
}Set a custom prompt for a specific user. If the prompt is empty, it reverts to the default.
Get Current Prompt:
GET /prompt-{username}Retrieve the current custom prompt for a user, or the default prompt if no custom prompt is set.
Response:
{
"username": "myusername",
"prompt": "Analyze this image for potential security threats and vulnerabilities.",
"is_custom": true,
"default_prompt": "Describe this image in detail"
}POST /process
Content-Type: multipart/form-data
image: [image file]
username: myusername
prompt: "Describe this image" (optional, will use user's custom prompt or default if not provided)Response:
{
"answer": "The best selected response",
"ai_responses": {
"gemini": "Gemini's response",
"deepseek": "DeepSeek's response"
},
"processing_time": 2.34,
"prompt_used": "Describe this image",
"debug_messages": [
"[10:30:05] [AI] Processing image for myusername",
"[10:30:05] [TARGET] Using prompt: 'Describe this image...' "
],
"success": true,
"error": null
}Includes debug_messages (emoji-free) for direct display on connected devices (e.g., smart glasses).
GET /healthWhile the server is running, use these commands in the console:
| Command | Description |
|---|---|
/listprofiles |
List all user profiles (π=custom prompt, π=default). |
/addprofile <username> <auth_key> |
Add a new user profile to the system. |
/deleteprofile <username> |
Delete a profile and all associated data (images, logs, custom prompts). |
/activityreport <username> |
Show detailed usage statistics and recent activity for a profile. |
/blacklistip <ip> |
Block an IP address from accessing the server. |
/prompt <username> |
View the current custom or default prompt for a user. |
/prompt <username> [new_prompt] |
Set a custom prompt for a user. Example: /prompt john [Analyze for security] |
/help |
Show all available commands and usage instructions. |
/quit |
Gracefully shutdown the server. |
| Provider | Image Support | Notes |
|---|---|---|
| Google Gemini | β | Fast, good for general tasks. |
| DeepSeek | β | Slower but very capable. |
| Qwen | β | Great for languages/translation. |
| ChatGPT (GPT-4o) | β | Reliable fallback option. |
- Authentication: 5 requests/minute
- Profile Updates: 10 requests/minute
- Image Processing: 3600 requests/hour (Designed for 1 Frame Per Second streaming!)
- Images & Responses: Cleaned up after 3 days or if a profile's data exceeds 1GB.
- Activity Logs: Automatically cleaned up (older than 3 days).
- Database: SQLite with automatic initialization and maintenance.
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β Flutter App βββββΆβ Auth Gateway βββββΆβ AI Router β
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β β
βΌ βΌ
βββββββββββββββββββ βββββββββββββββββββ
β Rate Limiter β β AI Services β
βββββββββββββββββββ β βββββββββββββββ β
β β β Gemini β β
βββββββββββββββββββ β β DeepSeek β β
β Database β β β Qwen β β
β (SQLite) β β β ChatGPT β β
βββββββββββββββββββ β βββββββββββββββ β
β βββββββββββββββββββ
βββββββββββββββββββ β
β File Storage β βΌ
β (Images/Logs) β βββββββββββββββββββ
βββββββββββββββββββ β Response Judge β
β (Gemini) β
βββββββββββββββββββ
fastapi>=0.100.0- Web framework.uvicorn[standard]>=0.20.0- ASGI server.httpx>=0.24.0- HTTP client for AI APIs (withurllibfallback).slowapi>=0.1.8- Rate limiting (with dummy fallback).pillow>=10.0.0- Image processing (with fallbacks to older versions/alternatives).aiofiles>=22.0.0- Async file operations (with sync fallback).python-multipart>=0.0.5- File upload support (with warning if missing).pydantic>=2.0.0- Data validation (with basic class fallback).
βββ main.py # Main server file (self-contained)
βββ ai_server.db # SQLite database (auto-created)
βββ stored_images/ # Image storage (auto-created)
βββ stored_responses/ # Response logs (auto-created)
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
Because it spells "TITS" upside down on a calculator, and we're not too mature for that. π
Made with β€οΈ for developers who want AI image processing without the hassle.