Download src/streamlit_app.py from faiz3123/vibing: direct link, hf CLI and curl.
- Browser
- Download file 3.62 kB
-
https://huggingface.co/spaces/faiz3123/vibing/resolve/main/src/streamlit_app.py
- Command line
-
hf download hf://spaces/faiz3123/vibing/src/streamlit_app.py
-
curl -L -o streamlit_app.py https://huggingface.co/spaces/faiz3123/vibing/resolve/main/src/streamlit_app.py
3.62 kB
| import streamlit as st | |
| import time | |
| import random | |
| import csv | |
| import os | |
| from faker import Faker | |
| from playwright.sync_api import sync_playwright | |
| st.set_page_config(page_title="Playwright HF Runner", layout="centered") | |
| st.title("🤖 Playwright Automation (Hugging Face)") | |
| # --------------------------- | |
| # Safety checks | |
| # --------------------------- | |
| if not os.path.exists(os.path.expanduser("~/.cache/ms-playwright")): | |
| st.error( | |
| "Playwright browsers are not installed.\n\n" | |
| "Make sure `playwright install chromium` is run during build." | |
| ) | |
| st.stop() | |
| # --------------------------- | |
| # Data | |
| # --------------------------- | |
| NAMES = [ | |
| "Ahmad","Amin","Anas","Arif","Hadi","Hafiz","Ilyas","Irfan","Isa","Ismail", | |
| "Jamal","Kareem","Mahmoud","Malik","Munir","Nadir","Nasser","Qasim","Rafi", | |
| "Salim","Sami","Taha","Usama","Yahya","Zainab","Aisha","Amira","Asiya", | |
| "Fatima","Hafsa","Iman","Iqra","Jamila","Maryam","Nour","Safiya","Salma" | |
| ] | |
| def generate_data(count: int): | |
| fake = Faker("en_US") | |
| rows = [] | |
| for _ in range(count): | |
| first = random.choice(NAMES) | |
| last = random.choice(NAMES) | |
| rows.append({ | |
| "name": f"{first} {last}", | |
| "email": f"{first.lower()}.{last.lower()}{random.randint(1000,9999)}@gmail.com", | |
| "password": fake.password(length=12) | |
| }) | |
| with open("muslim_data.csv", "w", newline="", encoding="utf-8") as f: | |
| writer = csv.DictWriter(f, fieldnames=["name", "email", "password"]) | |
| writer.writeheader() | |
| writer.writerows(rows) | |
| return rows | |
| # --------------------------- | |
| # UI | |
| # --------------------------- | |
| iterations = st.number_input( | |
| "Iterations (keep LOW on HF)", | |
| min_value=1, | |
| max_value=5, | |
| value=1 | |
| ) | |
| start = st.button("🚀 Start Automation") | |
| log_area = st.empty() | |
| def log(msg): | |
| log_area.code(msg) | |
| # --------------------------- | |
| # Automation | |
| # --------------------------- | |
| if start: | |
| st.warning("Running headless browser automation…") | |
| data = generate_data(iterations) | |
| URL = "https://vibe-to-hn-glow.lovable.app/#/product/5a3e92a6-72c0-45fd-9e4d-eb9ee9e4d3e7" | |
| with sync_playwright() as p: | |
| browser = p.chromium.launch( | |
| headless=True, | |
| args=[ | |
| "--no-sandbox", | |
| "--disable-dev-shm-usage", | |
| "--disable-gpu" | |
| ] | |
| ) | |
| for i in range(iterations): | |
| creds = data[i] | |
| log(f"Iteration {i+1}\n{creds['email']}") | |
| page = browser.new_page() | |
| try: | |
| page.goto(URL, timeout=60000) | |
| page.wait_for_load_state("networkidle") | |
| time.sleep(2) | |
| upvote = page.locator( | |
| 'div.hn-item-row:has(a:has-text("Anqair")) button:has(span:has-text("▲"))' | |
| ).first | |
| if upvote.is_visible(): | |
| upvote.click() | |
| log("▲ Clicked") | |
| create = page.locator('button.hn-link-orange:has-text("create one")').first | |
| if create.is_visible(): | |
| create.click() | |
| time.sleep(1) | |
| page.locator('input[type="email"]').fill(creds["email"]) | |
| page.locator('input[type="password"]').fill(creds["password"]) | |
| page.locator('button:has-text("Create")').click() | |
| log("Account created") | |
| except Exception as e: | |
| log(f"Error: {e}") | |
| page.close() | |
| time.sleep(1) | |
| browser.close() | |
| st.success("✅ Done") | |