commit d70989d79bc84d2f1273c103fdf6eab4bd8b9b7d
parent 805dd5c30548080f75746d60371cf06e259e844a
Author: Sanjeebani Parida <sanjeebani14@gmail.com>
Date: Wed, 3 Dec 2025 03:03:31 +0530
Added 2 sketch to image api models for canvas page.
Diffstat:
3 files changed, 91 insertions(+), 9 deletions(-)
diff --git a/.env b/.env
@@ -11,3 +11,4 @@ URL_DESCRIBE=https://locustlike-trieciously-rudolph.ngrok-free.dev/describe
URL_GENERATE=https://locustlike-trieciously-rudolph.ngrok-free.dev/generate
URL_INPAINTING=https://locustlike-trieciously-rudolph.ngrok-free.dev/inpainting
URL_INPAINTING_API=https://locustlike-trieciously-rudolph.ngrok-free.dev/inpainting-api
+URL_SKETCH_API=https://locustlike-trieciously-rudolph.ngrok-free.dev/sketch-api
+\ No newline at end of file
diff --git a/lib/services/flask_service.dart b/lib/services/flask_service.dart
@@ -18,9 +18,11 @@ class FlaskService {
static String get _urlGenerate => dotenv.env['URL_GENERATE'] ?? '';
static String get _urlInpainting => dotenv.env['URL_INPAINTING'] ?? '';
static String get _urlInpaintingApi => dotenv.env['URL_INPAINTING_API'] ?? '';
+ static String get _urlSketchApi => dotenv.env['URL_SKETCH_API'] ?? '';
static String get _urlAsset => dotenv.env['URL_ASSET'] ?? '';
static String get _urlDescribe => dotenv.env['URL_DESCRIBE'] ?? '';
+
static const Map<String, String> _headers = {
'Content-Type': 'application/json',
};
@@ -372,8 +374,8 @@ class FlaskService {
filenamePrefix: 'inpaint_$prompt',
);
}
-
- /// [Inpainting with Custom API Endpoint] (Restored from Old Code)
+
+ /// [Inpainting-API]
Future<String?> inpaintApiImage({
required String imagePath,
required String maskPath,
@@ -393,10 +395,65 @@ class FlaskService {
'image': base64Image,
'mask_image': base64Mask,
},
- filenamePrefix: 'inpaint_api_$prompt',
+ filenamePrefix: 'inpaint_api$prompt',
+ );
+ }
+
+ /// [Sketch-to-Image-API]
+ Future<String?> sketchToImageAPI({
+ required String sketchPath,
+ required String userPrompt,
+ required String stylePrompt,
+ required int option,
+ }) async {
+ debugPrint("🔗 [Pipeline] Starting Sketch-to-Image-API...");
+
+ // 1. Analyze Sketch
+ final String? sketchDescription = await describeImage(
+ imagePath: sketchPath,
+ prompt: '<MORE_DETAILED_CAPTION>',
+ );
+
+ if (sketchDescription == null) {
+ debugPrint("❌ [Pipeline] Failed: Could not analyze sketch.");
+ return null;
+ }
+
+ // 2. Construct Prompt & Generate
+ final String globalPrompt =
+ " $userPrompt.$stylePrompt. The image features: $sketchDescription";
+
+ debugPrint("🔗 [Pipeline] Generating base image...");
+
+ final String? generatedImagePath = await _performImageOperation(
+ fullUrl: _urlSketchApi,
+ logPrefix: '🖌️ Inpainting',
+ body: {
+ 'prompt': globalPrompt,
+ 'option': option,
+ },
+ filenamePrefix: 'sketch-to-image-api_$globalPrompt',
);
+
+ if (generatedImagePath == null) {
+ debugPrint("❌ [Pipeline] Failed: Image generation returned null.");
+ return null;
+ }
+
+ // 3. Remove Background (Pipeline Extension)
+ debugPrint("🔗 [Pipeline] Removing background from generated result...");
+
+ // This returns the path to the no-background version
+ return generateAsset(imagePath: generatedImagePath);
+
+
+
+
+
}
+
+
/// [Background Removal]
Future<String?> generateAsset({required String imagePath}) async {
// 1. Prepare and Upload
diff --git a/lib/ui/pages/canvas_board_page.dart b/lib/ui/pages/canvas_board_page.dart
@@ -1500,12 +1500,35 @@ class _CanvasBoardPageState extends State<CanvasBoardPage> {
else {
// Currently all sketch IDs map to the main sketch endpoint,
// but you can pass the ID if your backend supports different sketch models.
- newImageUrl = await FlaskService().sketchToImage(
- sketchPath: _tempBaseImage!.path,
- userPrompt: prompt,
- stylePrompt:
- "high quality, realistic", // You could vary this based on modelId
- );
+ if(modelId == 'sketch_fusion'){
+ newImageUrl = await FlaskService().sketchToImage(
+ sketchPath: _tempBaseImage!.path,
+ userPrompt: prompt,
+ stylePrompt:
+ "high quality, realistic", // You could vary this based on modelId
+ );
+ }
+ else if(modelId == 'sketch_advanced'){
+ newImageUrl = await FlaskService().sketchToImageAPI(
+ sketchPath: _tempBaseImage!.path,
+ userPrompt: prompt,
+ stylePrompt:
+ "high quality, realistic", // You could vary this based on modelId
+ option:1 ,
+ );
+
+ }
+ else if (modelId == 'sketch_creative') {
+ newImageUrl = await FlaskService().sketchToImageAPI(
+ sketchPath: _tempBaseImage!.path,
+ userPrompt: prompt,
+ stylePrompt:
+ "high quality, realistic", // You could vary this based on modelId
+ option: 2,
+ );
+ }
+
+
}
if (newImageUrl != null) {