Harsha1845 commited on
Commit
2965cdb
·
verified ·
1 Parent(s): b41929f

Update src/App.tsx

Browse files
Files changed (1) hide show
  1. src/App.tsx +15 -5
src/App.tsx CHANGED
@@ -14,6 +14,7 @@ function App() {
14
  const [generatedResult, setGeneratedResult] = useState<string | null>(null);
15
  const [isGenerating, setIsGenerating] = useState(false);
16
  const [generationError, setGenerationError] = useState<string | null>(null);
 
17
 
18
  const handleSelectProduct = (product: Product) => {
19
  setSelectedProduct(product);
@@ -26,13 +27,12 @@ function App() {
26
  setUserImage(null);
27
  setGeneratedResult(null);
28
  setGenerationError(null);
 
29
  };
30
 
31
  const handleCapture = async (imageSrc: string) => {
32
  setUserImage(imageSrc);
33
  setCurrentView(AppView.RESULT);
34
-
35
- // Automatically trigger generation
36
  if (selectedProduct) {
37
  await processTryOn(imageSrc, selectedProduct);
38
  }
@@ -41,13 +41,21 @@ function App() {
41
  const processTryOn = async (imageSrc: string, product: Product) => {
42
  setIsGenerating(true);
43
  setGenerationError(null);
 
 
44
  try {
45
  const resultImage = await generateTryOn(imageSrc, product);
46
  setGeneratedResult(resultImage);
47
  } catch (error: any) {
48
  console.error("Try-on failed", error);
49
- // Show the actual error message which helps with debugging (e.g. "API Key missing")
50
- setGenerationError(error.message || "Sorry, we couldn't generate the try-on image.");
 
 
 
 
 
 
51
  } finally {
52
  setIsGenerating(false);
53
  }
@@ -57,11 +65,11 @@ function App() {
57
  setCurrentView(AppView.CAMERA);
58
  setGeneratedResult(null);
59
  setGenerationError(null);
 
60
  };
61
 
62
  return (
63
  <div className="min-h-screen bg-slate-50 font-sans text-slate-900">
64
-
65
  {currentView === AppView.CATALOG && (
66
  <>
67
  <Navigation showBack={false} />
@@ -101,7 +109,9 @@ function App() {
101
  generatedImage={generatedResult}
102
  loading={isGenerating}
103
  error={generationError}
 
104
  onRetake={handleRetake}
 
105
  />
106
  </>
107
  )}
 
14
  const [generatedResult, setGeneratedResult] = useState<string | null>(null);
15
  const [isGenerating, setIsGenerating] = useState(false);
16
  const [generationError, setGenerationError] = useState<string | null>(null);
17
+ const [retryAfter, setRetryAfter] = useState<number | null>(null);
18
 
19
  const handleSelectProduct = (product: Product) => {
20
  setSelectedProduct(product);
 
27
  setUserImage(null);
28
  setGeneratedResult(null);
29
  setGenerationError(null);
30
+ setRetryAfter(null);
31
  };
32
 
33
  const handleCapture = async (imageSrc: string) => {
34
  setUserImage(imageSrc);
35
  setCurrentView(AppView.RESULT);
 
 
36
  if (selectedProduct) {
37
  await processTryOn(imageSrc, selectedProduct);
38
  }
 
41
  const processTryOn = async (imageSrc: string, product: Product) => {
42
  setIsGenerating(true);
43
  setGenerationError(null);
44
+ setRetryAfter(null);
45
+
46
  try {
47
  const resultImage = await generateTryOn(imageSrc, product);
48
  setGeneratedResult(resultImage);
49
  } catch (error: any) {
50
  console.error("Try-on failed", error);
51
+
52
+ // Extract wait time if it's a rate limit error
53
+ const waitMatch = error.message?.match(/retry in ([\d\.]+)s/);
54
+ if (waitMatch) {
55
+ setRetryAfter(Math.ceil(parseFloat(waitMatch[1])));
56
+ } else {
57
+ setGenerationError(error.message || "Sorry, we couldn't generate the try-on image.");
58
+ }
59
  } finally {
60
  setIsGenerating(false);
61
  }
 
65
  setCurrentView(AppView.CAMERA);
66
  setGeneratedResult(null);
67
  setGenerationError(null);
68
+ setRetryAfter(null);
69
  };
70
 
71
  return (
72
  <div className="min-h-screen bg-slate-50 font-sans text-slate-900">
 
73
  {currentView === AppView.CATALOG && (
74
  <>
75
  <Navigation showBack={false} />
 
109
  generatedImage={generatedResult}
110
  loading={isGenerating}
111
  error={generationError}
112
+ retryAfter={retryAfter}
113
  onRetake={handleRetake}
114
+ onRetry={() => processTryOn(userImage, selectedProduct)}
115
  />
116
  </>
117
  )}