@umituz/react-native-ai-generation-content 1.17.169 → 1.17.171

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,108 +1,41 @@
1
+ /**
2
+ * Image Enhancement Service
3
+ * AI prompt generation for image enhancement tasks
4
+ */
5
+
1
6
  import type { IImageEnhancementService } from '../../domain/repositories/IAIPromptServices';
2
- import type {
3
- ImageEnhancementConfig,
4
- EnhancementAdjustments,
5
- } from '../../domain/entities/ImageEnhancementConfig';
7
+ import type { ImageEnhancementConfig, EnhancementAdjustments } from '../../domain/entities/ImageEnhancementConfig';
6
8
  import type { AIPromptTemplate } from '../../domain/entities/AIPromptTemplate';
7
- import type { AIPromptResult } from '../../domain/entities/types';
8
- import { createAIPromptTemplate } from '../../domain/entities/AIPromptTemplate';
9
- import {
10
- validateImageEnhancementConfig,
11
- calculateAdjustments
12
- } from '../../domain/entities/ImageEnhancementConfig';
13
- import { PromptGenerationService } from '../services/PromptGenerationService';
14
-
15
- const createImageEnhancementBaseTemplate = (config?: {
16
- enhancementType?: string;
17
- targetStyle?: string;
18
- }): string => {
19
- const {
20
- enhancementType = 'comprehensive',
21
- targetStyle = 'natural'
22
- } = config || {};
9
+ import { validateImageEnhancementConfig, calculateAdjustments } from '../../domain/entities/ImageEnhancementConfig';
10
+ import { BasePromptService } from './base';
23
11
 
24
- return `
12
+ const BASE_TEMPLATE = `
25
13
  You are an expert AI image enhancement specialist.
26
14
  This is an IMAGE ENHANCEMENT task, not image generation.
27
15
 
28
- ENHANCEMENT GOAL:
29
- Apply ${enhancementType} improvements with ${targetStyle} appearance
30
- while preserving the original content and composition.
31
-
32
16
  ENHANCEMENT PRINCIPLES:
33
17
  - Maintain natural appearance and authenticity
34
18
  - Apply subtle, professional-grade adjustments
35
19
  - Preserve important details and textures
36
- - Avoid over-processing or artificial results
37
20
 
38
21
  TECHNICAL REQUIREMENTS:
39
22
  - Proper exposure and brightness correction
40
23
  - Optimal contrast and dynamic range
41
24
  - Natural color balance and saturation
42
25
  - Appropriate sharpening and clarity
43
- - Noise reduction without losing details
44
-
45
- STYLE CONSIDERATIONS:
46
- ${targetStyle === 'vivid' ? '- Vibrant colors with high impact' :
47
- targetStyle === 'dramatic' ? '- Enhanced contrast and mood' :
48
- targetStyle === 'professional' ? '- Conservative, polished look' :
49
- '- Natural, balanced appearance'}
50
26
 
51
27
  SAFETY CONSTRAINTS:
52
28
  - Do not alter the subject or composition
53
29
  - Preserve skin tones and natural colors
54
- - Avoid artificial or over-enhanced results
55
30
  - Maintain photo authenticity
56
-
57
- OUTPUT:
58
- A professionally enhanced version with ${enhancementType} improvements,
59
- optimized for ${targetStyle} presentation.
60
- `.trim();
61
- };
62
-
63
- export class ImageEnhancementService implements IImageEnhancementService {
64
- private promptService: PromptGenerationService;
65
-
66
- constructor() {
67
- this.promptService = new PromptGenerationService();
68
- }
69
-
70
- generateTemplate(config: ImageEnhancementConfig): Promise<AIPromptResult<AIPromptTemplate>> {
71
- try {
72
- if (!this.validateConfig(config)) {
73
- return Promise.resolve({
74
- success: false,
75
- error: 'VALIDATION_ERROR',
76
- message: 'Invalid image enhancement configuration'
77
- });
78
- }
79
-
80
- const template = this.createImageEnhancementTemplate(config);
81
- return Promise.resolve({ success: true, data: template });
82
- } catch {
83
- return Promise.resolve({
84
- success: false,
85
- error: 'GENERATION_FAILED',
86
- message: 'Failed to generate image enhancement template'
87
- });
88
- }
89
- }
90
-
91
- async generatePrompt(
92
- template: AIPromptTemplate,
93
- config: ImageEnhancementConfig
94
- ): Promise<AIPromptResult<string>> {
95
- const adjustments = this.calculateAdjustments(config);
96
- const variables = {
97
- enhancementType: config.enhancementType,
98
- intensity: config.intensity,
99
- preserveNatural: config.preserveNatural,
100
- autoAdjust: config.autoAdjust,
101
- targetStyle: config.targetStyle,
102
- adjustments,
103
- };
104
-
105
- return this.promptService.generateFromTemplate(template, variables);
31
+ `.trim();
32
+
33
+ export class ImageEnhancementService
34
+ extends BasePromptService<ImageEnhancementConfig>
35
+ implements IImageEnhancementService
36
+ {
37
+ protected getServiceName(): string {
38
+ return 'image enhancement';
106
39
  }
107
40
 
108
41
  validateConfig(config: ImageEnhancementConfig): boolean {
@@ -113,69 +46,30 @@ export class ImageEnhancementService implements IImageEnhancementService {
113
46
  return calculateAdjustments(config);
114
47
  }
115
48
 
116
- private createImageEnhancementTemplate(config: ImageEnhancementConfig): AIPromptTemplate {
117
- const templateId = `image-enhancement-${config.enhancementType}`;
118
-
119
- const baseTemplate = createImageEnhancementBaseTemplate({
49
+ protected buildVariables(config: ImageEnhancementConfig): Record<string, unknown> {
50
+ return {
120
51
  enhancementType: config.enhancementType,
52
+ intensity: config.intensity,
53
+ preserveNatural: config.preserveNatural,
54
+ autoAdjust: config.autoAdjust,
121
55
  targetStyle: config.targetStyle,
122
- });
56
+ adjustments: this.calculateAdjustments(config),
57
+ };
58
+ }
123
59
 
124
- return createAIPromptTemplate({
125
- id: templateId,
60
+ protected createTemplate(config: ImageEnhancementConfig): AIPromptTemplate {
61
+ return this.createTemplateWithDefaults({
62
+ id: `image-enhancement-${config.enhancementType}`,
126
63
  name: `Image Enhancement: ${config.enhancementType}`,
127
64
  description: `Enhance images with ${config.enhancementType} improvements`,
128
65
  category: 'image-enhancement',
129
- template: `${baseTemplate}
66
+ template: `${BASE_TEMPLATE}
130
67
 
131
- ENHANCEMENT TYPE:
132
- ${config.enhancementType}
133
-
134
- STYLE TARGET:
135
- ${config.targetStyle}
136
-
137
- ADJUSTMENT PARAMETERS:
138
- - Intensity Level: ${Math.round(config.intensity * 100)}%
139
- - Preserve Natural: ${config.preserveNatural}
140
- - Auto Adjust: ${config.autoAdjust}
141
- - Target Style: ${config.targetStyle}
142
-
143
- SPECIFIC ENHANCEMENTS:
144
- ${this.getSpecificEnhancements(config)}
145
-
146
- EXPECTED RESULT:
147
- Professional ${config.enhancementType} enhancement
148
- with ${config.targetStyle} presentation style,
149
- maintaining authenticity while improving quality.
150
- `.trim(),
151
- variables: [],
152
- safety: {
153
- contentFilter: true,
154
- adultContentFilter: true,
155
- violenceFilter: true,
156
- hateSpeechFilter: true,
157
- copyrightFilter: true,
158
- },
159
- version: '1.0.0',
68
+ TYPE: ${config.enhancementType}
69
+ STYLE: ${config.targetStyle}
70
+ INTENSITY: ${Math.round(config.intensity * 100)}%
71
+ PRESERVE NATURAL: ${config.preserveNatural}
72
+ AUTO ADJUST: ${config.autoAdjust}`,
160
73
  });
161
74
  }
162
-
163
- private getSpecificEnhancements(config: ImageEnhancementConfig): string {
164
- const enhancements: string[] = [];
165
-
166
- if (config.enhancementType === 'brightness' || config.enhancementType === 'all') {
167
- enhancements.push('- Brightness optimization for perfect exposure');
168
- }
169
- if (config.enhancementType === 'contrast' || config.enhancementType === 'all') {
170
- enhancements.push('- Contrast enhancement for dynamic range');
171
- }
172
- if (config.enhancementType === 'saturation' || config.enhancementType === 'all') {
173
- enhancements.push('- Saturation adjustment for color vibrancy');
174
- }
175
- if (config.enhancementType === 'sharpness' || config.enhancementType === 'all') {
176
- enhancements.push('- Sharpness improvement for detail clarity');
177
- }
178
-
179
- return enhancements.join('\n') || '- General image quality improvement';
180
- }
181
- }
75
+ }
@@ -1,23 +1,15 @@
1
1
  /**
2
- * ImagePromptBuilder
3
- * Fluent builder for composing AI image generation prompts
4
- *
5
- * @example
6
- * const { prompt, negativePrompt } = ImagePromptBuilder.create()
7
- * .withIdentityPreservation()
8
- * .withAnimeStyle()
9
- * .withQuality()
10
- * .build();
2
+ * ImagePromptBuilder - Fluent builder for composing AI image generation prompts
11
3
  */
12
4
 
13
5
  import {
6
+ IDENTITY_SEGMENTS,
14
7
  IDENTITY_NEGATIVE_SEGMENTS,
15
8
  ANIME_STYLE_SEGMENTS,
16
9
  QUALITY_SEGMENTS,
17
10
  QUALITY_NEGATIVE_SEGMENTS,
18
11
  ANTI_REALISM_SEGMENTS,
19
12
  ANATOMY_NEGATIVE_SEGMENTS,
20
- PRESET_COLLECTIONS,
21
13
  } from "../../domain/entities/image-prompt-segments";
22
14
 
23
15
  export interface ImagePromptResult {
@@ -25,6 +17,12 @@ export interface ImagePromptResult {
25
17
  negativePrompt: string;
26
18
  }
27
19
 
20
+ export interface AnimeSelfiePromptResult extends ImagePromptResult {
21
+ strength: number;
22
+ guidance_scale: number;
23
+ num_inference_steps: number;
24
+ }
25
+
28
26
  export interface ImagePromptBuilderOptions {
29
27
  separator?: string;
30
28
  }
@@ -46,15 +44,10 @@ export class ImagePromptBuilder {
46
44
  }
47
45
 
48
46
  /**
49
- * Add identity preservation prompts
50
- * Ensures the AI preserves the original person's features
47
+ * Add identity preservation prompts - ensures AI preserves original person's features
51
48
  */
52
- withIdentityPreservation(full = true): this {
53
- const segments = full
54
- ? PRESET_COLLECTIONS.fullIdentityPreservation
55
- : PRESET_COLLECTIONS.basicIdentityPreservation;
56
-
57
- this.positiveSegments.push(...segments);
49
+ withIdentityPreservation(): this {
50
+ this.positiveSegments.push(...Object.values(IDENTITY_SEGMENTS));
58
51
  this.negativeSegments.push(...Object.values(IDENTITY_NEGATIVE_SEGMENTS));
59
52
  return this;
60
53
  }
@@ -172,28 +165,38 @@ export class ImagePromptBuilder {
172
165
  }
173
166
  }
174
167
 
175
- // =============================================================================
176
- // PRESET BUILDERS
177
- // =============================================================================
178
-
179
168
  /**
180
- * Create an anime selfie prompt builder with identity preservation
169
+ * Create anime selfie prompt with recommended parameters
170
+ * IMPORTANT: Anime style FIRST (highest priority), identity preservation secondary
181
171
  */
182
- export function createAnimeSelfiePrompt(): ImagePromptResult {
183
- return ImagePromptBuilder.create()
184
- .withIdentityPreservation()
185
- .withAnimeStyle()
186
- .withAnatomySafety()
187
- .build();
172
+ export function createAnimeSelfiePrompt(customStyle?: string): AnimeSelfiePromptResult {
173
+ const builder = ImagePromptBuilder.create()
174
+ .withAnimeStyle() // Anime style FIRST - highest priority
175
+ .withIdentityPreservation() // Identity preservation secondary
176
+ .withAnatomySafety();
177
+
178
+ if (customStyle) {
179
+ builder.prependSegments([`${customStyle} style`]);
180
+ }
181
+
182
+ const { prompt, negativePrompt } = builder.build();
183
+
184
+ return {
185
+ prompt,
186
+ negativePrompt,
187
+ strength: 0.92, // High strength for style transformation
188
+ guidance_scale: 8.5, // Strong guidance for anime style
189
+ num_inference_steps: 50, // More steps for quality
190
+ };
188
191
  }
189
192
 
190
193
  /**
191
- * Create a style transfer prompt builder with identity preservation
194
+ * Create a style transfer prompt with identity preservation
192
195
  */
193
196
  export function createStyleTransferPrompt(style: string): ImagePromptResult {
194
197
  return ImagePromptBuilder.create()
198
+ .withSegment(`${style} style`) // Style first
195
199
  .withIdentityPreservation()
196
- .withSegment(`${style} style`)
197
200
  .withQuality()
198
201
  .withAnatomySafety()
199
202
  .build();
@@ -1,90 +1,52 @@
1
+ /**
2
+ * Photo Restoration Service
3
+ * AI prompt generation for photo restoration tasks
4
+ */
5
+
1
6
  import type { IPhotoRestorationService } from '../../domain/repositories/IAIPromptServices';
2
- import type {
3
- PhotoRestorationConfig,
4
- } from '../../domain/entities/PhotoRestorationConfig';
7
+ import type { PhotoRestorationConfig } from '../../domain/entities/PhotoRestorationConfig';
5
8
  import type { AIPromptTemplate } from '../../domain/entities/AIPromptTemplate';
6
- import type { AIPromptResult } from '../../domain/entities/types';
7
- import { createAIPromptTemplate } from '../../domain/entities/AIPromptTemplate';
8
9
  import { validatePhotoRestorationConfig, getQualityLevel } from '../../domain/entities/PhotoRestorationConfig';
9
- import { PromptGenerationService } from '../services/PromptGenerationService';
10
-
11
- const createPhotoRestorationBaseTemplate = (config?: {
12
- targetQuality?: string;
13
- preserveOriginal?: boolean;
14
- }): string => {
15
- const {
16
- targetQuality = 'high-quality',
17
- preserveOriginal = true
18
- } = config || {};
10
+ import { BasePromptService } from './base';
19
11
 
20
- return `
12
+ const BASE_TEMPLATE = `
21
13
  You are an expert AI photo restoration specialist.
22
14
  This is a PHOTO RESTORATION task, not image generation.
23
15
 
24
- RESTORATION OBJECTIVES:
25
- - Restore the original photo to ${targetQuality} condition
26
- - ${preserveOriginal ? 'Preserve the original content and composition' : 'Enhance with creative improvements'}
27
- - Remove imperfections while maintaining authenticity
28
- - Recover lost details and enhance overall quality
29
-
30
16
  RESTORATION TECHNIQUES:
31
17
  - Noise reduction and grain removal
32
18
  - Scratch and damage repair
33
19
  - Color correction and enhancement
34
20
  - Detail sharpening and clarity improvement
35
- - Exposure and contrast adjustment
36
21
 
37
22
  SAFETY CONSTRAINTS:
38
23
  - Do not add content that wasn't originally present
39
24
  - Maintain the original subject and composition
40
- - Avoid over-processing that creates unnatural results
41
25
  - Preserve important details and textures
42
-
43
- QUALITY STANDARDS:
44
- - Natural, authentic appearance
45
- - Balanced color reproduction
46
- - Appropriate level of detail enhancement
47
- - Clean, professional-grade result
48
-
49
- OUTPUT:
50
- A beautifully restored version of the original photo,
51
- maintaining its character while significantly improving quality.
52
- `.trim();
53
- };
54
-
55
- export class PhotoRestorationService implements IPhotoRestorationService {
56
- private promptService: PromptGenerationService;
57
-
58
- constructor() {
59
- this.promptService = new PromptGenerationService();
26
+ `.trim();
27
+
28
+ export class PhotoRestorationService
29
+ extends BasePromptService<PhotoRestorationConfig>
30
+ implements IPhotoRestorationService
31
+ {
32
+ protected getServiceName(): string {
33
+ return 'photo restoration';
60
34
  }
61
35
 
62
- generateTemplate(config: PhotoRestorationConfig): Promise<AIPromptResult<AIPromptTemplate>> {
63
- try {
64
- if (!this.validateConfig(config)) {
65
- return Promise.resolve({
66
- success: false,
67
- error: 'VALIDATION_ERROR',
68
- message: 'Invalid photo restoration configuration'
69
- });
70
- }
36
+ validateConfig(config: PhotoRestorationConfig): boolean {
37
+ return validatePhotoRestorationConfig(config);
38
+ }
71
39
 
72
- const template = this.createPhotoRestorationTemplate(config);
73
- return Promise.resolve({ success: true, data: template });
74
- } catch {
75
- return Promise.resolve({
76
- success: false,
77
- error: 'GENERATION_FAILED',
78
- message: 'Failed to generate photo restoration template'
79
- });
80
- }
40
+ estimateQuality(config: PhotoRestorationConfig): number {
41
+ let quality = 0.8;
42
+ if (config.restoreDetails) quality += 0.1;
43
+ if (config.enhanceColors) quality += 0.05;
44
+ if (config.removeNoise) quality += 0.05;
45
+ return Math.min(quality * getQualityLevel(config.severity), 1.0);
81
46
  }
82
47
 
83
- async generatePrompt(
84
- template: AIPromptTemplate,
85
- config: PhotoRestorationConfig
86
- ): Promise<AIPromptResult<string>> {
87
- const variables = {
48
+ protected buildVariables(config: PhotoRestorationConfig): Record<string, unknown> {
49
+ return {
88
50
  severity: config.severity,
89
51
  preserveOriginal: config.preserveOriginal,
90
52
  enhanceColors: config.enhanceColors,
@@ -93,68 +55,28 @@ export class PhotoRestorationService implements IPhotoRestorationService {
93
55
  restoreDetails: config.restoreDetails,
94
56
  qualityLevel: getQualityLevel(config.severity),
95
57
  };
96
-
97
- return this.promptService.generateFromTemplate(template, variables);
98
- }
99
-
100
- validateConfig(config: PhotoRestorationConfig): boolean {
101
- return validatePhotoRestorationConfig(config);
102
58
  }
103
59
 
104
- estimateQuality(config: PhotoRestorationConfig): number {
105
- let quality = 0.8;
106
-
107
- if (config.restoreDetails) quality += 0.1;
108
- if (config.enhanceColors) quality += 0.05;
109
- if (config.removeNoise) quality += 0.05;
60
+ protected createTemplate(config: PhotoRestorationConfig): AIPromptTemplate {
61
+ const qualityDesc =
62
+ config.severity === 'minor' ? 'subtle' :
63
+ config.severity === 'moderate' ? 'standard' : 'deep';
110
64
 
111
- const severityMultiplier = getQualityLevel(config.severity);
112
- return Math.min(quality * severityMultiplier, 1.0);
113
- }
114
-
115
- private createPhotoRestorationTemplate(config: PhotoRestorationConfig): AIPromptTemplate {
116
- const templateId = `photo-restoration-${config.severity}`;
117
- const qualityDesc = config.severity === 'minor' ? 'subtle restoration' :
118
- config.severity === 'moderate' ? 'standard restoration' :
119
- 'deep restoration';
120
-
121
- const baseTemplate = createPhotoRestorationBaseTemplate({
122
- targetQuality: qualityDesc,
123
- preserveOriginal: config.preserveOriginal,
124
- });
125
-
126
- return createAIPromptTemplate({
127
- id: templateId,
65
+ return this.createTemplateWithDefaults({
66
+ id: `photo-restoration-${config.severity}`,
128
67
  name: `Photo Restoration: ${config.severity}`,
129
- description: `Restore photos with ${qualityDesc}`,
68
+ description: `Restore photos with ${qualityDesc} restoration`,
130
69
  category: 'photo-restoration',
131
- template: `${baseTemplate}
132
-
133
- RESTORATION SEVERITY:
134
- ${config.severity}
135
-
136
- SPECIFIC REQUIREMENTS:
137
- - ${config.removeNoise ? 'Remove noise and grain' : 'Maintain texture character'}
138
- - ${config.fixBlur ? 'Fix blur and sharpen details' : 'Preserve original sharpness'}
139
- - ${config.enhanceColors ? 'Enhance color vibrancy' : 'Maintain original colors'}
140
- - ${config.restoreDetails ? 'Recover lost details' : 'Preserve current detail level'}
70
+ template: `${BASE_TEMPLATE}
141
71
 
142
- QUALITY TARGET:
143
- ${getQualityLevel(config.severity) * 100}% quality improvement expected.
72
+ SEVERITY: ${config.severity}
73
+ REQUIREMENTS:
74
+ - ${config.removeNoise ? 'Remove noise' : 'Maintain texture'}
75
+ - ${config.fixBlur ? 'Fix blur' : 'Preserve sharpness'}
76
+ - ${config.enhanceColors ? 'Enhance colors' : 'Maintain colors'}
77
+ - ${config.restoreDetails ? 'Recover details' : 'Preserve detail level'}
144
78
 
145
- OUTPUT:
146
- A professionally restored photo with ${qualityDesc},
147
- ready for display or further processing.
148
- `.trim(),
149
- variables: [],
150
- safety: {
151
- contentFilter: true,
152
- adultContentFilter: true,
153
- violenceFilter: true,
154
- hateSpeechFilter: true,
155
- copyrightFilter: true,
156
- },
157
- version: '1.0.0',
79
+ QUALITY TARGET: ${Math.round(getQualityLevel(config.severity) * 100)}%`,
158
80
  });
159
81
  }
160
- }
82
+ }