Bharatgas Image Generator
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 (
)}
{error && (
);
};
export default App;
Bharatgas इमेज जनरेटर
१९:६ पोर्ट्रेट आणि सेव्ह केलेला चेहरा वापरून फिचर्ड इमेज तयार करा.
{!imageUrl && !loading && ( )} {loading && (तुमची प्रोफेशनल इमेज तयार होत आहे...
{error}
)}
{imageUrl && (
)}