<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Phantom AI Image Maker</title>
    <style>
        /* Basic Reset */
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: Arial, sans-serif;
        }

        .apptitle{
            padding: 15px 30px;
            border-radius: 35px;
            color: white;
            font-size: 15px;
            cursor: pointer;
            margin-top: 15px;
            margin-bottom: 10px;
            transition: all 0.3s ease;
            width: 100%;
            max-width: 250px;
            height: 60px;
            background-color: #007b3d;
            box-shadow: 0px 0px 20px rgb(13, 255, 142);
    
        }
      

        /* Body Styling */
        body {
            background: #000000;
            margin: 0;  /* Remove default margin */
            color: #ffffff;
            font-size: 16px;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            flex-direction: column;
            overflow: hidden;
            padding: 0 15px;
            position: relative;   /* This is important to position the video behind */
            overflow-y: auto; 
        }

        #video-container {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
         }


        /* Video Styling */
        #background-video {
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%); /* Centers the video */
            width: 100%;
            height: 100%;
            object-fit: cover;  /* Ensures the video covers the entire screen */
            z-index: -1;  /* Makes sure the video stays in the background */
            display: none; 
        }

        /* Content Styling */
        .content {
            position: relative;
            z-index: 1; 
            overflow-y: auto;  /* Content will appear above the video */
            /* Other content styles here */
        }
    

    
        /* App Title */
        h1 {
            font-size: 30px;
            color: #ffffff;
            margin-bottom: 10px;
            text-align: center;
        }
    
        /* Subtitle Styling */
        h2 {
            font-size: 15px;
            color: #ffffff;
            margin-bottom: 10px;
            margin-top: 15px;
            text-align: center;
        }
    
        p {
            text-align: center;
        }
    
        /* Text Input Box */
        input[type="text"] {
            width: 100%;
            max-width: 500px;
            height: 50px;
            padding: 12px;
            border-radius: 20px;
            border: 2px solid #333;
            background-color: #222;
            color: #ffffff;
            font-size: 16px;
            transition: all 0.3s ease;
            box-shadow: 0px 0px 15px rgb(102, 235, 255);
            margin-top: 30px;
            margin-bottom: 20px;
            text-align: center;
        }
    
        input[type="text"]:focus {
            outline: none;
            border-color: #45dff3;
            background-color: #000000;
           
        }
    
        /* Button Styling */
        .button, .downloadbutton ,.generateanotherbutton{
            padding: 15px 30px;
            border-radius: 35px;
            color: white;
            font-size: 18px;
            cursor: pointer;
            transition: all 0.3s ease;
            width: 100%;
            max-width: 250px;
    
        }

        .button {
            background-color: #00af58;
            box-shadow: 0px 0px 20px rgb(0, 255, 115);
        }
    
        .downloadbutton {
            background-color: #b62d00;
            box-shadow: 0px 0px 20px rgb(255, 25, 25);
            margin-top: 10px;
        }

        .generateanotherbutton {
            padding: 10px 20px;
            background-color: #0063a5;
            box-shadow: 0px 0px 20px rgb(75, 168, 255);
            margin-top: 10px;
            margin-bottom: 10px;
        }
    
    
        .image-container img {
            max-width:  200px;
            max-height: 200px;  
            object-fit: contain;
            box-shadow: 0px 0px 15px rgb(255, 255, 255);
        }

        

        /* Processing Text */
        .processingtext {
            margin-top: 15px;
            font-size: 14px;
            color: #ffffff;
            display: none;
            text-align: center;
        }

        /* Warning Text */
        .warningtext {
            margin-top: 5px;
            font-size: 14px;
            color: #ffffff;
            display: none;
            text-align: center;
        }

        /* Warning Text */
        .emptyprompttext {
        margin-top: 10px;
        font-size: 18px;
        color: #ffffff;
        display: none;
        text-align: center;
        margin-top: 30px;
        margin-bottom: 30px;
        }    

        /* Warning Text */
        .modelbusytext {
            margin-top: 10px;
            font-size: 18px;
            color: #ffffff;
            display: none;
            text-align: center;
        }    
        
        /* Fresh Prompt Text */
        .freshprompttext {
        margin-top: 10px;
        font-size: 15px;
        color: #ffffff;
        display: none;
        text-align: center;
        } 


        /* Waiting Animation */
        .wave-animation {
            display: none;
            margin: 20px 0;
            }

            .wave-animation span {
            display: inline-block;
            width: 10px;
            height: 20px;
            background-color: #ffffff;
            margin: 0 2px;
            animation: wave 1.2s infinite ease-in-out;
            }

            .wave-animation span:nth-child(2) {
            animation-delay: -1.1s;
            }

            .wave-animation span:nth-child(3) {
            animation-delay: -1.0s;
            }

            .wave-animation span:nth-child(4) {
            animation-delay: -0.9s;
            }

            .wave-animation span:nth-child(5) {
            animation-delay: -0.8s;
            }

            @keyframes wave {
            0%, 100% {
                transform: scaleY(0.4);
            }
            50% {
                transform: scaleY(1.0);
            }
            }
    
        /* Timer Display */
        .timer {
            font-size: 20px;
            margin-top: 10px;
            color: #ffffff;
            margin-top: 10px;
            margin-bottom: 10px;
            align-items: center;
        }
    
        /* Media Queries for Mobile Devices */
        @media (max-width: 768px) {
            h1 {
                font-size: 30px;
            }
    
            h2 {
                font-size: 18px;
            }
    
            .button, .downloadbutton {
                font-size: 16px;
                padding: 12px 20px;
                max-width: 200px;
            }
    
            input[type="text"] {
                font-size: 14px;
                padding: 10px;
            }
    
            .image-container {
                max-width: 100%;
                height: auto;
            }
    
            .wave span {
                font-size: 16px;
            }
    
            .timer {
                font-size: 20px;
            }

            .select {
                max-width: 70%;
                height: auto;
            }
        }
    
        /* Extra Small Devices (Phone Portrait) */
        @media (max-width: 480px) {
            h1 {
                font-size: 26px;
            }
    
            h2 {
                font-size: 16px;
            }
    
            .button, .downloadbutton {
                font-size: 14px;
                padding: 12px 18px;
                max-width: 180px;
            }
    
            input[type="text"] {
                font-size: 14px;
                padding: 8px;
            }
    
            .image-container {
                max-width: 100%;
                height: auto;
            }
    
            .wave span {
                font-size: 14px;
            }

            .timer {
                font-size: 20px;
            }

            .select {
                max-width: 70%;
                height: auto;
            }
        }

            /* Dropdown Menu to select Models */
        select {
        width: 275px;
        padding: 12px;
        border-radius: 20px;
        border: 2px solid #333;
        background-color: #222;
        color: #ffffff;
        font-size: 16px;
        transition: all 0.3s ease;
        box-shadow: 0px 0px 15px rgb(102, 235, 255);
        margin-top: 10px;
        margin-bottom: 20px;
        text-align: center;
        align-self: center;
    }
    </style>


    
</head>
<body>

    <video autoplay muted loop id="background-video" preload="auto">
        <source src="https://od.lk/s/NzdfNTkwNzEzNzlf/smokeshortloop.mp4" type="video/mp4">
        Your browser does not support the video tag.
    </video>



    <!-- App Title and Subtitle -->
    <div class="apptitle">
        <h1>Phantom AI </h1>
     </div>

    <h2>Create Free Realistic AI Images </h2>  
    <p> Usage : Free Unlimted </p>  
    <p> Resolution : 1024 X 1024 px</p>
    <p> Wait Time : 1 to 3 Minutes </p>
    
    <h2>Model Specifications </h2> 
    <p> Omni Diffusion : High Quality ( Fast )  </p>  
    <p> Maya Diffusion : High Quality ( Fast ) </p>  
    <p> Stable Diffusion 3.5 : Low Quality ( Fastest )</p>  
    <p> Nova Realism : Higher Quality ( Slow ) </p>  
    <p> Epic Diffusion : Higher Quality ( Long Wait )</p> 
    <p> Ecstasy Realism : Best Quality ( Long Wait ) </p> 
 



    <h2> [ Note : Write detailed prompts including Subject | 
        Clothing | Location | Time of Day | Posture | Activity etc
         for best results ... ] </h2>

    <!-- Input Box for Image Description -->
   
    <input type="text" id="promptInput" placeholder="Enter image description...">



    <!-- Dropdown Menu for Selecting Model -->
    <select id="modelSelect">    
        <option value="https://api-inference.huggingface.co/models/prithivMLmods/Fashion-Hut-Modeling-LoRA">Omni Diffusion - Fast</option>
        <option value="https://api-inference.huggingface.co/models/ali-vilab/In-Context-LoRA">Maya Diffusion - Fast </option>
        <option value="https://api-inference.huggingface.co/models/stabilityai/stable-diffusion-3.5-large">Stable Diffusion 3.5 - Fastest</option>
        <option value="https://api-inference.huggingface.co/models/strangerzonehf/Flux-Midjourney-Mix-LoRA">Nova Realism - Slow</option>
        <option value="https://api-inference.huggingface.co/models/Jovie/Midjourney">Epic Diffusion - Long Wait  </option>
        <option value="https://api-inference.huggingface.co/models/prithivMLmods/Canopus-LoRA-Flux-UltraRealism-2.0">Ecstasy Realism - Long Wait </option>
        
        <!-- Future models can be added here -->
    </select>

    <!-- Waiting Text and Animation -->
    <div class="emptyprompttext">
        <span> Image Prompt can never be Empty ! Please Enter Image Prompt First ! </span>
    </div>

    <!-- Button to Trigger Image Generation -->
    <button class="button" onclick="generateImage()">Generate Image</button>

    <!-- Waiting Text and Animation -->
    <div class="processingtext">
        <span> Your Image is generating Please Wait .... </span>
    </div>

     <!-- Waiting Animation -->

     <div class="wave-animation" id="waveAnimation">
        <span></span><span></span><span></span><span></span><span></span>
      </div>


   

    <!-- Waiting Text -->
    <div class="warningtext">
        <span> Please Do not close the app or minimize the screen ... </span>
        <span> Image would not be generated correctly ... </span>
    </div>

    <!-- Model Busy Text -->
    <div class="modelbusytext">
        <span> Model too Busy with high Traffic ! Try Again ... </span>
    </div>

    <div class="timer" id="timer"></div>

    <!-- Display Image After Generation -->
    <div class="image-container" id="imageContainer">
        <img id="generatedImage" src="" alt="Generated Image" style="display:none;">
        <br>
    </div>



   


    <button class="downloadbutton" id="downloadBtn" style="display:none;" onclick="downloadandroid()">Download HD Image</button>

     <!-- Fresh prompt Text -->
     <div class="freshprompttext">
    <span> Please use Fresh prompt for every new Image  ... </span>
    </div>
    

    <button class="generateanotherbutton" id="generateanotherBtn"  style="display:none;" onclick="refresh()">Generate Another</button>


    <script>

        // Get the video element and the video container
        const video = document.getElementById('background-video');
        const videoContainer = document.getElementById('video-container');

        // Add an event listener to handle when the video is ready to play
        video.addEventListener('canplaythrough', function() {
            // When the video is ready, hide the black background and show the video
            video.style.display = 'block'; // Show the video
        });

        // Optionally, handle the case where the video fails to load
        video.addEventListener('error', function() {
            alert('There was an error loading the video.');
        });


        // App Sounds

        let audio;  // Declare audio globally to be accessible across multiple functions

        function buttonclick() {
        const audio = new Audio('https://od.lk/s/NzdfNTkwNDMyNDlf/Button%20Click.mp3');
        audio.play();
        }   

        function errorsound() {
        const audio = new Audio('https://od.lk/s/NzdfNTkwNDQzMDhf/Error%20Sound.mp3');
        audio.play();
        }  

        function processingvoice() {
        const audio = new Audio('https://od.lk/s/NzdfNTkwNDMwNTFf/Generating%20your%20Image.mp3');
        audio.play();
        }    


        function finish() {
        const audio = new Audio('https://od.lk/s/NzdfNTkwNDMxNDRf/finish.mp3');
        audio.play();
        } 


        function processingmusic() {
        // If the audio object is not initialized, create a new one
        if (!audio) {
            audio = new Audio('https://od.lk/s/NzdfNTkyMzg0MzNf/loopmusic2.mp3');
        }

        // Play the audio if it is not playing
        if (audio.paused) {
            audio.play();
        }
        }

        // Function to stop the processing music (pause and reset)
        function stopProcessingMusic() {
        if (audio && !audio.paused) {
            audio.pause();  // Pause the music
            audio.currentTime = 0;  // Optionally reset to the start
        }
        }



        // Function to handle the image generation
        async function generateImage() {
            // Show waiting animation and hide image container
            document.querySelector('.processingtext').style.display = 'block';
            document.querySelector('.warningtext').style.display = 'block';
            document.querySelector('.emptyprompttext').style.display = 'none';
            document.querySelector('.modelbusytext').style.display = 'none';
            document.querySelector('.freshprompttext').style.display = 'none';
            document.getElementById('waveAnimation').style.display = 'block';
            document.getElementById('imageContainer').style.display = 'none';
            document.getElementById('generatedImage').style.display = 'none';
            document.getElementById('downloadBtn').style.display = 'none';
            document.getElementById('generateanotherBtn').style.display = 'none';
            document.getElementById('timer').innerText = "Elapsed Time : 00:00"; // Reset Timer


          

            // Start Timer
            startTime = Date.now();
            timerInterval = setInterval(updateTimer, 1000); // Update every second

            // Get input text
            const prompt = document.getElementById('promptInput').value;
            const modelUrl = document.getElementById("modelSelect").value;  // Get selected model URL

            if (!prompt) {
                console.error('Please Enter a Prompt First !');
                errorsound()
                document.querySelector('.emptyprompttext').style.display = 'block';
                document.querySelector('.button').style.display = 'none';
                document.querySelector('.processingtext').style.display = 'none';
                document.querySelector('.warningtext').style.display = 'none';
                document.querySelector('.timer').style.display = 'none';
                document.getElementById('waveAnimation').style.display = 'none'; 
                document.getElementById('downloadBtn').style.display = 'none';
                document.getElementById('generateanotherBtn').style.display = 'block';
                document.getElementById('promptInput').style.display = 'none'; 
                document.getElementById('modelSelect').style.display = 'none'; 
                clearInterval(timerInterval);
                return;
            }

            // API request data
            const data = {
                inputs: prompt
            };

            try {
                // API Call to the Flux API model
                  
                // Play Sound for Generating Your Image
                buttonclick()
                processingvoice()
                processingmusic()
    
                const response = await fetch(modelUrl,
                    {
                        headers: {
                            "Authorization": "Bearer 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",
                            "Content-Type": "application/json"
                        },
                        method: "POST",
                        body: JSON.stringify(data),
                    }
                    


                );

                // Check if the response is okay
                if (!response.ok) {
                    const errorData = await response.json();
                    console.error('Error from API:', errorData);
                    throw new Error('Failed to generate image');
                }

                // Convert response to blob (image)
                const imageBlob = await response.blob();

                // Create an image URL from the blob
                const imageUrl = URL.createObjectURL(imageBlob);

                // Hide waiting animation and show the image
                document.querySelector('.button').style.display = 'none';
                document.querySelector('.processingtext').style.display = 'none';
                document.querySelector('.warningtext').style.display = 'none';
                document.getElementById('waveAnimation').style.display = 'none'; 
                document.getElementById('imageContainer').style.display = 'block';
                document.getElementById('generatedImage').style.display = 'block';
                document.getElementById('generatedImage').src = imageUrl;

                // Play Task Finish Sound
                stopProcessingMusic()
                finish()

                // Enable the download button
                document.getElementById('downloadBtn').style.display = 'block';
                document.querySelector('.freshprompttext').style.display = 'block';
                document.getElementById('generateanotherBtn').style.display = 'block';

                document.getElementById("promptInput").value = "";
                document.getElementById('promptInput').style.display = 'none'; 
                document.getElementById('modelSelect').style.display = 'block'; 

        
                // Stop the timer
                clearInterval(timerInterval);

            } catch (error) {
                stopProcessingMusic()
                errorsound()
                console.error('Error generating image:', error);
                document.querySelector('.button').style.display = 'none';
                document.querySelector('.modelbusytext').style.display = 'block';
                document.querySelector('.processingtext').style.display = 'none';
                document.querySelector('.warningtext').style.display = 'none';
                document.querySelector('.timer').style.display = 'none';
                document.getElementById('waveAnimation').style.display = 'none'; 
                document.getElementById('downloadBtn').style.display = 'none';
                document.getElementById('generateanotherBtn').style.display = 'block';
                document.getElementById('promptInput').style.display = 'none'; 
                document.querySelector('.freshprompttext').style.display = 'none';
                clearInterval(timerInterval);
            }
        }

        function downloadandroid() {
            const image = document.getElementById('generatedImage');
            const imageUrl = image.src; // This could be a blob URL (blob://)
            
            // Check if it's a blob URL
            if (imageUrl.startsWith('blob:')) {
                // Convert the blob URL to a blob object
                fetch(imageUrl)
                    .then(response => response.blob())
                    .then(blob => {
                        // Create a FileReader to read the blob data
                        const reader = new FileReader();
                        reader.onloadend = function() {
                            // Send the base64 string to the Android WebView
                            const base64String = reader.result.split(',')[1]; // Get the base64 part
                            // Call a JavaScript function on Android
                            window.Android.downloadBlob(base64String);
                        };
                        reader.readAsDataURL(blob); // Convert blob to base64 string
                    })
                    .catch(error => {
                        console.error("Error downloading blob:", error);
                    });
            } else {
                // If it's not a blob URL, just create a normal download link
                const link = document.createElement('a');
                link.href = imageUrl;
                link.download = 'Flux_Image.png';
                link.click();
            }
        }


            // Function to handle image download
        function download() {
        const image = document.getElementById('generatedImage');
        const imageUrl = image.src;
        const link = document.createElement('a');
        link.href = imageUrl;
        link.download = 'Flux_Image.png';
        link.click();
        }




        // Update Timer Function
        function updateTimer() 
        {
            const elapsedTime = Math.floor((Date.now() - startTime) / 1000);
            const minutes = String(Math.floor(elapsedTime / 60)).padStart(2, '0');
            const seconds = String(elapsedTime % 60).padStart(2, '0');
            document.getElementById('timer').innerText = `Elapsed Time : ${minutes}:${seconds}`;
        }

        function refresh() {
        location.reload(); // Reload the current page    
        }

   
    
    </script>

</body>
</html>
