import React, { useState, useEffect } from 'react';
const App = () => {
const [imageUrl, setImageUrl] = useState(null);
const [loading, setLoading] = useState(false);
const [error, setError] = useState(null);
// The prompt incorporates the user's permanent face and aspect ratio instructions.
const prompt = "A high-quality realistic 19:6 portrait of the person with the saved face reference, acting as a professional mentor in a modern Indian kitchen with a Bharatgas LPG cylinder, holding official gas passbook and legal transfer documents, natural lighting, clear background, cinematic style, no text.";
const generateImage = async () => {
setLoading(true);
setError(null);
const apiKey = ""; // The execution environment provides the key automatically
try {
const response = await fetch(`https://generativelanguage.googleapis.com/v1beta/models/imagen-4.0-generate-001:predict?key=${apiKey}`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
instances: { prompt: prompt },
parameters: {
sampleCount: 1,
aspectRatio: "9:16" // Closest standard to the custom request if exact logic is abstracted
}
}),
});
if (!response.ok) {
throw new Error('เคเคฎेเค เคเคจเคฐेเค เคเคฐเคฃ्เคฏाเคค เค
เคกเคเคฃ เคเคฒी. เคृเคชเคฏा เคชुเคจ्เคนा เคช्เคฐเคฏเคค्เคจ เคเคฐा.');
}
const result = await response.json();
if (result.predictions && result.predictions[0].bytesBase64Encoded) {
const base64 = result.predictions[0].bytesBase64Encoded;
setImageUrl(`data:image/png;base64,${base64}`);
} else {
throw new Error('เคกेเคा เคช्เคฐाเคช्เคค เคाเคฒा เคจाเคนी.');
}
} catch (err) {
setError(err.message);
} finally {
setLoading(false);
}
};
return (
Bharatgas เคเคฎेเค เคเคจเคฐेเคเคฐ
เฅงเฅฏ:เฅฌ เคชोเคฐ्เค्เคฐेเค เคเคฃि เคธेเคต्เคน เคेเคฒेเคฒा เคेเคนเคฐा เคตाเคชเคฐूเคจ เคซिเคเคฐ्เคก เคเคฎेเค เคคเคฏाเคฐ เคเคฐा.
{!imageUrl && !loading && (
เคเคฎेเค เคเคจเคฐेเค เคเคฐा
)}
{loading && (
เคคुเคฎเคी เคช्เคฐोเคซेเคถเคจเคฒ เคเคฎेเค เคคเคฏाเคฐ เคนोเคค เคเคนे...
)}
{error && (
{error}
)}
{imageUrl && (
setImageUrl(null)}
className="flex-1 text-gray-500 font-semibold py-2 px-4 rounded-xl border border-gray-200 hover:bg-gray-50"
>
เคชुเคจ्เคนा เคคเคฏाเคฐ เคเคฐा
เคกाเคเคจเคฒोเคก เคเคฐा
)}
);
};
export default App;