Spaces:
Sleeping
Sleeping
| 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() | |