@umituz/react-native-ai-generation-content 1.12.1 → 1.12.3
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.
- package/package.json +6 -2
- package/src/domains/prompts/domain/entities/AIPromptTemplate.ts +48 -0
- package/src/domains/prompts/domain/entities/BackgroundRemovalConfig.ts +86 -0
- package/src/domains/prompts/domain/entities/ColorizationConfig.ts +101 -0
- package/src/domains/prompts/domain/entities/FaceSwapConfig.ts +54 -0
- package/src/domains/prompts/domain/entities/FuturePredictionConfig.ts +93 -0
- package/src/domains/prompts/domain/entities/GeneratedPrompt.ts +32 -0
- package/src/domains/prompts/domain/entities/ImageEnhancementConfig.ts +93 -0
- package/src/domains/prompts/domain/entities/PhotoRestorationConfig.ts +64 -0
- package/src/domains/prompts/domain/entities/StyleTransferConfig.ts +80 -0
- package/src/domains/prompts/domain/entities/TextGenerationConfig.ts +100 -0
- package/src/domains/prompts/domain/entities/types.ts +27 -0
- package/src/domains/prompts/domain/entities/value-objects.ts +33 -0
- package/src/domains/prompts/domain/repositories/IAIPromptServices.ts +106 -0
- package/src/domains/prompts/domain/repositories/IPromptHistoryRepository.ts +10 -0
- package/src/domains/prompts/domain/repositories/ITemplateRepository.ts +11 -0
- package/src/domains/prompts/index.ts +318 -0
- package/src/domains/prompts/infrastructure/repositories/PromptHistoryRepository.ts +85 -0
- package/src/domains/prompts/infrastructure/repositories/TemplateRepository.ts +77 -0
- package/src/domains/prompts/infrastructure/services/BackgroundRemovalService.ts +209 -0
- package/src/domains/prompts/infrastructure/services/ColorizationService.ts +232 -0
- package/src/domains/prompts/infrastructure/services/FaceSwapService.ts +198 -0
- package/src/domains/prompts/infrastructure/services/FuturePredictionService.ts +176 -0
- package/src/domains/prompts/infrastructure/services/ImageEnhancementService.ts +181 -0
- package/src/domains/prompts/infrastructure/services/PhotoRestorationService.ts +160 -0
- package/src/domains/prompts/infrastructure/services/PromptGenerationService.ts +59 -0
- package/src/domains/prompts/infrastructure/services/StyleTransferService.ts +194 -0
- package/src/domains/prompts/infrastructure/services/TextGenerationService.ts +241 -0
- package/src/domains/prompts/presentation/hooks/useAIServices.ts +213 -0
- package/src/domains/prompts/presentation/hooks/useAsyncState.ts +56 -0
- package/src/domains/prompts/presentation/hooks/useFaceSwap.ts +100 -0
- package/src/domains/prompts/presentation/hooks/useImageEnhancement.ts +100 -0
- package/src/domains/prompts/presentation/hooks/usePhotoRestoration.ts +100 -0
- package/src/domains/prompts/presentation/hooks/usePromptGeneration.ts +144 -0
- package/src/domains/prompts/presentation/hooks/useStyleTransfer.ts +125 -0
- package/src/domains/prompts/presentation/hooks/useTemplateRepository.ts +113 -0
- package/src/domains/prompts/presentation/theme/theme.ts +16 -0
- package/src/domains/prompts/presentation/theme/types.ts +82 -0
- package/src/domains/prompts/presentation/theme/utils.ts +24 -0
- package/src/index.ts +6 -0
- package/src/presentation/components/GenerationProgressContent.tsx +3 -3
- package/src/presentation/components/PendingJobCard.tsx +4 -4
- package/src/presentation/components/PendingJobCardActions.tsx +2 -2
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import type { IFaceSwapService } from '../../domain/repositories/IAIPromptServices';
|
|
2
|
+
import type {
|
|
3
|
+
AIPromptTemplate
|
|
4
|
+
} from '../../domain/entities/AIPromptTemplate';
|
|
5
|
+
import type {
|
|
6
|
+
FaceSwapConfig,
|
|
7
|
+
FaceSwapGenerationResult,
|
|
8
|
+
FaceSwapSafety
|
|
9
|
+
} from '../../domain/entities/FaceSwapConfig';
|
|
10
|
+
import type { AIPromptCategory } from '../../domain/entities/types';
|
|
11
|
+
import { createAIPromptTemplate } from '../../domain/entities/AIPromptTemplate';
|
|
12
|
+
import { validateFaceSwapConfig } from '../../domain/entities/FaceSwapConfig';
|
|
13
|
+
import type { AIPromptResult } from '../../domain/entities/types';
|
|
14
|
+
import { PromptGenerationService } from '../services/PromptGenerationService';
|
|
15
|
+
|
|
16
|
+
const DEFAULT_FACE_SWAP_SAFETY: FaceSwapSafety = {
|
|
17
|
+
contentFilter: true,
|
|
18
|
+
identityPreservation: true,
|
|
19
|
+
adultContentFilter: true,
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const createFaceSwapBaseTemplate = (config?: {
|
|
23
|
+
targetPerson?: string;
|
|
24
|
+
transformationType?: string;
|
|
25
|
+
quality?: string;
|
|
26
|
+
}): string => {
|
|
27
|
+
const {
|
|
28
|
+
targetPerson = 'SAME PERSON',
|
|
29
|
+
transformationType = 'transformation',
|
|
30
|
+
quality = 'App Store–ready'
|
|
31
|
+
} = config || {};
|
|
32
|
+
|
|
33
|
+
return `
|
|
34
|
+
You are an expert AI photo editor.
|
|
35
|
+
This is a PHOTO EDITING task, not text-to-image generation.
|
|
36
|
+
|
|
37
|
+
IDENTITY PRESERVATION (CRITICAL):
|
|
38
|
+
The output must clearly depict the ${targetPerson} from the uploaded photo.
|
|
39
|
+
The person must remain recognizable after transformation.
|
|
40
|
+
|
|
41
|
+
FACE IDENTITY (DO NOT CHANGE):
|
|
42
|
+
- Facial bone structure and proportions
|
|
43
|
+
- Eye shape and eye color
|
|
44
|
+
- Nose shape and size
|
|
45
|
+
- Lip shape and proportions
|
|
46
|
+
- Skin tone and natural facial texture
|
|
47
|
+
|
|
48
|
+
ALLOWED NON-DESTRUCTIVE CHANGES:
|
|
49
|
+
- Hair style and hair color (wig-like or costume-based)
|
|
50
|
+
- Facial hair (beard, mustache) as costume elements
|
|
51
|
+
- Accessories (hats, glasses, headwear)
|
|
52
|
+
- Subtle expression adjustments that do NOT alter facial structure
|
|
53
|
+
- Costume makeup that does NOT reshape the face
|
|
54
|
+
|
|
55
|
+
STRICTLY FORBIDDEN:
|
|
56
|
+
- Face replacement or face swapping with another identity
|
|
57
|
+
- Changing the person into a different real individual
|
|
58
|
+
- Changing gender or ethnicity
|
|
59
|
+
- Extreme age transformation
|
|
60
|
+
- Distorted faces or unrealistic anatomy
|
|
61
|
+
|
|
62
|
+
SAFETY CONSTRAINTS:
|
|
63
|
+
Do NOT add nudity, sexual content, violence, weapons, drugs, political or religious symbols,
|
|
64
|
+
copyrighted characters, celebrities, text overlays, logos, or watermarks.
|
|
65
|
+
|
|
66
|
+
STYLE & QUALITY:
|
|
67
|
+
- Realistic photographic style
|
|
68
|
+
- High-quality, natural lighting
|
|
69
|
+
- Clean, premium, ${quality} result
|
|
70
|
+
|
|
71
|
+
FINAL RULE:
|
|
72
|
+
This is a fictional, cosmetic ${transformationType} for entertainment only.
|
|
73
|
+
`.trim();
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
export class FaceSwapService implements IFaceSwapService {
|
|
77
|
+
private promptService: PromptGenerationService;
|
|
78
|
+
private availableStyles: string[] = [];
|
|
79
|
+
|
|
80
|
+
constructor() {
|
|
81
|
+
this.promptService = new PromptGenerationService();
|
|
82
|
+
this.initializeDefaultStyles();
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
async generateTemplate(config: FaceSwapConfig): Promise<AIPromptResult<AIPromptTemplate>> {
|
|
86
|
+
try {
|
|
87
|
+
if (!this.validateConfig(config)) {
|
|
88
|
+
return {
|
|
89
|
+
success: false,
|
|
90
|
+
error: 'INVALID_VARIABLES',
|
|
91
|
+
message: 'Invalid face swap configuration'
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const template = this.createFaceSwapTemplate(config);
|
|
96
|
+
return { success: true, data: template };
|
|
97
|
+
} catch (error) {
|
|
98
|
+
return {
|
|
99
|
+
success: false,
|
|
100
|
+
error: 'GENERATION_FAILED',
|
|
101
|
+
message: 'Failed to generate face swap template'
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
async generatePrompt(
|
|
107
|
+
template: AIPromptTemplate,
|
|
108
|
+
config: FaceSwapConfig
|
|
109
|
+
): Promise<AIPromptResult<string>> {
|
|
110
|
+
const variables = {
|
|
111
|
+
styleName: config.styleName,
|
|
112
|
+
environment: config.environment || 'Neutral studio background',
|
|
113
|
+
preserveIdentity: config.preserveIdentity,
|
|
114
|
+
allowHairStyle: config.allowHairStyle,
|
|
115
|
+
allowAccessories: config.allowAccessories,
|
|
116
|
+
allowExpression: config.allowExpression,
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
return this.promptService.generateFromTemplate(template, variables);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
validateConfig(config: FaceSwapConfig): boolean {
|
|
123
|
+
return validateFaceSwapConfig(config);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
async getAvailableStyles(): Promise<string[]> {
|
|
127
|
+
return Promise.resolve([...this.availableStyles]);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
private initializeDefaultStyles(): void {
|
|
131
|
+
this.availableStyles = [];
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
public registerStyle(style: string): void {
|
|
135
|
+
if (!this.availableStyles.includes(style)) {
|
|
136
|
+
this.availableStyles.push(style);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
public registerStyles(styles: string[]): void {
|
|
141
|
+
styles.forEach(style => this.registerStyle(style));
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
public clearStyles(): void {
|
|
145
|
+
this.availableStyles = [];
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
private createFaceSwapTemplate(config: FaceSwapConfig): AIPromptTemplate {
|
|
149
|
+
const templateId = `face-swap-${config.styleName.toLowerCase().replace(/\s+/g, '-')}`;
|
|
150
|
+
|
|
151
|
+
return createAIPromptTemplate({
|
|
152
|
+
id: templateId,
|
|
153
|
+
name: `Face Swap: ${config.styleName}`,
|
|
154
|
+
description: `Transform face into ${config.styleName} style`,
|
|
155
|
+
category: 'face-swap' as AIPromptCategory,
|
|
156
|
+
template: this.buildFaceSwapTemplate(config),
|
|
157
|
+
variables: [],
|
|
158
|
+
safety: {
|
|
159
|
+
contentFilter: DEFAULT_FACE_SWAP_SAFETY.contentFilter,
|
|
160
|
+
adultContentFilter: DEFAULT_FACE_SWAP_SAFETY.adultContentFilter,
|
|
161
|
+
violenceFilter: true,
|
|
162
|
+
hateSpeechFilter: true,
|
|
163
|
+
copyrightFilter: true,
|
|
164
|
+
},
|
|
165
|
+
version: '1.0.0',
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
private buildFaceSwapTemplate(config: FaceSwapConfig): string {
|
|
170
|
+
const baseTemplate = createFaceSwapBaseTemplate({
|
|
171
|
+
targetPerson: 'SAME PERSON',
|
|
172
|
+
transformationType: 'transformation',
|
|
173
|
+
quality: 'App Store–ready',
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
return `${baseTemplate}
|
|
177
|
+
|
|
178
|
+
STYLE NAME:
|
|
179
|
+
${config.styleName}
|
|
180
|
+
|
|
181
|
+
TRANSFORMATION GOAL:
|
|
182
|
+
Transform the same person into this ${config.styleName} style
|
|
183
|
+
${config.preserveIdentity ? 'while preserving their facial identity.' : ''}
|
|
184
|
+
|
|
185
|
+
ENVIRONMENT:
|
|
186
|
+
${config.environment || 'Neutral studio background'}
|
|
187
|
+
|
|
188
|
+
EXPRESSION:
|
|
189
|
+
- Natural expression
|
|
190
|
+
- Subtle and natural, without changing facial structure
|
|
191
|
+
|
|
192
|
+
OUTPUT:
|
|
193
|
+
The same person from the uploaded photo,
|
|
194
|
+
clearly recognizable,
|
|
195
|
+
realistically transformed into a ${config.styleName} style.
|
|
196
|
+
`.trim();
|
|
197
|
+
}
|
|
198
|
+
}
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import type { IFuturePredictionService } from '../../domain/repositories/IAIPromptServices';
|
|
2
|
+
import type { AIPromptTemplate } from '../../domain/entities/AIPromptTemplate';
|
|
3
|
+
import type { AIPromptResult } from '../../domain/entities/types';
|
|
4
|
+
import type {
|
|
5
|
+
FuturePredictionConfig,
|
|
6
|
+
FuturePredictionResult,
|
|
7
|
+
} from '../../domain/entities/FuturePredictionConfig';
|
|
8
|
+
import { createAIPromptTemplate } from '../../domain/entities/AIPromptTemplate';
|
|
9
|
+
import {
|
|
10
|
+
validateFuturePredictionConfig,
|
|
11
|
+
getFutureYear,
|
|
12
|
+
} from '../../domain/entities/FuturePredictionConfig';
|
|
13
|
+
import { PromptGenerationService } from './PromptGenerationService';
|
|
14
|
+
|
|
15
|
+
const IMAGE_PROMPT_TEMPLATE = `
|
|
16
|
+
Generate a single high-quality, photorealistic image of {{subjectA}}{{#if subjectB}} and {{subjectB}}{{/if}}.
|
|
17
|
+
Role/Relationship: {{subjectRole}}
|
|
18
|
+
Context/Scenario: {{scenarioTitle}}
|
|
19
|
+
Additional Details: {{promptModifier}}
|
|
20
|
+
|
|
21
|
+
Requirements:
|
|
22
|
+
- Maintain facial identity and key features of the individual(s) provided in input images.
|
|
23
|
+
- Ensure lighting, environment, and skin tones are realistic and consistent.
|
|
24
|
+
- Style: High detail, professional photography, 4k resolution.
|
|
25
|
+
- No text, watermarks, or artificial artifacts.
|
|
26
|
+
`.trim();
|
|
27
|
+
|
|
28
|
+
const STORY_PROMPT_TEMPLATE = `
|
|
29
|
+
Write a short, engaging, and evocative description for a future scene.
|
|
30
|
+
Subjects: {{subjectA}}{{#if subjectB}} and {{subjectB}}{{/if}}
|
|
31
|
+
Role: {{subjectRole}}
|
|
32
|
+
Scenario: {{scenarioTitle}}
|
|
33
|
+
Atmosphere/Tone: {{tone}}
|
|
34
|
+
Context: {{promptModifier}}
|
|
35
|
+
Imaginary Year: {{futureYear}}
|
|
36
|
+
|
|
37
|
+
Style:
|
|
38
|
+
- 2-3 sentences max.
|
|
39
|
+
- Be vivid and imaginative.
|
|
40
|
+
- Do not use hashtags.
|
|
41
|
+
{{#if language}}Please respond in {{language}} language.{{/if}}
|
|
42
|
+
`.trim();
|
|
43
|
+
|
|
44
|
+
export class FuturePredictionService implements IFuturePredictionService {
|
|
45
|
+
private promptService: PromptGenerationService;
|
|
46
|
+
|
|
47
|
+
constructor() {
|
|
48
|
+
this.promptService = new PromptGenerationService();
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
async generateTemplate(
|
|
52
|
+
config: FuturePredictionConfig
|
|
53
|
+
): Promise<AIPromptResult<AIPromptTemplate>> {
|
|
54
|
+
if (!this.validateConfig(config)) {
|
|
55
|
+
return {
|
|
56
|
+
success: false,
|
|
57
|
+
error: 'VALIDATION_ERROR',
|
|
58
|
+
message: 'Invalid future prediction configuration',
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const template = this.createTemplate(config);
|
|
63
|
+
return { success: true, data: template };
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
async generatePrompts(
|
|
67
|
+
config: FuturePredictionConfig
|
|
68
|
+
): Promise<AIPromptResult<FuturePredictionResult>> {
|
|
69
|
+
if (!this.validateConfig(config)) {
|
|
70
|
+
return {
|
|
71
|
+
success: false,
|
|
72
|
+
error: 'VALIDATION_ERROR',
|
|
73
|
+
message: 'Invalid configuration',
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const imagePrompt = this.buildImagePrompt(config);
|
|
78
|
+
const storyPrompt = this.buildStoryPrompt(config);
|
|
79
|
+
|
|
80
|
+
return {
|
|
81
|
+
success: true,
|
|
82
|
+
data: {
|
|
83
|
+
imagePrompt,
|
|
84
|
+
storyPrompt,
|
|
85
|
+
metadata: {
|
|
86
|
+
scenarioId: config.scenarioId,
|
|
87
|
+
personCount: config.settings.personCount,
|
|
88
|
+
language: config.settings.language,
|
|
89
|
+
generatedAt: Date.now(),
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
validateConfig(config: FuturePredictionConfig): boolean {
|
|
96
|
+
return validateFuturePredictionConfig(config);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
buildImagePrompt(config: FuturePredictionConfig): string {
|
|
100
|
+
const subjectRole = config.settings.subjectRole || 'individuals';
|
|
101
|
+
|
|
102
|
+
return IMAGE_PROMPT_TEMPLATE
|
|
103
|
+
.replace(/{{subjectA}}/g, config.subjectA)
|
|
104
|
+
.replace(/{{subjectB}}/g, config.subjectB || '')
|
|
105
|
+
.replace(/{{#if subjectB}} and {{subjectB}}{{\/if}}/g, config.subjectB ? ` and ${config.subjectB}` : '')
|
|
106
|
+
.replace(/{{subjectRole}}/g, subjectRole)
|
|
107
|
+
.replace(/{{scenarioTitle}}/g, config.scenarioTitle)
|
|
108
|
+
.replace(/{{promptModifier}}/g, config.promptModifier);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
buildStoryPrompt(config: FuturePredictionConfig): string {
|
|
112
|
+
const futureYear = config.settings.year || getFutureYear();
|
|
113
|
+
const tone = config.settings.tone || 'neutral';
|
|
114
|
+
const subjectRole = config.settings.subjectRole || 'individuals';
|
|
115
|
+
|
|
116
|
+
let prompt = STORY_PROMPT_TEMPLATE
|
|
117
|
+
.replace(/{{subjectA}}/g, config.subjectA)
|
|
118
|
+
.replace(/{{subjectB}}/g, config.subjectB || '')
|
|
119
|
+
.replace(/{{#if subjectB}} and {{subjectB}}{{\/if}}/g, config.subjectB ? ` and ${config.subjectB}` : '')
|
|
120
|
+
.replace(/{{subjectRole}}/g, subjectRole)
|
|
121
|
+
.replace(/{{scenarioTitle}}/g, config.scenarioTitle)
|
|
122
|
+
.replace(/{{tone}}/g, tone)
|
|
123
|
+
.replace(/{{promptModifier}}/g, config.promptModifier)
|
|
124
|
+
.replace(/{{futureYear}}/g, String(futureYear));
|
|
125
|
+
|
|
126
|
+
if (config.settings.language && config.settings.language !== 'en') {
|
|
127
|
+
prompt = prompt.replace(
|
|
128
|
+
/{{#if language}}(.*?){{\/if}}/g,
|
|
129
|
+
`$1`.replace(/{{language}}/g, this.getLanguageName(config.settings.language))
|
|
130
|
+
);
|
|
131
|
+
} else {
|
|
132
|
+
prompt = prompt.replace(/{{#if language}}.*?{{\/if}}/g, '');
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
return prompt.trim();
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
private createTemplate(config: FuturePredictionConfig): AIPromptTemplate {
|
|
139
|
+
return createAIPromptTemplate({
|
|
140
|
+
id: `future-prediction-${config.scenarioId}`,
|
|
141
|
+
name: `Future Prediction: ${config.scenarioTitle}`,
|
|
142
|
+
description: `Generate future prediction for ${config.scenarioId} scenario`,
|
|
143
|
+
category: 'future-prediction',
|
|
144
|
+
template: this.buildImagePrompt(config),
|
|
145
|
+
variables: [],
|
|
146
|
+
safety: {
|
|
147
|
+
contentFilter: true,
|
|
148
|
+
adultContentFilter: true,
|
|
149
|
+
violenceFilter: true,
|
|
150
|
+
hateSpeechFilter: true,
|
|
151
|
+
copyrightFilter: true,
|
|
152
|
+
},
|
|
153
|
+
version: '1.0.0',
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
private getLanguageName(code: string): string {
|
|
158
|
+
const languages: Record<string, string> = {
|
|
159
|
+
tr: 'Turkish',
|
|
160
|
+
es: 'Spanish',
|
|
161
|
+
fr: 'French',
|
|
162
|
+
de: 'German',
|
|
163
|
+
it: 'Italian',
|
|
164
|
+
pt: 'Portuguese',
|
|
165
|
+
ru: 'Russian',
|
|
166
|
+
ja: 'Japanese',
|
|
167
|
+
ko: 'Korean',
|
|
168
|
+
zh: 'Chinese',
|
|
169
|
+
ar: 'Arabic',
|
|
170
|
+
hi: 'Hindi',
|
|
171
|
+
th: 'Thai',
|
|
172
|
+
vi: 'Vietnamese',
|
|
173
|
+
};
|
|
174
|
+
return languages[code] || 'English';
|
|
175
|
+
}
|
|
176
|
+
}
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import type { IImageEnhancementService } from '../../domain/repositories/IAIPromptServices';
|
|
2
|
+
import type {
|
|
3
|
+
ImageEnhancementConfig,
|
|
4
|
+
EnhancementAdjustments,
|
|
5
|
+
} from '../../domain/entities/ImageEnhancementConfig';
|
|
6
|
+
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 || {};
|
|
23
|
+
|
|
24
|
+
return `
|
|
25
|
+
You are an expert AI image enhancement specialist.
|
|
26
|
+
This is an IMAGE ENHANCEMENT task, not image generation.
|
|
27
|
+
|
|
28
|
+
ENHANCEMENT GOAL:
|
|
29
|
+
Apply ${enhancementType} improvements with ${targetStyle} appearance
|
|
30
|
+
while preserving the original content and composition.
|
|
31
|
+
|
|
32
|
+
ENHANCEMENT PRINCIPLES:
|
|
33
|
+
- Maintain natural appearance and authenticity
|
|
34
|
+
- Apply subtle, professional-grade adjustments
|
|
35
|
+
- Preserve important details and textures
|
|
36
|
+
- Avoid over-processing or artificial results
|
|
37
|
+
|
|
38
|
+
TECHNICAL REQUIREMENTS:
|
|
39
|
+
- Proper exposure and brightness correction
|
|
40
|
+
- Optimal contrast and dynamic range
|
|
41
|
+
- Natural color balance and saturation
|
|
42
|
+
- 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
|
+
|
|
51
|
+
SAFETY CONSTRAINTS:
|
|
52
|
+
- Do not alter the subject or composition
|
|
53
|
+
- Preserve skin tones and natural colors
|
|
54
|
+
- Avoid artificial or over-enhanced results
|
|
55
|
+
- 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
|
+
async generateTemplate(config: ImageEnhancementConfig): Promise<AIPromptResult<AIPromptTemplate>> {
|
|
71
|
+
try {
|
|
72
|
+
if (!this.validateConfig(config)) {
|
|
73
|
+
return {
|
|
74
|
+
success: false,
|
|
75
|
+
error: 'VALIDATION_ERROR',
|
|
76
|
+
message: 'Invalid image enhancement configuration'
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const template = this.createImageEnhancementTemplate(config);
|
|
81
|
+
return { success: true, data: template };
|
|
82
|
+
} catch (error) {
|
|
83
|
+
return {
|
|
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);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
validateConfig(config: ImageEnhancementConfig): boolean {
|
|
109
|
+
return validateImageEnhancementConfig(config);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
calculateAdjustments(config: ImageEnhancementConfig): EnhancementAdjustments {
|
|
113
|
+
return calculateAdjustments(config);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
private createImageEnhancementTemplate(config: ImageEnhancementConfig): AIPromptTemplate {
|
|
117
|
+
const templateId = `image-enhancement-${config.enhancementType}`;
|
|
118
|
+
|
|
119
|
+
const baseTemplate = createImageEnhancementBaseTemplate({
|
|
120
|
+
enhancementType: config.enhancementType,
|
|
121
|
+
targetStyle: config.targetStyle,
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
return createAIPromptTemplate({
|
|
125
|
+
id: templateId,
|
|
126
|
+
name: `Image Enhancement: ${config.enhancementType}`,
|
|
127
|
+
description: `Enhance images with ${config.enhancementType} improvements`,
|
|
128
|
+
category: 'image-enhancement',
|
|
129
|
+
template: `${baseTemplate}
|
|
130
|
+
|
|
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',
|
|
160
|
+
});
|
|
161
|
+
}
|
|
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
|
+
}
|