@umituz/react-native-ai-generation-content 1.15.0 → 1.15.1
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 +1 -1
- package/src/features/audio-generation/index.ts +0 -1
- package/src/features/colorization/index.ts +0 -1
- package/src/features/face-swap/index.ts +0 -1
- package/src/features/future-prediction/index.ts +0 -1
- package/src/features/image-captioning/index.ts +0 -1
- package/src/features/inpainting/index.ts +0 -1
- package/src/features/photo-restoration/index.ts +0 -1
- package/src/features/sketch-to-image/index.ts +0 -1
- package/src/features/style-transfer/index.ts +0 -1
- package/src/features/text-to-image/index.ts +0 -1
- package/src/features/text-to-video/index.ts +0 -1
- package/src/features/upscaling/index.ts +0 -1
- package/src/presentation/hooks/base/index.ts +9 -0
- package/src/presentation/hooks/base/types.ts +47 -0
- package/src/presentation/hooks/base/use-dual-image-feature.ts +178 -0
- package/src/presentation/hooks/base/use-image-with-prompt-feature.ts +170 -0
- package/src/presentation/hooks/base/use-single-image-feature.ts +154 -0
- package/src/presentation/hooks/index.ts +3 -0
- package/src/features/audio-generation/presentation/hooks.ts +0 -39
- package/src/features/colorization/presentation/hooks.ts +0 -39
- package/src/features/face-swap/presentation/hooks.ts +0 -41
- package/src/features/future-prediction/presentation/hooks.ts +0 -39
- package/src/features/image-captioning/presentation/hooks.ts +0 -39
- package/src/features/inpainting/presentation/hooks.ts +0 -39
- package/src/features/photo-restoration/presentation/hooks.ts +0 -39
- package/src/features/sketch-to-image/presentation/hooks.ts +0 -39
- package/src/features/style-transfer/presentation/hooks.ts +0 -39
- package/src/features/text-to-image/presentation/hooks.ts +0 -39
- package/src/features/text-to-video/presentation/hooks.ts +0 -39
- package/src/features/upscaling/presentation/hooks.ts +0 -39
package/package.json
CHANGED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base Feature Hook Types
|
|
3
|
+
* Provider-agnostic types for feature hooks
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Result from AI processing
|
|
8
|
+
*/
|
|
9
|
+
export interface FeatureProcessResult {
|
|
10
|
+
readonly success: boolean;
|
|
11
|
+
readonly outputUrl?: string;
|
|
12
|
+
readonly error?: string;
|
|
13
|
+
readonly metadata?: Record<string, unknown>;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Base state shared by all feature hooks
|
|
18
|
+
*/
|
|
19
|
+
export interface BaseFeatureState {
|
|
20
|
+
readonly isProcessing: boolean;
|
|
21
|
+
readonly progress: number;
|
|
22
|
+
readonly error: string | null;
|
|
23
|
+
readonly processedUrl: string | null;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Base actions shared by all feature hooks
|
|
28
|
+
*/
|
|
29
|
+
export interface BaseFeatureActions {
|
|
30
|
+
readonly reset: () => void;
|
|
31
|
+
readonly clearError: () => void;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Progress callback type
|
|
36
|
+
*/
|
|
37
|
+
export type OnProgressCallback = (progress: number) => void;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Image selection callback - provided by app
|
|
41
|
+
*/
|
|
42
|
+
export type OnSelectImageCallback = () => Promise<string | null>;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Save callback - provided by app
|
|
46
|
+
*/
|
|
47
|
+
export type OnSaveCallback = (url: string) => Promise<void>;
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* useDualImageFeature Hook
|
|
3
|
+
* Provider-agnostic hook for dual image processing features
|
|
4
|
+
* Examples: AI Hug, AI Kiss, Face Swap
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { useCallback, useState } from "react";
|
|
8
|
+
import type {
|
|
9
|
+
BaseFeatureState,
|
|
10
|
+
BaseFeatureActions,
|
|
11
|
+
FeatureProcessResult,
|
|
12
|
+
OnProgressCallback,
|
|
13
|
+
OnSelectImageCallback,
|
|
14
|
+
OnSaveCallback,
|
|
15
|
+
} from "./types";
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Request passed to processRequest callback
|
|
19
|
+
*/
|
|
20
|
+
export interface DualImageProcessRequest {
|
|
21
|
+
readonly firstImageUri: string;
|
|
22
|
+
readonly secondImageUri: string;
|
|
23
|
+
readonly onProgress: OnProgressCallback;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Configuration for dual image feature
|
|
28
|
+
*/
|
|
29
|
+
export interface UseDualImageFeatureConfig {
|
|
30
|
+
readonly onSelectFirstImage: OnSelectImageCallback;
|
|
31
|
+
readonly onSelectSecondImage: OnSelectImageCallback;
|
|
32
|
+
readonly processRequest: (
|
|
33
|
+
request: DualImageProcessRequest
|
|
34
|
+
) => Promise<FeatureProcessResult>;
|
|
35
|
+
readonly onSave?: OnSaveCallback;
|
|
36
|
+
readonly onError?: (error: string) => void;
|
|
37
|
+
readonly onSuccess?: (url: string) => void;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* State for dual image feature
|
|
42
|
+
*/
|
|
43
|
+
export interface DualImageFeatureState extends BaseFeatureState {
|
|
44
|
+
readonly firstImageUri: string | null;
|
|
45
|
+
readonly secondImageUri: string | null;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Return type for dual image feature hook
|
|
50
|
+
*/
|
|
51
|
+
export interface UseDualImageFeatureReturn
|
|
52
|
+
extends DualImageFeatureState,
|
|
53
|
+
BaseFeatureActions {
|
|
54
|
+
readonly selectFirstImage: () => Promise<void>;
|
|
55
|
+
readonly selectSecondImage: () => Promise<void>;
|
|
56
|
+
readonly process: () => Promise<void>;
|
|
57
|
+
readonly save: () => Promise<void>;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function useDualImageFeature(
|
|
61
|
+
config: UseDualImageFeatureConfig
|
|
62
|
+
): UseDualImageFeatureReturn {
|
|
63
|
+
const [firstImageUri, setFirstImageUri] = useState<string | null>(null);
|
|
64
|
+
const [secondImageUri, setSecondImageUri] = useState<string | null>(null);
|
|
65
|
+
const [processedUrl, setProcessedUrl] = useState<string | null>(null);
|
|
66
|
+
const [isProcessing, setIsProcessing] = useState(false);
|
|
67
|
+
const [progress, setProgress] = useState(0);
|
|
68
|
+
const [error, setError] = useState<string | null>(null);
|
|
69
|
+
|
|
70
|
+
const selectFirstImage = useCallback(async (): Promise<void> => {
|
|
71
|
+
try {
|
|
72
|
+
const uri = await config.onSelectFirstImage();
|
|
73
|
+
if (uri) {
|
|
74
|
+
setFirstImageUri(uri);
|
|
75
|
+
setError(null);
|
|
76
|
+
setProcessedUrl(null);
|
|
77
|
+
}
|
|
78
|
+
} catch (err) {
|
|
79
|
+
const message = err instanceof Error ? err.message : "error.selectImage";
|
|
80
|
+
setError(message);
|
|
81
|
+
config.onError?.(message);
|
|
82
|
+
}
|
|
83
|
+
}, [config]);
|
|
84
|
+
|
|
85
|
+
const selectSecondImage = useCallback(async (): Promise<void> => {
|
|
86
|
+
try {
|
|
87
|
+
const uri = await config.onSelectSecondImage();
|
|
88
|
+
if (uri) {
|
|
89
|
+
setSecondImageUri(uri);
|
|
90
|
+
setError(null);
|
|
91
|
+
setProcessedUrl(null);
|
|
92
|
+
}
|
|
93
|
+
} catch (err) {
|
|
94
|
+
const message = err instanceof Error ? err.message : "error.selectImage";
|
|
95
|
+
setError(message);
|
|
96
|
+
config.onError?.(message);
|
|
97
|
+
}
|
|
98
|
+
}, [config]);
|
|
99
|
+
|
|
100
|
+
const process = useCallback(async (): Promise<void> => {
|
|
101
|
+
if (!firstImageUri || !secondImageUri) {
|
|
102
|
+
const message = "error.noImages";
|
|
103
|
+
setError(message);
|
|
104
|
+
config.onError?.(message);
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
setIsProcessing(true);
|
|
109
|
+
setProgress(0);
|
|
110
|
+
setError(null);
|
|
111
|
+
|
|
112
|
+
try {
|
|
113
|
+
const result = await config.processRequest({
|
|
114
|
+
firstImageUri,
|
|
115
|
+
secondImageUri,
|
|
116
|
+
onProgress: setProgress,
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
if (result.success && result.outputUrl) {
|
|
120
|
+
setProcessedUrl(result.outputUrl);
|
|
121
|
+
config.onSuccess?.(result.outputUrl);
|
|
122
|
+
} else {
|
|
123
|
+
const message = result.error || "error.processing";
|
|
124
|
+
setError(message);
|
|
125
|
+
config.onError?.(message);
|
|
126
|
+
}
|
|
127
|
+
} catch (err) {
|
|
128
|
+
const message = err instanceof Error ? err.message : "error.processing";
|
|
129
|
+
setError(message);
|
|
130
|
+
config.onError?.(message);
|
|
131
|
+
} finally {
|
|
132
|
+
setIsProcessing(false);
|
|
133
|
+
setProgress(0);
|
|
134
|
+
}
|
|
135
|
+
}, [firstImageUri, secondImageUri, config]);
|
|
136
|
+
|
|
137
|
+
const save = useCallback(async (): Promise<void> => {
|
|
138
|
+
if (!processedUrl || !config.onSave) {
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
try {
|
|
143
|
+
await config.onSave(processedUrl);
|
|
144
|
+
} catch (err) {
|
|
145
|
+
const message = err instanceof Error ? err.message : "error.save";
|
|
146
|
+
setError(message);
|
|
147
|
+
config.onError?.(message);
|
|
148
|
+
}
|
|
149
|
+
}, [processedUrl, config]);
|
|
150
|
+
|
|
151
|
+
const reset = useCallback((): void => {
|
|
152
|
+
setFirstImageUri(null);
|
|
153
|
+
setSecondImageUri(null);
|
|
154
|
+
setProcessedUrl(null);
|
|
155
|
+
setIsProcessing(false);
|
|
156
|
+
setProgress(0);
|
|
157
|
+
setError(null);
|
|
158
|
+
}, []);
|
|
159
|
+
|
|
160
|
+
const clearError = useCallback((): void => {
|
|
161
|
+
setError(null);
|
|
162
|
+
}, []);
|
|
163
|
+
|
|
164
|
+
return {
|
|
165
|
+
firstImageUri,
|
|
166
|
+
secondImageUri,
|
|
167
|
+
processedUrl,
|
|
168
|
+
isProcessing,
|
|
169
|
+
progress,
|
|
170
|
+
error,
|
|
171
|
+
selectFirstImage,
|
|
172
|
+
selectSecondImage,
|
|
173
|
+
process,
|
|
174
|
+
save,
|
|
175
|
+
reset,
|
|
176
|
+
clearError,
|
|
177
|
+
};
|
|
178
|
+
}
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* useImageWithPromptFeature Hook
|
|
3
|
+
* Provider-agnostic hook for image + prompt processing features
|
|
4
|
+
* Examples: Inpainting, Style Transfer, Background Replacement
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { useCallback, useState } from "react";
|
|
8
|
+
import type {
|
|
9
|
+
BaseFeatureState,
|
|
10
|
+
BaseFeatureActions,
|
|
11
|
+
FeatureProcessResult,
|
|
12
|
+
OnProgressCallback,
|
|
13
|
+
OnSelectImageCallback,
|
|
14
|
+
OnSaveCallback,
|
|
15
|
+
} from "./types";
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Request passed to processRequest callback
|
|
19
|
+
*/
|
|
20
|
+
export interface ImageWithPromptProcessRequest {
|
|
21
|
+
readonly imageUri: string;
|
|
22
|
+
readonly prompt: string;
|
|
23
|
+
readonly onProgress: OnProgressCallback;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Configuration for image with prompt feature
|
|
28
|
+
*/
|
|
29
|
+
export interface UseImageWithPromptFeatureConfig {
|
|
30
|
+
readonly onSelectImage: OnSelectImageCallback;
|
|
31
|
+
readonly processRequest: (
|
|
32
|
+
request: ImageWithPromptProcessRequest
|
|
33
|
+
) => Promise<FeatureProcessResult>;
|
|
34
|
+
readonly onSave?: OnSaveCallback;
|
|
35
|
+
readonly onError?: (error: string) => void;
|
|
36
|
+
readonly onSuccess?: (url: string) => void;
|
|
37
|
+
readonly requirePrompt?: boolean;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* State for image with prompt feature
|
|
42
|
+
*/
|
|
43
|
+
export interface ImageWithPromptFeatureState extends BaseFeatureState {
|
|
44
|
+
readonly imageUri: string | null;
|
|
45
|
+
readonly prompt: string;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Return type for image with prompt feature hook
|
|
50
|
+
*/
|
|
51
|
+
export interface UseImageWithPromptFeatureReturn
|
|
52
|
+
extends ImageWithPromptFeatureState,
|
|
53
|
+
BaseFeatureActions {
|
|
54
|
+
readonly selectImage: () => Promise<void>;
|
|
55
|
+
readonly setPrompt: (prompt: string) => void;
|
|
56
|
+
readonly process: () => Promise<void>;
|
|
57
|
+
readonly save: () => Promise<void>;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function useImageWithPromptFeature(
|
|
61
|
+
config: UseImageWithPromptFeatureConfig
|
|
62
|
+
): UseImageWithPromptFeatureReturn {
|
|
63
|
+
const [imageUri, setImageUri] = useState<string | null>(null);
|
|
64
|
+
const [prompt, setPrompt] = useState<string>("");
|
|
65
|
+
const [processedUrl, setProcessedUrl] = useState<string | null>(null);
|
|
66
|
+
const [isProcessing, setIsProcessing] = useState(false);
|
|
67
|
+
const [progress, setProgress] = useState(0);
|
|
68
|
+
const [error, setError] = useState<string | null>(null);
|
|
69
|
+
|
|
70
|
+
const selectImage = useCallback(async (): Promise<void> => {
|
|
71
|
+
try {
|
|
72
|
+
const uri = await config.onSelectImage();
|
|
73
|
+
if (uri) {
|
|
74
|
+
setImageUri(uri);
|
|
75
|
+
setError(null);
|
|
76
|
+
setProcessedUrl(null);
|
|
77
|
+
}
|
|
78
|
+
} catch (err) {
|
|
79
|
+
const message = err instanceof Error ? err.message : "error.selectImage";
|
|
80
|
+
setError(message);
|
|
81
|
+
config.onError?.(message);
|
|
82
|
+
}
|
|
83
|
+
}, [config]);
|
|
84
|
+
|
|
85
|
+
const process = useCallback(async (): Promise<void> => {
|
|
86
|
+
if (!imageUri) {
|
|
87
|
+
const message = "error.noImage";
|
|
88
|
+
setError(message);
|
|
89
|
+
config.onError?.(message);
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if (config.requirePrompt && !prompt.trim()) {
|
|
94
|
+
const message = "error.noPrompt";
|
|
95
|
+
setError(message);
|
|
96
|
+
config.onError?.(message);
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
setIsProcessing(true);
|
|
101
|
+
setProgress(0);
|
|
102
|
+
setError(null);
|
|
103
|
+
|
|
104
|
+
try {
|
|
105
|
+
const result = await config.processRequest({
|
|
106
|
+
imageUri,
|
|
107
|
+
prompt: prompt.trim(),
|
|
108
|
+
onProgress: setProgress,
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
if (result.success && result.outputUrl) {
|
|
112
|
+
setProcessedUrl(result.outputUrl);
|
|
113
|
+
config.onSuccess?.(result.outputUrl);
|
|
114
|
+
} else {
|
|
115
|
+
const message = result.error || "error.processing";
|
|
116
|
+
setError(message);
|
|
117
|
+
config.onError?.(message);
|
|
118
|
+
}
|
|
119
|
+
} catch (err) {
|
|
120
|
+
const message = err instanceof Error ? err.message : "error.processing";
|
|
121
|
+
setError(message);
|
|
122
|
+
config.onError?.(message);
|
|
123
|
+
} finally {
|
|
124
|
+
setIsProcessing(false);
|
|
125
|
+
setProgress(0);
|
|
126
|
+
}
|
|
127
|
+
}, [imageUri, prompt, config]);
|
|
128
|
+
|
|
129
|
+
const save = useCallback(async (): Promise<void> => {
|
|
130
|
+
if (!processedUrl || !config.onSave) {
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
try {
|
|
135
|
+
await config.onSave(processedUrl);
|
|
136
|
+
} catch (err) {
|
|
137
|
+
const message = err instanceof Error ? err.message : "error.save";
|
|
138
|
+
setError(message);
|
|
139
|
+
config.onError?.(message);
|
|
140
|
+
}
|
|
141
|
+
}, [processedUrl, config]);
|
|
142
|
+
|
|
143
|
+
const reset = useCallback((): void => {
|
|
144
|
+
setImageUri(null);
|
|
145
|
+
setPrompt("");
|
|
146
|
+
setProcessedUrl(null);
|
|
147
|
+
setIsProcessing(false);
|
|
148
|
+
setProgress(0);
|
|
149
|
+
setError(null);
|
|
150
|
+
}, []);
|
|
151
|
+
|
|
152
|
+
const clearError = useCallback((): void => {
|
|
153
|
+
setError(null);
|
|
154
|
+
}, []);
|
|
155
|
+
|
|
156
|
+
return {
|
|
157
|
+
imageUri,
|
|
158
|
+
prompt,
|
|
159
|
+
processedUrl,
|
|
160
|
+
isProcessing,
|
|
161
|
+
progress,
|
|
162
|
+
error,
|
|
163
|
+
selectImage,
|
|
164
|
+
setPrompt,
|
|
165
|
+
process,
|
|
166
|
+
save,
|
|
167
|
+
reset,
|
|
168
|
+
clearError,
|
|
169
|
+
};
|
|
170
|
+
}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* useSingleImageFeature Hook
|
|
3
|
+
* Provider-agnostic hook for single image processing features
|
|
4
|
+
* App provides processRequest callback with their AI provider
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { useCallback, useState } from "react";
|
|
8
|
+
import type {
|
|
9
|
+
BaseFeatureState,
|
|
10
|
+
BaseFeatureActions,
|
|
11
|
+
FeatureProcessResult,
|
|
12
|
+
OnProgressCallback,
|
|
13
|
+
OnSelectImageCallback,
|
|
14
|
+
OnSaveCallback,
|
|
15
|
+
} from "./types";
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Request passed to processRequest callback
|
|
19
|
+
*/
|
|
20
|
+
export interface SingleImageProcessRequest {
|
|
21
|
+
readonly imageUri: string;
|
|
22
|
+
readonly onProgress: OnProgressCallback;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Configuration for single image feature
|
|
27
|
+
*/
|
|
28
|
+
export interface UseSingleImageFeatureConfig {
|
|
29
|
+
readonly onSelectImage: OnSelectImageCallback;
|
|
30
|
+
readonly processRequest: (
|
|
31
|
+
request: SingleImageProcessRequest
|
|
32
|
+
) => Promise<FeatureProcessResult>;
|
|
33
|
+
readonly onSave?: OnSaveCallback;
|
|
34
|
+
readonly onError?: (error: string) => void;
|
|
35
|
+
readonly onSuccess?: (url: string) => void;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* State for single image feature
|
|
40
|
+
*/
|
|
41
|
+
export interface SingleImageFeatureState extends BaseFeatureState {
|
|
42
|
+
readonly imageUri: string | null;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Return type for single image feature hook
|
|
47
|
+
*/
|
|
48
|
+
export interface UseSingleImageFeatureReturn
|
|
49
|
+
extends SingleImageFeatureState,
|
|
50
|
+
BaseFeatureActions {
|
|
51
|
+
readonly selectImage: () => Promise<void>;
|
|
52
|
+
readonly process: () => Promise<void>;
|
|
53
|
+
readonly save: () => Promise<void>;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function useSingleImageFeature(
|
|
57
|
+
config: UseSingleImageFeatureConfig
|
|
58
|
+
): UseSingleImageFeatureReturn {
|
|
59
|
+
const [imageUri, setImageUri] = useState<string | null>(null);
|
|
60
|
+
const [processedUrl, setProcessedUrl] = useState<string | null>(null);
|
|
61
|
+
const [isProcessing, setIsProcessing] = useState(false);
|
|
62
|
+
const [progress, setProgress] = useState(0);
|
|
63
|
+
const [error, setError] = useState<string | null>(null);
|
|
64
|
+
|
|
65
|
+
const selectImage = useCallback(async (): Promise<void> => {
|
|
66
|
+
try {
|
|
67
|
+
const uri = await config.onSelectImage();
|
|
68
|
+
if (uri) {
|
|
69
|
+
setImageUri(uri);
|
|
70
|
+
setError(null);
|
|
71
|
+
setProcessedUrl(null);
|
|
72
|
+
}
|
|
73
|
+
} catch (err) {
|
|
74
|
+
const message = err instanceof Error ? err.message : "error.selectImage";
|
|
75
|
+
setError(message);
|
|
76
|
+
config.onError?.(message);
|
|
77
|
+
}
|
|
78
|
+
}, [config]);
|
|
79
|
+
|
|
80
|
+
const process = useCallback(async (): Promise<void> => {
|
|
81
|
+
if (!imageUri) {
|
|
82
|
+
const message = "error.noImage";
|
|
83
|
+
setError(message);
|
|
84
|
+
config.onError?.(message);
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
setIsProcessing(true);
|
|
89
|
+
setProgress(0);
|
|
90
|
+
setError(null);
|
|
91
|
+
|
|
92
|
+
try {
|
|
93
|
+
const result = await config.processRequest({
|
|
94
|
+
imageUri,
|
|
95
|
+
onProgress: setProgress,
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
if (result.success && result.outputUrl) {
|
|
99
|
+
setProcessedUrl(result.outputUrl);
|
|
100
|
+
config.onSuccess?.(result.outputUrl);
|
|
101
|
+
} else {
|
|
102
|
+
const message = result.error || "error.processing";
|
|
103
|
+
setError(message);
|
|
104
|
+
config.onError?.(message);
|
|
105
|
+
}
|
|
106
|
+
} catch (err) {
|
|
107
|
+
const message = err instanceof Error ? err.message : "error.processing";
|
|
108
|
+
setError(message);
|
|
109
|
+
config.onError?.(message);
|
|
110
|
+
} finally {
|
|
111
|
+
setIsProcessing(false);
|
|
112
|
+
setProgress(0);
|
|
113
|
+
}
|
|
114
|
+
}, [imageUri, config]);
|
|
115
|
+
|
|
116
|
+
const save = useCallback(async (): Promise<void> => {
|
|
117
|
+
if (!processedUrl || !config.onSave) {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
try {
|
|
122
|
+
await config.onSave(processedUrl);
|
|
123
|
+
} catch (err) {
|
|
124
|
+
const message = err instanceof Error ? err.message : "error.save";
|
|
125
|
+
setError(message);
|
|
126
|
+
config.onError?.(message);
|
|
127
|
+
}
|
|
128
|
+
}, [processedUrl, config]);
|
|
129
|
+
|
|
130
|
+
const reset = useCallback((): void => {
|
|
131
|
+
setImageUri(null);
|
|
132
|
+
setProcessedUrl(null);
|
|
133
|
+
setIsProcessing(false);
|
|
134
|
+
setProgress(0);
|
|
135
|
+
setError(null);
|
|
136
|
+
}, []);
|
|
137
|
+
|
|
138
|
+
const clearError = useCallback((): void => {
|
|
139
|
+
setError(null);
|
|
140
|
+
}, []);
|
|
141
|
+
|
|
142
|
+
return {
|
|
143
|
+
imageUri,
|
|
144
|
+
processedUrl,
|
|
145
|
+
isProcessing,
|
|
146
|
+
progress,
|
|
147
|
+
error,
|
|
148
|
+
selectImage,
|
|
149
|
+
process,
|
|
150
|
+
save,
|
|
151
|
+
reset,
|
|
152
|
+
clearError,
|
|
153
|
+
};
|
|
154
|
+
}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-unsafe-argument */
|
|
2
|
-
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
3
|
-
/* eslint-disable @typescript-eslint/no-unnecessary-type-assertion */
|
|
4
|
-
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
|
5
|
-
/* eslint-disable @typescript-eslint/no-unsafe-call */
|
|
6
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
7
|
-
import { useState, useCallback } from 'react';
|
|
8
|
-
import { useGeneration } from '../../../presentation/hooks/use-generation';
|
|
9
|
-
import { AudioGenerationRequest, AudioGenerationResult } from '../domain/entities';
|
|
10
|
-
|
|
11
|
-
export interface UseAudioGenerationReturn {
|
|
12
|
-
generateAudio: (request: AudioGenerationRequest) => Promise<AudioGenerationResult>;
|
|
13
|
-
isGenerating: boolean;
|
|
14
|
-
result: AudioGenerationResult | null;
|
|
15
|
-
error: Error | null;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export const useAudioGeneration = (): UseAudioGenerationReturn => {
|
|
19
|
-
const { generate, isGenerating, error, result: genResult } = useGeneration({ model: "deprecated" });
|
|
20
|
-
const [result, setResult] = useState<AudioGenerationResult | null>(null);
|
|
21
|
-
|
|
22
|
-
const generateAudio = useCallback(async (request: AudioGenerationRequest) => {
|
|
23
|
-
await generate(request as any);
|
|
24
|
-
|
|
25
|
-
if (genResult?.data) {
|
|
26
|
-
setResult(genResult.data as AudioGenerationResult);
|
|
27
|
-
return genResult.data as AudioGenerationResult;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
throw new Error('Audio generation failed to return a result');
|
|
31
|
-
}, [generate, genResult]);
|
|
32
|
-
|
|
33
|
-
return {
|
|
34
|
-
generateAudio,
|
|
35
|
-
isGenerating,
|
|
36
|
-
result,
|
|
37
|
-
error: error as any,
|
|
38
|
-
};
|
|
39
|
-
};
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-unsafe-argument */
|
|
2
|
-
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
3
|
-
/* eslint-disable @typescript-eslint/no-unnecessary-type-assertion */
|
|
4
|
-
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
|
5
|
-
/* eslint-disable @typescript-eslint/no-unsafe-call */
|
|
6
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
7
|
-
import { useState, useCallback } from 'react';
|
|
8
|
-
import { useGeneration } from '../../../presentation/hooks/use-generation';
|
|
9
|
-
import { ColorizationRequest, ColorizationResult } from '../domain/entities';
|
|
10
|
-
|
|
11
|
-
export interface UseColorizationReturn {
|
|
12
|
-
colorize: (request: ColorizationRequest) => Promise<ColorizationResult>;
|
|
13
|
-
isColorizing: boolean;
|
|
14
|
-
result: ColorizationResult | null;
|
|
15
|
-
error: Error | null;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export const useColorization = (): UseColorizationReturn => {
|
|
19
|
-
const { generate, isGenerating, error, result: genResult } = useGeneration({ model: "deprecated" });
|
|
20
|
-
const [result, setResult] = useState<ColorizationResult | null>(null);
|
|
21
|
-
|
|
22
|
-
const colorize = useCallback(async (request: ColorizationRequest) => {
|
|
23
|
-
await generate(request as any);
|
|
24
|
-
|
|
25
|
-
if (genResult?.data) {
|
|
26
|
-
setResult(genResult.data as ColorizationResult);
|
|
27
|
-
return genResult.data as ColorizationResult;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
throw new Error('Colorization failed to return a result');
|
|
31
|
-
}, [generate, genResult]);
|
|
32
|
-
|
|
33
|
-
return {
|
|
34
|
-
colorize,
|
|
35
|
-
isColorizing: isGenerating,
|
|
36
|
-
result,
|
|
37
|
-
error: error as any,
|
|
38
|
-
};
|
|
39
|
-
};
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-unsafe-argument */
|
|
2
|
-
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
3
|
-
/* eslint-disable @typescript-eslint/no-unnecessary-type-assertion */
|
|
4
|
-
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
|
5
|
-
/* eslint-disable @typescript-eslint/no-unsafe-call */
|
|
6
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
7
|
-
import { useState, useCallback } from 'react';
|
|
8
|
-
import { useGeneration } from '../../../presentation/hooks/use-generation';
|
|
9
|
-
import { FaceSwapRequest, FaceSwapResult } from '../domain/entities';
|
|
10
|
-
|
|
11
|
-
export interface UseFaceSwapReturn {
|
|
12
|
-
swapFace: (request: FaceSwapRequest) => Promise<FaceSwapResult>;
|
|
13
|
-
isSwapping: boolean;
|
|
14
|
-
result: FaceSwapResult | null;
|
|
15
|
-
error: Error | null;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export const useFaceSwap = (): UseFaceSwapReturn => {
|
|
19
|
-
// @ts-ignore - Deprecated feature, kept for backward compatibility
|
|
20
|
-
const { generate, isGenerating, error, result: genResult } = useGeneration<FaceSwapResult>({ model: 'face-swap' });
|
|
21
|
-
const [result, setResult] = useState<FaceSwapResult | null>(null);
|
|
22
|
-
|
|
23
|
-
const swapFace = useCallback(async (request: FaceSwapRequest) => {
|
|
24
|
-
// @ts-ignore - Deprecated feature
|
|
25
|
-
await generate(request);
|
|
26
|
-
|
|
27
|
-
if (genResult?.data) {
|
|
28
|
-
setResult(genResult.data as FaceSwapResult);
|
|
29
|
-
return genResult.data as FaceSwapResult;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
throw new Error('Face swap failed to return a result');
|
|
33
|
-
}, [generate, genResult]);
|
|
34
|
-
|
|
35
|
-
return {
|
|
36
|
-
swapFace,
|
|
37
|
-
isSwapping: isGenerating,
|
|
38
|
-
result,
|
|
39
|
-
error: error as any,
|
|
40
|
-
};
|
|
41
|
-
};
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-unsafe-argument */
|
|
2
|
-
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
3
|
-
/* eslint-disable @typescript-eslint/no-unnecessary-type-assertion */
|
|
4
|
-
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
|
5
|
-
/* eslint-disable @typescript-eslint/no-unsafe-call */
|
|
6
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
7
|
-
import { useState, useCallback } from 'react';
|
|
8
|
-
import { useGeneration } from '../../../presentation/hooks/use-generation';
|
|
9
|
-
import { FuturePredictionRequest, FuturePredictionResult } from '../domain/entities';
|
|
10
|
-
|
|
11
|
-
export interface UseFuturePredictionReturn {
|
|
12
|
-
predictFuture: (request: FuturePredictionRequest) => Promise<FuturePredictionResult>;
|
|
13
|
-
isPredicting: boolean;
|
|
14
|
-
result: FuturePredictionResult | null;
|
|
15
|
-
error: Error | null;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export const useFuturePrediction = (): UseFuturePredictionReturn => {
|
|
19
|
-
const { generate, isGenerating, error, result: genResult } = useGeneration({ model: "deprecated" });
|
|
20
|
-
const [result, setResult] = useState<FuturePredictionResult | null>(null);
|
|
21
|
-
|
|
22
|
-
const predictFuture = useCallback(async (request: FuturePredictionRequest) => {
|
|
23
|
-
await generate(request as any);
|
|
24
|
-
|
|
25
|
-
if (genResult?.data) {
|
|
26
|
-
setResult(genResult.data as FuturePredictionResult);
|
|
27
|
-
return genResult.data as FuturePredictionResult;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
throw new Error('Future prediction failed to return a result');
|
|
31
|
-
}, [generate, genResult]);
|
|
32
|
-
|
|
33
|
-
return {
|
|
34
|
-
predictFuture,
|
|
35
|
-
isPredicting: isGenerating,
|
|
36
|
-
result,
|
|
37
|
-
error: error as any,
|
|
38
|
-
};
|
|
39
|
-
};
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-unsafe-argument */
|
|
2
|
-
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
3
|
-
/* eslint-disable @typescript-eslint/no-unnecessary-type-assertion */
|
|
4
|
-
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
|
5
|
-
/* eslint-disable @typescript-eslint/no-unsafe-call */
|
|
6
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
7
|
-
import { useState, useCallback } from 'react';
|
|
8
|
-
import { useGeneration } from '../../../presentation/hooks/use-generation';
|
|
9
|
-
import { ImageCaptioningRequest, ImageCaptioningResult } from '../domain/entities';
|
|
10
|
-
|
|
11
|
-
export interface UseImageCaptioningReturn {
|
|
12
|
-
generateCaption: (request: ImageCaptioningRequest) => Promise<ImageCaptioningResult>;
|
|
13
|
-
isGenerating: boolean;
|
|
14
|
-
result: ImageCaptioningResult | null;
|
|
15
|
-
error: Error | null;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export const useImageCaptioning = (): UseImageCaptioningReturn => {
|
|
19
|
-
const { generate, isGenerating, error, result: genResult } = useGeneration({ model: "deprecated" });
|
|
20
|
-
const [result, setResult] = useState<ImageCaptioningResult | null>(null);
|
|
21
|
-
|
|
22
|
-
const generateCaption = useCallback(async (request: ImageCaptioningRequest) => {
|
|
23
|
-
await generate(request as any);
|
|
24
|
-
|
|
25
|
-
if (genResult?.data) {
|
|
26
|
-
setResult(genResult.data as ImageCaptioningResult);
|
|
27
|
-
return genResult.data as ImageCaptioningResult;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
throw new Error('Caption generation failed to return a result');
|
|
31
|
-
}, [generate, genResult]);
|
|
32
|
-
|
|
33
|
-
return {
|
|
34
|
-
generateCaption,
|
|
35
|
-
isGenerating,
|
|
36
|
-
result,
|
|
37
|
-
error: error as any,
|
|
38
|
-
};
|
|
39
|
-
};
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-unsafe-argument */
|
|
2
|
-
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
3
|
-
/* eslint-disable @typescript-eslint/no-unnecessary-type-assertion */
|
|
4
|
-
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
|
5
|
-
/* eslint-disable @typescript-eslint/no-unsafe-call */
|
|
6
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
7
|
-
import { useState, useCallback } from 'react';
|
|
8
|
-
import { useGeneration } from '../../../presentation/hooks/use-generation';
|
|
9
|
-
import { InpaintingRequest, InpaintingResult } from '../domain/entities';
|
|
10
|
-
|
|
11
|
-
export interface UseInpaintingReturn {
|
|
12
|
-
inpaint: (request: InpaintingRequest) => Promise<InpaintingResult>;
|
|
13
|
-
isInpainting: boolean;
|
|
14
|
-
result: InpaintingResult | null;
|
|
15
|
-
error: Error | null;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export const useInpainting = (): UseInpaintingReturn => {
|
|
19
|
-
const { generate, isGenerating, error, result: genResult } = useGeneration({ model: "deprecated" });
|
|
20
|
-
const [result, setResult] = useState<InpaintingResult | null>(null);
|
|
21
|
-
|
|
22
|
-
const inpaint = useCallback(async (request: InpaintingRequest) => {
|
|
23
|
-
await generate(request as any);
|
|
24
|
-
|
|
25
|
-
if (genResult?.data) {
|
|
26
|
-
setResult(genResult.data as InpaintingResult);
|
|
27
|
-
return genResult.data as InpaintingResult;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
throw new Error('Inpainting failed to return a result');
|
|
31
|
-
}, [generate, genResult]);
|
|
32
|
-
|
|
33
|
-
return {
|
|
34
|
-
inpaint,
|
|
35
|
-
isInpainting: isGenerating,
|
|
36
|
-
result,
|
|
37
|
-
error: error as any,
|
|
38
|
-
};
|
|
39
|
-
};
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-unsafe-argument */
|
|
2
|
-
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
3
|
-
/* eslint-disable @typescript-eslint/no-unnecessary-type-assertion */
|
|
4
|
-
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
|
5
|
-
/* eslint-disable @typescript-eslint/no-unsafe-call */
|
|
6
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
7
|
-
import { useState, useCallback } from 'react';
|
|
8
|
-
import { useGeneration } from '../../../presentation/hooks/use-generation';
|
|
9
|
-
import { PhotoRestorationRequest, PhotoRestorationResult } from '../domain/entities';
|
|
10
|
-
|
|
11
|
-
export interface UsePhotoRestorationReturn {
|
|
12
|
-
restorePhoto: (request: PhotoRestorationRequest) => Promise<PhotoRestorationResult>;
|
|
13
|
-
isRestoring: boolean;
|
|
14
|
-
result: PhotoRestorationResult | null;
|
|
15
|
-
error: Error | null;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export const usePhotoRestoration = (): UsePhotoRestorationReturn => {
|
|
19
|
-
const { generate, isGenerating, error, result: genResult } = useGeneration({ model: "deprecated" });
|
|
20
|
-
const [result, setResult] = useState<PhotoRestorationResult | null>(null);
|
|
21
|
-
|
|
22
|
-
const restorePhoto = useCallback(async (request: PhotoRestorationRequest) => {
|
|
23
|
-
await generate(request as any);
|
|
24
|
-
|
|
25
|
-
if (genResult?.data) {
|
|
26
|
-
setResult(genResult.data as PhotoRestorationResult);
|
|
27
|
-
return genResult.data as PhotoRestorationResult;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
throw new Error('Photo restoration failed to return a result');
|
|
31
|
-
}, [generate, genResult]);
|
|
32
|
-
|
|
33
|
-
return {
|
|
34
|
-
restorePhoto,
|
|
35
|
-
isRestoring: isGenerating,
|
|
36
|
-
result,
|
|
37
|
-
error: error as any,
|
|
38
|
-
};
|
|
39
|
-
};
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-unsafe-argument */
|
|
2
|
-
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
3
|
-
/* eslint-disable @typescript-eslint/no-unnecessary-type-assertion */
|
|
4
|
-
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
|
5
|
-
/* eslint-disable @typescript-eslint/no-unsafe-call */
|
|
6
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
7
|
-
import { useState, useCallback } from 'react';
|
|
8
|
-
import { useGeneration } from '../../../presentation/hooks/use-generation';
|
|
9
|
-
import { SketchToImageRequest, SketchToImageResult } from '../domain/entities';
|
|
10
|
-
|
|
11
|
-
export interface UseSketchToImageReturn {
|
|
12
|
-
generateFromSketch: (request: SketchToImageRequest) => Promise<SketchToImageResult>;
|
|
13
|
-
isGenerating: boolean;
|
|
14
|
-
result: SketchToImageResult | null;
|
|
15
|
-
error: Error | null;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export const useSketchToImage = (): UseSketchToImageReturn => {
|
|
19
|
-
const { generate, isGenerating, error, result: genResult } = useGeneration({ model: "deprecated" });
|
|
20
|
-
const [result, setResult] = useState<SketchToImageResult | null>(null);
|
|
21
|
-
|
|
22
|
-
const generateFromSketch = useCallback(async (request: SketchToImageRequest) => {
|
|
23
|
-
await generate(request as any);
|
|
24
|
-
|
|
25
|
-
if (genResult?.data) {
|
|
26
|
-
setResult(genResult.data as SketchToImageResult);
|
|
27
|
-
return genResult.data as SketchToImageResult;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
throw new Error('Sketch to image generation failed to return a result');
|
|
31
|
-
}, [generate, genResult]);
|
|
32
|
-
|
|
33
|
-
return {
|
|
34
|
-
generateFromSketch,
|
|
35
|
-
isGenerating,
|
|
36
|
-
result,
|
|
37
|
-
error: error as any,
|
|
38
|
-
};
|
|
39
|
-
};
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-unsafe-argument */
|
|
2
|
-
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
3
|
-
/* eslint-disable @typescript-eslint/no-unnecessary-type-assertion */
|
|
4
|
-
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
|
5
|
-
/* eslint-disable @typescript-eslint/no-unsafe-call */
|
|
6
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
7
|
-
import { useState, useCallback } from 'react';
|
|
8
|
-
import { useGeneration } from '../../../presentation/hooks/use-generation';
|
|
9
|
-
import { StyleTransferRequest, StyleTransferResult } from '../domain/entities';
|
|
10
|
-
|
|
11
|
-
export interface UseStyleTransferReturn {
|
|
12
|
-
transferStyle: (request: StyleTransferRequest) => Promise<StyleTransferResult>;
|
|
13
|
-
isTransferring: boolean;
|
|
14
|
-
result: StyleTransferResult | null;
|
|
15
|
-
error: Error | null;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export const useStyleTransfer = (): UseStyleTransferReturn => {
|
|
19
|
-
const { generate, isGenerating, error, result: genResult } = useGeneration({ model: "deprecated" });
|
|
20
|
-
const [result, setResult] = useState<StyleTransferResult | null>(null);
|
|
21
|
-
|
|
22
|
-
const transferStyle = useCallback(async (request: StyleTransferRequest) => {
|
|
23
|
-
await generate(request as any);
|
|
24
|
-
|
|
25
|
-
if (genResult?.data) {
|
|
26
|
-
setResult(genResult.data as StyleTransferResult);
|
|
27
|
-
return genResult.data as StyleTransferResult;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
throw new Error('Style transfer failed to return a result');
|
|
31
|
-
}, [generate, genResult]);
|
|
32
|
-
|
|
33
|
-
return {
|
|
34
|
-
transferStyle,
|
|
35
|
-
isTransferring: isGenerating,
|
|
36
|
-
result,
|
|
37
|
-
error: error as any,
|
|
38
|
-
};
|
|
39
|
-
};
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-unsafe-argument */
|
|
2
|
-
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
3
|
-
/* eslint-disable @typescript-eslint/no-unnecessary-type-assertion */
|
|
4
|
-
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
|
5
|
-
/* eslint-disable @typescript-eslint/no-unsafe-call */
|
|
6
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
7
|
-
import { useState, useCallback } from 'react';
|
|
8
|
-
import { useGeneration } from '../../../presentation/hooks/use-generation';
|
|
9
|
-
import { TextToImageRequest, TextToImageResult } from '../domain/entities';
|
|
10
|
-
|
|
11
|
-
export interface UseTextToImageReturn {
|
|
12
|
-
generateImage: (request: TextToImageRequest) => Promise<TextToImageResult>;
|
|
13
|
-
isGenerating: boolean;
|
|
14
|
-
result: TextToImageResult | null;
|
|
15
|
-
error: Error | null;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export const useTextToImage = (): UseTextToImageReturn => {
|
|
19
|
-
const { generate, isGenerating, error, result: genResult } = useGeneration({ model: "deprecated" });
|
|
20
|
-
const [result, setResult] = useState<TextToImageResult | null>(null);
|
|
21
|
-
|
|
22
|
-
const generateImage = useCallback(async (request: TextToImageRequest) => {
|
|
23
|
-
await generate(request as any);
|
|
24
|
-
|
|
25
|
-
if (genResult?.data) {
|
|
26
|
-
setResult(genResult.data as TextToImageResult);
|
|
27
|
-
return genResult.data as TextToImageResult;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
throw new Error('Image generation failed to return a result');
|
|
31
|
-
}, [generate, genResult]);
|
|
32
|
-
|
|
33
|
-
return {
|
|
34
|
-
generateImage,
|
|
35
|
-
isGenerating,
|
|
36
|
-
result,
|
|
37
|
-
error: error as any,
|
|
38
|
-
};
|
|
39
|
-
};
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-unsafe-argument */
|
|
2
|
-
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
3
|
-
/* eslint-disable @typescript-eslint/no-unnecessary-type-assertion */
|
|
4
|
-
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
|
5
|
-
/* eslint-disable @typescript-eslint/no-unsafe-call */
|
|
6
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
7
|
-
import { useState, useCallback } from 'react';
|
|
8
|
-
import { useGeneration } from '../../../presentation/hooks/use-generation';
|
|
9
|
-
import { TextToVideoRequest, TextToVideoResult } from '../domain/entities';
|
|
10
|
-
|
|
11
|
-
export interface UseTextToVideoReturn {
|
|
12
|
-
generateVideo: (request: TextToVideoRequest) => Promise<TextToVideoResult>;
|
|
13
|
-
isGenerating: boolean;
|
|
14
|
-
result: TextToVideoResult | null;
|
|
15
|
-
error: Error | null;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export const useTextToVideo = (): UseTextToVideoReturn => {
|
|
19
|
-
const { generate, isGenerating, error, result: genResult } = useGeneration({ model: "deprecated" });
|
|
20
|
-
const [result, setResult] = useState<TextToVideoResult | null>(null);
|
|
21
|
-
|
|
22
|
-
const generateVideo = useCallback(async (request: TextToVideoRequest) => {
|
|
23
|
-
await generate(request as any);
|
|
24
|
-
|
|
25
|
-
if (genResult?.data) {
|
|
26
|
-
setResult(genResult.data as TextToVideoResult);
|
|
27
|
-
return genResult.data as TextToVideoResult;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
throw new Error('Video generation failed to return a result');
|
|
31
|
-
}, [generate, genResult]);
|
|
32
|
-
|
|
33
|
-
return {
|
|
34
|
-
generateVideo,
|
|
35
|
-
isGenerating,
|
|
36
|
-
result,
|
|
37
|
-
error: error as any,
|
|
38
|
-
};
|
|
39
|
-
};
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-unsafe-argument */
|
|
2
|
-
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
3
|
-
/* eslint-disable @typescript-eslint/no-unnecessary-type-assertion */
|
|
4
|
-
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
|
5
|
-
/* eslint-disable @typescript-eslint/no-unsafe-call */
|
|
6
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
7
|
-
import { useState, useCallback } from 'react';
|
|
8
|
-
import { useGeneration } from '../../../presentation/hooks/use-generation';
|
|
9
|
-
import { UpscaleRequest, UpscaleResult } from '../domain/entities';
|
|
10
|
-
|
|
11
|
-
export interface UseUpscalingReturn {
|
|
12
|
-
upscale: (request: UpscaleRequest) => Promise<UpscaleResult>;
|
|
13
|
-
isUpscaling: boolean;
|
|
14
|
-
result: UpscaleResult | null;
|
|
15
|
-
error: Error | null;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export const useUpscaling = (): UseUpscalingReturn => {
|
|
19
|
-
const { generate, isGenerating, error, result: genResult } = useGeneration({ model: "deprecated" });
|
|
20
|
-
const [result, setResult] = useState<UpscaleResult | null>(null);
|
|
21
|
-
|
|
22
|
-
const upscale = useCallback(async (request: UpscaleRequest) => {
|
|
23
|
-
await generate(request as any);
|
|
24
|
-
|
|
25
|
-
if (genResult?.data) {
|
|
26
|
-
setResult(genResult.data as UpscaleResult);
|
|
27
|
-
return genResult.data as UpscaleResult;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
throw new Error('Upscaling failed to return a result');
|
|
31
|
-
}, [generate, genResult]);
|
|
32
|
-
|
|
33
|
-
return {
|
|
34
|
-
upscale,
|
|
35
|
-
isUpscaling: isGenerating,
|
|
36
|
-
result,
|
|
37
|
-
error: error as any,
|
|
38
|
-
};
|
|
39
|
-
};
|