import os import gradio as gr from io import BytesIO import zipfile import tempfile import random import json from gradio_client import Client, handle_file import base64 from PIL import Image BUY_PREMIUM = "π₯ Get Premium Token to Unlock" STATUS_MESSAGES = { 201: "Not satisfied with the results? Get a Premium Token for instant, deeper results including social profiles.", 301: "Invalid token! Get Premium Token using link in page" } backend = Client(os.getenv("BACKEND")) def base64_to_image(base64_str): return base64.b64decode(base64_str + '=' * (-len(base64_str) % 4)) def search_face(file, token=None): result_text = backend.predict( file=handle_file(file), token=token, api_name="/search_face" ) result = json.loads(result_text) outarray = [] if result['status'] > 300: raise gr.Error(STATUS_MESSAGES[result['status']]) for item in result['result']: image = Image.open(BytesIO(base64_to_image(item['image']))) outarray.append((image, item['url'])) if result['status'] == 201: gr.Info(STATUS_MESSAGES[result['status']], duration=11) return outarray def export_images(items): if not items: return None # Create a zip file in memory zip_buffer = BytesIO() with zipfile.ZipFile(zip_buffer, 'w') as zip_file: url_text = "" i = 1 for item in items: if item[1] == BUY_PREMIUM: continue with open(item[0], 'rb') as img_file: zip_file.writestr(f'image_{i}.jpg', img_file.read()) url_text += f"image_{i}.jpg: {item[1]}\n" i += 1 zip_file.writestr("urls.txt", url_text) zip_buffer.seek(0) with tempfile.NamedTemporaryFile(delete=False, suffix=".zip") as temp_file: temp_file.write(zip_buffer.getvalue()) temp_file_path = temp_file.name return temp_file_path custom_css = """ caption.caption { user-select: text; cursor: text; } div#export_file { max-height: 63.39px; } .svelte-snayfm { height: auto; } .icon.svelte-snayfm { width: 48px; height: 48px; } .button-gradient { background: linear-gradient(45deg, #ff416c, #ff4b2b, #ff9b00, #ff416c); background-size: 400% 400%; border: none; padding: 14px 28px; font-size: 16px; font-weight: bold; color: white; border-radius: 10px; cursor: pointer; transition: 0.3s ease-in-out; animation: gradientAnimation 2s infinite linear; box-shadow: 0 4px 10px rgba(255, 65, 108, 0.6); } @keyframes gradientAnimation { 0% { background-position: 0% 50%; } 25% { background-position: 50% 100%; } 50% { background-position: 100% 50%; } 75% { background-position: 50% 0%; } 100% { background-position: 0% 50%; } } .button-gradient:hover { transform: scale(1.05); box-shadow: 0 6px 15px rgba(255, 75, 43, 0.8); } @keyframes labelGradientFlow { 0% { background-position: 0% 50%; } 50% { background-position: 100% 50%; } 100% { background-position: 0% 50%; } } label.svelte-i3tvor.float { background: linear-gradient(90deg, #555555, #333333, #555555); /* Dark gray gradient */ background-size: 200% 200%; color: #f1f1f1; font-weight: bold; text-align: center; animation: labelGradientFlow 4s infinite ease-in-out; box-shadow: 0 0 6px rgba(50, 50, 50, 0.7); /* Subtle dark glow */ transition: all 0.3s ease-in-out; } """ js = """ function aff() { const links = document.querySelectorAll('a'); const currentUrl = new URL(window.location.href); const currentParams = currentUrl.searchParams.toString(); links.forEach(link => { const href = link.getAttribute('href'); if (href && (href.startsWith('https://faceonlive.pocketsflow.com') || href.startsWith('https://faceonlive.com'))) { const targetUrl = new URL(href); // Append current page parameters to the link currentParams.split('&').forEach(param => { if (param) { const [key, value] = param.split('='); targetUrl.searchParams.set(key, value); } }); link.setAttribute('href', targetUrl.toString()); } }); return '' } """ head = """ """ output = gr.Gallery(label="Search may take a few minutes.)", columns=[3], object_fit="contain", height="480px", interactive=False) col2 = gr.Column(scale=2, visible=False) def init_ui(): return gr.update(visible=True), gr.update(visible=False) def search_ui(): return gr.update(visible=False), gr.update(visible=True) def search_face_examples(image): return search_face(image), gr.update(visible=False), gr.update(visible=True) def set_url_token(request: gr.Request): if request and request.query_params: params = dict(request.query_params) if "ptoken" in params: return params["ptoken"] return "" def update_button(token): if token: return gr.update(visible=False), gr.update(value="π Unlock Deep Search Now!", elem_classes="button-gradient") else: return gr.update(visible=True), gr.update(value="π Free Face Search", elem_classes="") MARKDOWN0 = """ # Free Face Search Online - β€οΈLike above if this space helps #### [Learn more about our Reverse Face Search](https://faceonlive.com/face-search-online) #### [Check out our Face Search API integration and Affiliate Program here.](https://portfolio.faceonlive.com/#face_search) """ MARKDOWN2 = """ ### [Why Get the Premium Token?](https://faceonlive.pocketsflow.com/checkout?productId=676c15b1971244a587ca07cb) β **Deep Search** β **Social Media and Deep Web Scan** β **Exclusive Access to Hidden Profiles** β **No Subscription Needed** """ MARKDOWN3 = """