import os import shutil import tempfile from git import Repo from huggingface_hub import upload_folder import gradio as gr HF_TOKEN = os.getenv("HF_TOKEN") GITHUB_REPO = "https://github.com/JawadAliAI/Cybersecurity-ProjectS.git" TARGET_SPACE = "Muhammadidrees/cyberpunk" def clone_and_store(): if not HF_TOKEN: return "❌ HF_TOKEN not found. Add it in Space → Settings → Secrets." tmp_dir = tempfile.mkdtemp() try: repo_path = os.path.join(tmp_dir, "github_repo") # 1️⃣ Clone GitHub repository Repo.clone_from(GITHUB_REPO, repo_path) # 2️⃣ Remove git metadata shutil.rmtree(os.path.join(repo_path, ".git"), ignore_errors=True) # 3️⃣ Upload contents to Hugging Face Space upload_folder( folder_path=repo_path, repo_id=TARGET_SPACE, repo_type="space", token=HF_TOKEN, commit_message="Deploy Cybersecurity-ProjectS from GitHub" ) return "✅ GitHub repository successfully stored in Hugging Face Space!" except Exception as e: return f"❌ Error: {str(e)}" finally: shutil.rmtree(tmp_dir, ignore_errors=True) # 🎛 Minimal UI with gr.Blocks(title="GitHub → Hugging Face Space Deployer") as demo: gr.Markdown("## 🚀 Deploy Cybersecurity Project to Hugging Face Space") status = gr.Textbox(label="Status", lines=3) deploy_btn = gr.Button("Clone & Store") deploy_btn.click(clone_and_store, outputs=status) demo.launch()