sushilideaclan01 commited on
Commit
da4a2eb
·
1 Parent(s): e5ce876

feat: Add cost estimator for image generation in BatchForm, ExtensiveForm, and GenerationForm

Browse files
frontend/components/generation/BatchForm.tsx CHANGED
@@ -8,7 +8,7 @@ import { Input } from "@/components/ui/Input";
8
  import { Select } from "@/components/ui/Select";
9
  import { Button } from "@/components/ui/Button";
10
  import { Card, CardContent, CardHeader, CardTitle, CardDescription } from "@/components/ui/Card";
11
- import { IMAGE_MODELS } from "@/lib/constants/models";
12
  import type { Niche } from "@/types/api";
13
 
14
  interface BatchFormProps {
@@ -39,6 +39,7 @@ export const BatchForm: React.FC<BatchFormProps> = ({
39
 
40
  const count = watch("count");
41
  const imagesPerAd = watch("images_per_ad");
 
42
 
43
  return (
44
  <Card variant="glass">
@@ -155,6 +156,16 @@ export const BatchForm: React.FC<BatchFormProps> = ({
155
  </p>
156
  </div>
157
 
 
 
 
 
 
 
 
 
 
 
158
  <Button
159
  type="submit"
160
  variant="primary"
 
8
  import { Select } from "@/components/ui/Select";
9
  import { Button } from "@/components/ui/Button";
10
  import { Card, CardContent, CardHeader, CardTitle, CardDescription } from "@/components/ui/Card";
11
+ import { IMAGE_MODELS, getModelCost, formatCost } from "@/lib/constants/models";
12
  import type { Niche } from "@/types/api";
13
 
14
  interface BatchFormProps {
 
39
 
40
  const count = watch("count");
41
  const imagesPerAd = watch("images_per_ad");
42
+ const selectedModel = watch("image_model");
43
 
44
  return (
45
  <Card variant="glass">
 
156
  </p>
157
  </div>
158
 
159
+ {/* Cost Estimator */}
160
+ <div className="bg-gradient-to-r from-green-50 to-emerald-50 border border-green-200 rounded-xl p-4">
161
+ <p className="text-sm font-semibold text-gray-800">
162
+ 💰 <strong>Estimated Cost:</strong> {formatCost(getModelCost(selectedModel || "", count * imagesPerAd))}
163
+ </p>
164
+ <p className="text-xs text-gray-600 mt-1">
165
+ {count * imagesPerAd} total image{count * imagesPerAd > 1 ? 's' : ''} × {IMAGE_MODELS.find(m => m.value === (selectedModel || ""))?.label.split(' - ')[0] || "Default model"}
166
+ </p>
167
+ </div>
168
+
169
  <Button
170
  type="submit"
171
  variant="primary"
frontend/components/generation/ExtensiveForm.tsx CHANGED
@@ -6,7 +6,7 @@ import { zodResolver } from "@hookform/resolvers/zod";
6
  import { z } from "zod";
7
  import { Card, CardContent, CardHeader, CardTitle, CardDescription } from "@/components/ui/Card";
8
  import { Select } from "@/components/ui/Select";
9
- import { IMAGE_MODELS } from "@/lib/constants/models";
10
  import type { Niche } from "@/types/api";
11
 
12
  const extensiveSchema = z.object({
@@ -70,6 +70,7 @@ export const ExtensiveForm: React.FC<ExtensiveFormProps> = ({
70
  const numImages = watch("num_images");
71
  const numStrategies = watch("num_strategies");
72
  const selectedNiche = watch("niche");
 
73
 
74
  return (
75
  <Card variant="glass">
@@ -197,6 +198,16 @@ export const ExtensiveForm: React.FC<ExtensiveFormProps> = ({
197
  </p>
198
  </div>
199
 
 
 
 
 
 
 
 
 
 
 
200
  <button
201
  type="submit"
202
  disabled={isLoading}
 
6
  import { z } from "zod";
7
  import { Card, CardContent, CardHeader, CardTitle, CardDescription } from "@/components/ui/Card";
8
  import { Select } from "@/components/ui/Select";
9
+ import { IMAGE_MODELS, getModelCost, formatCost } from "@/lib/constants/models";
10
  import type { Niche } from "@/types/api";
11
 
12
  const extensiveSchema = z.object({
 
70
  const numImages = watch("num_images");
71
  const numStrategies = watch("num_strategies");
72
  const selectedNiche = watch("niche");
73
+ const selectedModel = watch("image_model");
74
 
75
  return (
76
  <Card variant="glass">
 
198
  </p>
199
  </div>
200
 
201
+ {/* Cost Estimator */}
202
+ <div className="bg-gradient-to-r from-green-50 to-emerald-50 border border-green-200 rounded-xl p-4">
203
+ <p className="text-sm font-semibold text-gray-800">
204
+ 💰 <strong>Estimated Cost:</strong> {formatCost(getModelCost(selectedModel || "", numStrategies * numImages))}
205
+ </p>
206
+ <p className="text-xs text-gray-600 mt-1">
207
+ {numStrategies * numImages} total image{numStrategies * numImages > 1 ? 's' : ''} × {IMAGE_MODELS.find(m => m.value === (selectedModel || ""))?.label.split(' - ')[0] || "Default model"}
208
+ </p>
209
+ </div>
210
+
211
  <button
212
  type="submit"
213
  disabled={isLoading}
frontend/components/generation/GenerationForm.tsx CHANGED
@@ -8,7 +8,7 @@ import { Input } from "@/components/ui/Input";
8
  import { Select } from "@/components/ui/Select";
9
  import { Button } from "@/components/ui/Button";
10
  import { Card, CardContent, CardHeader, CardTitle, CardDescription } from "@/components/ui/Card";
11
- import { IMAGE_MODELS } from "@/lib/constants/models";
12
  import type { Niche } from "@/types/api";
13
  import { Loader2, TrendingUp, Check } from "lucide-react";
14
  import apiClient from "@/lib/api/client";
@@ -65,6 +65,7 @@ export const GenerationForm: React.FC<GenerationFormProps> = ({
65
  const numImages = watch("num_images");
66
  const currentNiche = watch("niche");
67
  const useTrending = watch("use_trending");
 
68
 
69
  // Fetch trends when toggle is enabled
70
  const handleFetchTrends = async () => {
@@ -218,6 +219,16 @@ export const GenerationForm: React.FC<GenerationFormProps> = ({
218
  )}
219
  </div>
220
 
 
 
 
 
 
 
 
 
 
 
221
  <Button
222
  type="submit"
223
  variant="primary"
 
8
  import { Select } from "@/components/ui/Select";
9
  import { Button } from "@/components/ui/Button";
10
  import { Card, CardContent, CardHeader, CardTitle, CardDescription } from "@/components/ui/Card";
11
+ import { IMAGE_MODELS, getModelCost, formatCost } from "@/lib/constants/models";
12
  import type { Niche } from "@/types/api";
13
  import { Loader2, TrendingUp, Check } from "lucide-react";
14
  import apiClient from "@/lib/api/client";
 
65
  const numImages = watch("num_images");
66
  const currentNiche = watch("niche");
67
  const useTrending = watch("use_trending");
68
+ const selectedModel = watch("image_model");
69
 
70
  // Fetch trends when toggle is enabled
71
  const handleFetchTrends = async () => {
 
219
  )}
220
  </div>
221
 
222
+ {/* Cost Estimator */}
223
+ <div className="bg-gradient-to-r from-green-50 to-emerald-50 border border-green-200 rounded-xl p-4">
224
+ <p className="text-sm font-semibold text-gray-800">
225
+ 💰 <strong>Estimated Cost:</strong> {formatCost(getModelCost(selectedModel || "", numImages))}
226
+ </p>
227
+ <p className="text-xs text-gray-600 mt-1">
228
+ {numImages} image{numImages > 1 ? 's' : ''} × {IMAGE_MODELS.find(m => m.value === (selectedModel || ""))?.label.split(' - ')[0] || "Default model"}
229
+ </p>
230
+ </div>
231
+
232
  <Button
233
  type="submit"
234
  variant="primary"
frontend/lib/constants/models.ts CHANGED
@@ -3,22 +3,46 @@
3
  * These match the MODEL_REGISTRY in services/image.py
4
  */
5
  export const IMAGE_MODELS = [
6
- { value: "", label: "Default (z-image-turbo)" },
7
- // { value: "z-image-turbo", label: "Z-Image Turbo (Fast & High Quality)" },
8
- { value: "gpt-image-1.5", label: "GPT Image 1.5 (OpenAI)" },
9
- { value: "nano-banana", label: "Nano Banana (Google)" },
10
- { value: "nano-banana-pro", label: "Nano Banana Pro (Google)" },
11
- { value: "imagen-4", label: "Imagen-4 (Google)" },
12
- { value: "imagen-4-ultra", label: "Imagen-4 Ultra (Google)" },
13
- { value: "recraft-v3", label: "Recraft V3" },
14
- { value: "ideogram-v3", label: "Ideogram V3" },
15
- { value: "ideogram-v3-turbo", label: "Ideogram V3 Turbo" },
16
- { value: "photon", label: "Photon (Luma)" },
17
- { value: "seedream-3", label: "Seedream-3 (ByteDance)" },
18
- { value: "seedream-4.5", label: "Seedream-4.5 (ByteDance)" },
19
- { value: "flux-2-max", label: "Flux 2 Max (Black Forest Labs)" },
20
- { value: "qwen-image", label: "Qwen Image (Pruna AI)" },
21
- { value: "p-image", label: "P-Image (Pruna AI)" },
 
 
22
  ] as const;
23
 
24
  export type ImageModel = typeof IMAGE_MODELS[number]["value"];
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  * These match the MODEL_REGISTRY in services/image.py
4
  */
5
  export const IMAGE_MODELS = [
6
+ { value: "", label: "Default (z-image-turbo) - $0.01/image", price: 0.01, priceNote: "per megapixel" },
7
+ // { value: "z-image-turbo", label: "Z-Image Turbo (Fast & High Quality) - $0.01/image", price: 0.01, priceNote: "per megapixel" },
8
+ { value: "gpt-image-1.5", label: "GPT Image 1.5 (OpenAI) - $0.136/image", price: 0.136 },
9
+ { value: "nano-banana", label: "Nano Banana (Google) - $0.039/image", price: 0.039 },
10
+ { value: "nano-banana-pro", label: "Nano Banana Pro (Google) - $0.15/image", price: 0.15 },
11
+ { value: "imagen-4", label: "Imagen-4 (Google) - $0.04/image", price: 0.04 },
12
+ { value: "imagen-4-ultra", label: "Imagen-4 Ultra (Google) - $0.06/image", price: 0.06 },
13
+ { value: "imagen-4-fast", label: "Imagen-4 Fast (Google) - $0.02/image", price: 0.02 },
14
+ { value: "gemini-2.5-flash-image", label: "Gemini 2.5 Flash Image (Google) - $0.039/image", price: 0.039 },
15
+ { value: "recraft-v3", label: "Recraft V3", price: null },
16
+ { value: "ideogram-v3", label: "Ideogram V3", price: null },
17
+ { value: "ideogram-v3-turbo", label: "Ideogram V3 Turbo - $0.03/image", price: 0.03 },
18
+ { value: "photon", label: "Photon (Luma)", price: null },
19
+ { value: "seedream-3", label: "Seedream-3 (ByteDance)", price: null },
20
+ { value: "seedream-4.5", label: "Seedream-4.5 (ByteDance) - $0.04/image", price: 0.04 },
21
+ { value: "flux-2-max", label: "Flux 2 Max (Black Forest Labs) - $0.04/image", price: 0.04 },
22
+ { value: "qwen-image", label: "Qwen Image (Pruna AI) - $0.025/image", price: 0.025 },
23
+ { value: "p-image", label: "P-Image (Pruna AI) - $0.005/image (200 for $1)", price: 0.005 },
24
  ] as const;
25
 
26
  export type ImageModel = typeof IMAGE_MODELS[number]["value"];
27
+
28
+ /**
29
+ * Get the estimated cost for generating images with a specific model
30
+ * @param modelValue - The model identifier
31
+ * @param imageCount - Number of images to generate (default: 1)
32
+ * @returns Estimated cost in USD, or null if pricing is not available
33
+ */
34
+ export function getModelCost(modelValue: string, imageCount: number = 1): number | null {
35
+ const model = IMAGE_MODELS.find(m => m.value === modelValue);
36
+ if (!model || model.price === null) return null;
37
+ return model.price * imageCount;
38
+ }
39
+
40
+ /**
41
+ * Format the cost for display
42
+ * @param cost - Cost in USD
43
+ * @returns Formatted cost string
44
+ */
45
+ export function formatCost(cost: number | null): string {
46
+ if (cost === null) return "Pricing not available";
47
+ return `$${cost.toFixed(3)}`;
48
+ }