File size: 2,731 Bytes
e1b76ea
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/bin/bash
# KnowLedge - Hugging Face Space deployment guide
# Run each block manually in sequence.
# Prerequisites: huggingface_hub installed, HF account created

# -- Step 1: Install HF CLI -------------------------------------------------
pip install huggingface_hub

# -- Step 2: Login to Hugging Face ------------------------------------------
huggingface-cli login
# Paste your HF token when prompted
# Get token at: https://huggingface.co/settings/tokens
# Token needs "write" permission

# -- Step 3: Create the Space ------------------------------------------------
python3 - << 'EOF'
from huggingface_hub import HfApi
api = HfApi()
api.create_repo(
    repo_id="knowledge-inference",   # becomes: your-username/knowledge-inference
    repo_type="space",
    space_sdk="gradio",
    private=False,                    # must be public for free ZeroGPU
    exist_ok=True,
)
print("Space created successfully")
EOF

# -- Step 4: Upload Space files ----------------------------------------------
python3 - << 'EOF'
from huggingface_hub import HfApi
import os

api = HfApi()
space_id = f"{api.whoami()['name']}/knowledge-inference"
base_dir = os.getcwd()

files = ["app.py", "inference.py", "requirements.txt", "README.md"]
for f in files:
    path = os.path.join(base_dir, f)
    api.upload_file(
        path_or_fileobj=path,
        path_in_repo=f,
        repo_id=space_id,
        repo_type="space",
    )
    print(f"Uploaded: {f}")

print(f"\nSpace URL: https://huggingface.co/spaces/{space_id}")
print(f"API URL:   https://{space_id.replace('/', '-')}.hf.space")
EOF

# -- Step 5: Enable ZeroGPU --------------------------------------------------
# Go to: https://huggingface.co/spaces/YOUR-USERNAME/knowledge-inference/settings
# Under "Space Hardware" -> select "ZeroGPU (NVIDIA H200)"
# This cannot be done via API - must be done in the HF web UI
echo "-> Manually enable ZeroGPU in Space settings:"
echo "  https://huggingface.co/spaces/$(huggingface-cli whoami)/knowledge-inference/settings"

# -- Step 6: Get your Space API URL ------------------------------------------
# After deployment (~3-5 minutes for build), your endpoints are:
# Text:   POST https://your-username-knowledge-inference.hf.space/api/generate
# Vision: POST https://your-username-knowledge-inference.hf.space/api/generate_vision
# Health: GET  https://your-username-knowledge-inference.hf.space/api/health

# -- Step 7: Set Render env vars ---------------------------------------------
# In Render dashboard -> your service -> Environment:
# INFERENCE_BACKEND = hf_space
# HF_SPACE_URL      = your-username/knowledge-inference
# Then trigger a manual redeploy on Render.

echo "Deployment complete. Set HF_SPACE_URL in Render and redeploy."