mirror of
https://github.com/snapotter-hq/SnapOtter.git
synced 2026-08-03 07:46:42 +02:00
feat: add Phase 4 AI tools with Python bridge and 6 new tools
Add Python bridge (packages/ai/src/bridge.ts) that calls Python scripts via child_process with venv-first fallback to system python3. Implements 6 AI-powered tools: - Remove Background: rembg-based with U2-Net/IS-Net models - Image Upscaling: Real-ESRGAN with Lanczos fallback - OCR/Text Extraction: Tesseract + PaddleOCR engines - Face/PII Blur: MediaPipe face detection with configurable blur - Object Eraser: LaMa inpainting with mask-based input - Smart Crop: Sharp attention-based entropy cropping (no Python needed) Each tool includes: Python script, TypeScript wrapper, API route, and React settings component. All Python scripts handle ImportError gracefully with clear installation messages.
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
import { runPythonScript } from "./bridge.js";
|
||||
import { writeFile, readFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
|
||||
export interface UpscaleOptions {
|
||||
scale?: number;
|
||||
}
|
||||
|
||||
export interface UpscaleResult {
|
||||
buffer: Buffer;
|
||||
width: number;
|
||||
height: number;
|
||||
method: string;
|
||||
}
|
||||
|
||||
export async function upscale(
|
||||
inputBuffer: Buffer,
|
||||
outputDir: string,
|
||||
options: UpscaleOptions = {},
|
||||
): Promise<UpscaleResult> {
|
||||
const inputPath = join(outputDir, "input_upscale.png");
|
||||
const outputPath = join(outputDir, "output_upscale.png");
|
||||
|
||||
await writeFile(inputPath, inputBuffer);
|
||||
const { stdout } = await runPythonScript("upscale.py", [
|
||||
inputPath,
|
||||
outputPath,
|
||||
JSON.stringify(options),
|
||||
]);
|
||||
|
||||
const result = JSON.parse(stdout);
|
||||
if (!result.success) {
|
||||
throw new Error(result.error || "Upscaling failed");
|
||||
}
|
||||
|
||||
const buffer = await readFile(outputPath);
|
||||
return {
|
||||
buffer,
|
||||
width: result.width,
|
||||
height: result.height,
|
||||
method: result.method ?? "unknown",
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user