diff --git a/app/api_routes.py b/app/api_routes.py
index e375463..14778e9 100644
--- a/app/api_routes.py
+++ b/app/api_routes.py
@@ -479,7 +479,6 @@ def api_create_image() -> Response:
else:
data = request.get_json()
prompt: str = data.get("query")
- print(prompt, user.id)
image: Image = Image(
prompt=prompt,
user_id=user.id,
diff --git a/client/bun.lockb b/client/bun.lockb
index a846132..d8e95a6 100755
Binary files a/client/bun.lockb and b/client/bun.lockb differ
diff --git a/client/src/components/Navbar.tsx b/client/src/components/Navbar.tsx
index b10e6a6..50ad163 100644
--- a/client/src/components/Navbar.tsx
+++ b/client/src/components/Navbar.tsx
@@ -24,11 +24,7 @@ export default function Navbar() {
Hub
-
-
- Imagine
-
-
+
{user == null ? (
<>
diff --git a/client/src/components/modals/command-modal.tsx b/client/src/components/modals/command-modal.tsx
index 784553c..c554bc4 100644
--- a/client/src/components/modals/command-modal.tsx
+++ b/client/src/components/modals/command-modal.tsx
@@ -23,6 +23,7 @@ import {
} from "lucide-react";
import {
useCreateChatbotModal,
+ useImagineModal,
useSettingsModal,
useTranslateMagicModal,
useTtsMagicModal,
@@ -34,6 +35,7 @@ export function CommandModal() {
const createBotModal = useCreateChatbotModal();
const settingsModal = useSettingsModal();
+ const imagineModal = useImagineModal();
const ttsModal = useTtsMagicModal();
const translateModal = useTranslateMagicModal();
const navigate = useNavigate();
@@ -80,12 +82,7 @@ export function CommandModal() {
Translate Magic
- {
- setOpen(false);
- navigate("/imagine");
- }}
- >
+ imagineModal.onOpen()}>
Generate Images
diff --git a/client/src/components/modals/imgine-modal.tsx b/client/src/components/modals/imgine-modal.tsx
new file mode 100644
index 0000000..8e8e787
--- /dev/null
+++ b/client/src/components/modals/imgine-modal.tsx
@@ -0,0 +1,166 @@
+import {
+ AlertDialog,
+ AlertDialogContent,
+ AlertDialogDescription,
+ AlertDialogFooter,
+ AlertDialogHeader,
+ AlertDialogTitle,
+} from "@/components/ui/alert-dialog";
+import { imageSrc, SERVER_URL } from "@/lib/utils";
+import { useImagineModal } from "@/stores/modal-store";
+import axios from "axios";
+import { Button } from "../ui/button";
+import toast from "react-hot-toast";
+import { Textarea } from "../ui/textarea";
+import { Pickaxe, X } from "lucide-react";
+import { useState } from "react";
+import { Skeleton } from "../ui/skeleton";
+
+export default function ImagineModal() {
+ const modal = useImagineModal();
+ const [text, setText] = useState("");
+ const [loading, setLoading] = useState(false);
+ const [generated, setGenerated] = useState(false);
+ const [imagePrompt, setImagePrompt] = useState(null);
+
+ const GenerateImage = async () => {
+ if (text.length <= 3) {
+ toast.error("Come on write something unique.");
+ return;
+ }
+ setGenerated(false);
+ setImagePrompt("");
+ setImagePrompt(text);
+ setGenerated(true);
+ };
+
+ const SaveImage = async () => {
+ setLoading(true);
+ try {
+ if (imagePrompt && imagePrompt.length <= 3) {
+ toast.error("Come on write something unique.");
+ return;
+ }
+ const token = localStorage.getItem("token");
+
+ const authHeaders = {
+ Authorization: `Bearer ${token || ""}`,
+ };
+ const response = await axios.post(
+ `${SERVER_URL}/api/imagine`,
+ {
+ query: imagePrompt,
+ },
+ {
+ headers: authHeaders,
+ }
+ );
+ if (response.data.success) {
+ setImagePrompt("");
+ setGenerated(false);
+ setText("");
+ } else {
+ toast.error("Error in saving image");
+ }
+ } catch (error: any) {
+ const errorMessage =
+ error.response?.data?.message ||
+ error.message ||
+ "An unexpected error occurred.";
+ toast.error(errorMessage);
+ console.log("[GENERATION_ERROR]", error);
+ } finally {
+ setLoading(false);
+ }
+ };
+
+ return (
+ modal.onClose()}>
+
+
+
+
+
Imgine a image and generate it
+
+
+
+
+ Let's see how you imagination is. I know you are creative enough.
+
+
+ {generated && imagePrompt && (
+
+
+
+ )}
+
+
+
+
+
+
+ If you want to save this Image in database then Click 'Capture'
+
+
+
+
+
+
+ );
+}
+
+function ImageWithLoading({ imagePrompt }: { imagePrompt: string }) {
+ const [loading, setLoading] = useState(true);
+ // Handle when image loads
+ const handleImageLoad = () => {
+ setLoading(false); // Hide loader
+ };
+ return (
+
+ {loading && (
+
+
+
+ )}
+
![{imagePrompt}]({imageSrc(imagePrompt)})
+
+ );
+}
diff --git a/client/src/contexts/modals.tsx b/client/src/contexts/modals.tsx
index 1fb8dd6..d666ba4 100644
--- a/client/src/contexts/modals.tsx
+++ b/client/src/contexts/modals.tsx
@@ -1,5 +1,6 @@
import CreateChatbotModal from "@/components/modals/create-chatbot-modal";
import DeleteChatbotModal from "@/components/modals/delete-chatbot-modal";
+import ImagineModal from "@/components/modals/imgine-modal";
import SettingsModal from "@/components/modals/settings-modal";
import ShareModal from "@/components/modals/share-modal";
import TranslateMagicModal from "@/components/modals/translate-magic-modal";
@@ -17,6 +18,7 @@ export default function Modals() {
+
>
);
diff --git a/client/src/stores/modal-store.ts b/client/src/stores/modal-store.ts
index e8ea395..debc8ff 100644
--- a/client/src/stores/modal-store.ts
+++ b/client/src/stores/modal-store.ts
@@ -9,3 +9,4 @@ export const useSettingsModal = create(defaultModalValues);
export const useShareModal = create(defaultModalValues);
export const useTtsMagicModal = create(defaultModalValues);
export const useTranslateMagicModal = create(defaultModalValues);
+export const useImagineModal = create(defaultModalValues);