CoolFace
Apppublic

tahermotukuna/DesktopComputer

sourceHugging Faceupdated 6mo agoView on Hugging Face
0likes
app.py154 linesDownload Raw Back to root
1import os2import asyncio3import random4import psutil5import threading6import gradio as gr7from playwright.async_api import async_playwright8from fake_useragent import UserAgent9 10# --- 1. SYSTEM INITIALIZATION ---11print("System: Installing Playwright and Linux dependencies...")12os.system("playwright install chromium")13os.system("playwright install-deps chromium")14 15# --- 2. CONFIGURATION ---16BASE_URL = "https://www.codestorez.com"17TARGET_URL = f"{BASE_URL}/?imageShow"18 19# Dwell Time: 1m (60s) to 2m 30s (150s)20MIN_STAY = 15021MAX_STAY = 30022SPAWN_DELAY = 10 23 24DEVICES = {25    "desktop": {"width": 1920, "height": 1080, "is_mobile": False},26    "tablet": {"width": 768, "height": 1024, "is_mobile": True},27    "mobile": {"width": 390, "height": 844, "is_mobile": True}28}29 30REFERRERS = [31    "https://www.facebook.com/", "https://www.google.com/",32    "https://x.com/", "https://www.linkedin.com/",33    "https://www.reddit.com/", "https://www.bing.com/"34]35 36ua = UserAgent()37data = {"success": 0, "fail": 0, "active_sessions": 0, "log": "System Initialized"}38 39async def run_human_session(session_id):40    data["active_sessions"] += 141    selected_ref = random.choice(REFERRERS)42    dev_name = random.choice(list(DEVICES.keys()))43    profile = DEVICES[dev_name]44    45    async with async_playwright() as p:46        try:47            browser = await p.chromium.launch(48                headless=True, 49                args=['--no-sandbox', '--disable-setuid-sandbox', '--disable-dev-shm-usage', '--single-process']50            )51            52            context = await browser.new_context(53                user_agent=ua.random,54                viewport={'width': profile['width'], 'height': profile['height']},55                is_mobile=profile['is_mobile'],56                extra_http_headers={"Referer": selected_ref}57            )58            page = await context.new_page()59            60            # --- STEP 1: Landing ---61            data["log"] = f"Session {session_id}: Landing on {TARGET_URL} as {dev_name.upper()} via {selected_ref}"62            await page.goto(TARGET_URL, wait_until="networkidle", timeout=90000)63            64            # --- STEP 2: Natural Scrolling ---65            for i in range(random.randint(6, 10)):66                scroll_amt = random.randint(400, 1100)67                data["log"] = f"Session {session_id}: Scrolling {scroll_amt}px to view content/images..."68                await page.mouse.wheel(0, scroll_amt)69                await asyncio.sleep(random.uniform(4, 7))70 71            # --- STEP 3: Smart Internal Navigation ---72            data["log"] = f"Session {session_id}: Searching for internal links..."73            links = await page.query_selector_all("a")74            internal_links = []75            for link in links:76                href = await link.get_attribute("href")77                if href and (BASE_URL in href or (href.startswith("/") and not href.startswith("//"))):78                    if not any(x in href for x in ['facebook', 'twitter', 'linkedin', 'mailto:']):79                        internal_links.append(link)80 81            if internal_links:82                target = random.choice(internal_links)83                target_url = await target.get_attribute("href")84                85                await target.scroll_into_view_if_needed()86                await asyncio.sleep(random.uniform(2, 4))87                88                data["log"] = f"Session {session_id}: Clicking internal URL -> {target_url}"89                await target.click()90                await page.wait_for_load_state("networkidle")91                data["log"] = f"Session {session_id}: Now browsing page: {page.url}"92                93                # Small scroll on second page94                await page.mouse.wheel(0, random.randint(300, 600))95            96            # --- STEP 4: High-Retention Stay ---97            stay_duration = random.uniform(MIN_STAY, MAX_STAY)98            data["log"] = f"Session {session_id}: Retention Phase. Reading for {int(stay_duration)}s..."99            await asyncio.sleep(stay_duration)100            101            data["success"] += 1102            data["log"] = f"✅ Session {session_id} Successful ({dev_name.upper()})"103            104        except Exception as e:105            data["fail"] += 1106            data["log"] = f"❌ Session {session_id} Failed: {str(e)[:45]}"107        finally:108            try:109                await browser.close()110            except:111                pass112            data["active_sessions"] -= 1113 114def engine_loop():115    loop = asyncio.new_event_loop()116    asyncio.set_event_loop(loop)117    118    async def main():119        session_id = 0120        while True:121            session_id += 1122            asyncio.create_task(run_human_session(session_id))123            await asyncio.sleep(SPAWN_DELAY) 124                125    loop.run_until_complete(main())126 127threading.Thread(target=engine_loop, daemon=True).start()128 129# --- DASHBOARD UI ---130def update_dashboard():131    ram = psutil.virtual_memory().used / (1024**3)132    return (133        f"{data['success']}", 134        f"{data['fail']}", 135        f"{data['active_sessions']}",136        f"{ram:.2f} GB / 16.00 GB",137        data["log"]138    )139 140with gr.Blocks(title="Taher IT - Multi-Device Simulator") as demo:141    gr.Markdown("# 🚀 TAHER IT - DEVICE EMULATOR ENGINE")142    gr.Markdown(f"Emulating Desktop, Tablet, & Mobile | Target: `{TARGET_URL}`")143    144    with gr.Row():145        s_box = gr.Textbox(label="Success Visits", value="0")146        f_box = gr.Textbox(label="Failed Sessions", value="0")147        a_box = gr.Textbox(label="Active Browsers", value="0")148        r_box = gr.Textbox(label="RAM Usage", value="0")149    150    activity_log = gr.Textbox(label="Live Activity Log (Detailed Actions)", value="Starting...")151 152    gr.Timer(2).tick(update_dashboard, outputs=[s_box, f_box, a_box, r_box, activity_log])153 154demo.launch(server_name="0.0.0.0", server_port=7860)