File size: 1,543 Bytes
a07f228
 
 
 
f9ce145
a07f228
 
 
 
f9ce145
 
a07f228
 
f9ce145
a07f228
f9ce145
a07f228
 
 
 
 
 
f9ce145
 
 
 
 
 
 
 
 
 
 
 
 
a07f228
 
f9ce145
a07f228
 
 
 
 
 
 
 
f9ce145
 
 
 
 
 
a07f228
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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()