doc: added methods to generateImage method

This commit is contained in:
Leon Xu committed 2023-01-30 15:37:07 -08:00
1 parent 107a6df34b
commit 9f899183b7
1 file changed
+22 -1
+22 -1
View File
@@ -28,7 +28,28 @@ const CreatePost = () => {
setForm({ ...form, prompt: randomPrompt });
};
const generateImage = () => {};
const generateImage = async () => {
if (form.prompt) {
try {
setGeneratingImg(true);
const response = await fetch("http://localhost:8000/api/v1/dalle", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ prompt: form.prompt }),
});
const data = await response.json();
setForm({ ...form, photo: `data:image/jpeg;base64,${data.photo}` });
} catch (error) {
console.log(error);
} finally {
setGeneratingImg(false);
}
} else {
alert("Please enter a prompt");
}
};
return (
<section className="max-w-7xl mx-auto">