import requests import json import base64 import io import os from PIL import Image import gradio as gr import uuid # import tqdm # import time theme = gr.themes.Soft().set( body_background_fill='*primary_50', # block_border_width='*block_label_border_width', # block_border_width_dark='*checkbox_border_width', button_secondary_background_fill='*primary_500', # button_secondary_background_fill_dark='*primary_700', button_secondary_background_fill_hover='*primary_400', button_secondary_border_color='*primary_100', # button_secondary_border_color_dark='*primary_700', button_secondary_text_color='*button_primary_text_color' ) init_html = '''
''' js_payment = """ function pay() { const buttonContainer = document.getElementById("buttonContainer"); const payButton = document.getElementById("payButton"); // Set the href attribute payButton.href = "https://piczify.lemonsqueezy.com/checkout/custom/283c32f2-7635-4809-af0a-6adf8f853cda?signature=4b486a404cf7d5751e7fc8b38f15a63bef909028ccbfc1a97b5efb4121c1f9fd"; payButton.textContent = "Click here to Pay 9.99$"; // Apply button styles payButton.style.display = "inline-block"; payButton.style.padding = "10px 20px"; payButton.style.backgroundColor = "#007bff"; payButton.style.color = "#fff"; payButton.style.textDecoration = "none"; payButton.style.border = "none"; payButton.style.borderRadius = "5px"; payButton.style.cursor = "pointer"; payButton.style.fontSize = "16px"; // Add the button to the container buttonContainer.appendChild(payButton); } """ scripts = """ function game() { var parentX = document.querySelector(".sliding-puzzle").clientHeight; var baseDistance = 34.5; var tileMap = { 1: { tileNumber: 1, position: 1, top: 0, left: 0 }, 2: { tileNumber: 2, position: 2, top: 0, left: baseDistance * 1 }, 3: { tileNumber: 3, position: 3, top: 0, left: baseDistance * 2 }, 4: { tileNumber: 4, position: 4, top: baseDistance, left: 0 }, 5: { tileNumber: 5, position: 5, top: baseDistance, left: baseDistance }, 6: { tileNumber: 6, position: 6, top: baseDistance, left: baseDistance * 2 }, 7: { tileNumber: 7, position: 7, top: baseDistance * 2, left: 0 }, 8: { tileNumber: 8, position: 8, top: baseDistance * 2, left: baseDistance }, empty: { position: 9, top: baseDistance * 2, left: baseDistance * 2 } } var history = []; function movementMap(position) { if (position == 9) return [6, 8]; if (position == 8) return [5, 7, 9]; if (position == 7) return [4, 8]; if (position == 6) return [3, 5, 9]; if (position == 5) return [2, 4, 6, 8]; if (position == 4) return [1, 5, 7]; if (position == 3) return [2, 6]; if (position == 2) return [1, 3, 5]; if (position == 1) return [2, 4]; } document.querySelector('#shuffle').addEventListener('click', shuffle , true); document.querySelector('#solve').addEventListener('click', solve , true); var tiles = document.querySelectorAll('.tile'); var delay = -50; for(var i = 0; i < tiles.length; i++) { tiles[i].addEventListener('click', tileClicked ,true ); var tileId = tiles[i].innerHTML; delay += 50; setTimeout(setup, delay, tiles[i]); } function setup(tile) { var tileId = tile.innerHTML; var xMovement = parentX * (tileMap[tileId].left/100); var yMovement = parentX * (tileMap[tileId].top/100); var translateString = "translateX(" + xMovement + "px) " + "translateY(" + yMovement + "px)" tile.style.webkitTransform = translateString; recolorTile(tile, tileId); } function tileClicked(event) { var tileNumber = event.target.innerHTML; moveTile(event.target); if (checkSolution()) { console.log("You win!"); } } function moveTile(tile, recordHistory = true) { var tileNumber = tile.innerHTML; if (!tileMovable(tileNumber)) { console.log("Tile " + tileNumber + " can't be moved."); return; } if (recordHistory == true) { if (history.length >= 3) { if (history[history.length-1] != history[history.length-3]) history.push(tileNumber); } else { history.push(tileNumber); } } var emptyTop = tileMap.empty.top; var emptyLeft = tileMap.empty.left; var emptyPosition = tileMap.empty.position; tileMap.empty.top = tileMap[tileNumber].top; tileMap.empty.left = tileMap[tileNumber].left; tileMap.empty.position = tileMap[tileNumber].position; var xMovement = parentX * (emptyLeft/100); var yMovement = parentX * (emptyTop/100); var translateString = "translateX(" + xMovement + "px) " + "translateY(" + yMovement + "px)" tile.style.webkitTransform = translateString; tileMap[tileNumber].top = emptyTop; tileMap[tileNumber].left = emptyLeft; tileMap[tileNumber].position = emptyPosition; recolorTile(tile, tileNumber); } function tileMovable(tileNumber) { var selectedTile = tileMap[tileNumber]; var emptyTile = tileMap.empty; var movableTiles = movementMap(emptyTile.position); if (movableTiles.includes(selectedTile.position)) { return true; } else { return false; } } function checkSolution() { if (tileMap.empty.position !== 9) return false; for (var key in tileMap) { if ((key != 1) && (key != "empty")) { if (tileMap[key].position < tileMap[key-1].position) return false; } } history = []; return true; } function recolorTile(tile, tileId) { if (tileId == tileMap[tileId].position) { tile.classList.remove("error"); } else { tile.classList.add("error"); } } shuffleTimeouts = []; function shuffle() { clearTimers(solveTimeouts); var boardTiles = document.querySelectorAll('.tile'); var shuffleDelay = 200; shuffleLoop(); var shuffleCounter = 0; while (shuffleCounter < 20) { shuffleDelay += 200; shuffleTimeouts.push(setTimeout(shuffleLoop, shuffleDelay)); shuffleCounter++; } } var lastShuffled; function shuffleLoop() { var emptyPosition = tileMap.empty.position; var shuffleTiles = movementMap(emptyPosition); var tilePosition = shuffleTiles[Math.floor(Math.floor(Math.random()*shuffleTiles.length))]; var locatedTile; for(var i = 1; i <= 8; i++) { if (tileMap[i].position == tilePosition) { var locatedTileNumber = tileMap[i].tileNumber; locatedTile = tiles[locatedTileNumber-1]; } } if (lastShuffled != locatedTileNumber) { moveTile(locatedTile); lastShuffled = locatedTileNumber; } else { shuffleLoop(); } } function clearTimers(timeoutArray) { for (var i = 0; i < timeoutArray.length; i++) { clearTimeout(timeoutArray[i]) } } solveTimeouts = [] function solve() { clearTimers(shuffleTimeouts); repeater = history.length; for (var i = 0; i < repeater; i++) { console.log("started"); solveTimeouts.push(setTimeout(moveTile, i*100, tiles[history.pop()-1], false)); } } } """ git_html_start = f"""