import gradio as gr from datetime import datetime from datasets import Dataset, load_dataset from huggingface_hub import login, HfApi import pandas as pd import os import time import tempfile import logging logging.basicConfig(level=logging.INFO) logger = logging.getLogger(__name__) HF_TOKEN = os.environ.get("HF_TOKEN") if HF_TOKEN: login(token=HF_TOKEN) logger.info("Authenticated with Hugging Face") else: logger.warning("HF_TOKEN not found - running without authentication") # ============================ # AUTOβINITIALIZE DATASETS # ============================ from huggingface_hub import HfApi, HfFileSystem import pandas as pd import pyarrow as pa import pyarrow.parquet as pq import io api = HfApi() fs = HfFileSystem() # Define the schema for your registration system REGISTRATION_COLUMNS = ["name", "email", "team", "timestamp"] def ensure_dataset_initialized(dataset_id): """Ensure the dataset exists and contains a valid Parquet file.""" print(f"[INIT] Checking dataset: {dataset_id}") # 1. Ensure the dataset repo exists try: api.repo_info(dataset_id, repo_type="dataset") print(f"[INIT] Dataset {dataset_id} exists.") except: print(f"[INIT] Dataset {dataset_id} does not exist. Creating it...") api.create_repo(dataset_id, repo_type="dataset", exist_ok=True) # 2. Check for existing Parquet file parquet_repo_path = f"datasets/{dataset_id}/data.parquet" if fs.exists(parquet_repo_path): print(f"[INIT] Found existing Parquet file in {dataset_id}") return print(f"[INIT] No Parquet file found in {dataset_id}. Creating a new one...") # 3. Create an empty Parquet file with the correct schema df = pd.DataFrame(columns=REGISTRATION_COLUMNS) table = pa.Table.from_pandas(df) buffer = io.BytesIO() pq.write_table(table, buffer) buffer.seek(0) # 4. Upload the new Parquet file api.upload_file( path_or_fileobj=buffer, path_in_repo="data.parquet", #path_in_repo="data.parquet", repo_id=dataset_id, repo_type="dataset" ) print(f"[INIT] Created new Parquet file for {dataset_id}") DATASET_NAME = "osaaso/registrations"#"build-small-hackathon/build-small-hackathon-registrations" # Auto-backups land under the user namespace (not the org) so the org's dataset # list isn't polluted with thousands of timestamped backup repos. The HF_TOKEN # secret on the Space must have write access to BOTH the org dataset (above) # and this user namespace. BACKUP_DATASET_PREFIX = "osaaso/build-small-hackathon-registrations-auto-backup" #"ysharma/build-small-hackathon-registrations-auto-backup" DISCORD_INVITE = "https://discord.gg/YHECTft87Z" DISCORD_CHANNEL = "build-small-hackathon-official" # Initialize both datasets before the app starts ensure_dataset_initialized(DATASET_NAME) ensure_dataset_initialized(BACKUP_DATASET_PREFIX) # Hero layout: banner on the left, stacked info cards on the right. HERO_HTML = """
{DISCORD_CHANNEL} Β· office hours, AMAs, and support.