Spaces:
Sleeping
Sleeping
udbhav
commited on
Commit
Β·
284f009
1
Parent(s):
2b04fb9
first commit
Browse files- .gitignore +33 -0
- Dockerfile +154 -0
- app.py +103 -0
- requirements.txt +40 -0
.gitignore
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Cache directory (downloaded private repo)
|
| 2 |
+
cache/
|
| 3 |
+
|
| 4 |
+
# Python cache
|
| 5 |
+
__pycache__/
|
| 6 |
+
*.pyc
|
| 7 |
+
*.pyo
|
| 8 |
+
*.pyd
|
| 9 |
+
.Python
|
| 10 |
+
|
| 11 |
+
# Environment files
|
| 12 |
+
.env
|
| 13 |
+
.venv
|
| 14 |
+
env/
|
| 15 |
+
venv/
|
| 16 |
+
|
| 17 |
+
# IDE files
|
| 18 |
+
.vscode/
|
| 19 |
+
.idea/
|
| 20 |
+
*.swp
|
| 21 |
+
*.swo
|
| 22 |
+
|
| 23 |
+
# OS files
|
| 24 |
+
.DS_Store
|
| 25 |
+
Thumbs.db
|
| 26 |
+
|
| 27 |
+
# Logs
|
| 28 |
+
*.log
|
| 29 |
+
logs/
|
| 30 |
+
|
| 31 |
+
# Temporary files
|
| 32 |
+
*.tmp
|
| 33 |
+
*.temp
|
Dockerfile
ADDED
|
@@ -0,0 +1,154 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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}/bin:/usr/local/bin:${PATH}
|
| 11 |
+
# ENV LD_LIBRARY_PATH=${CUDA_HOME}/lib64:${LD_LIBRARY_PATH}
|
| 12 |
+
|
| 13 |
+
# # System deps + Deadsnakes PPA for Python 3.12
|
| 14 |
+
# RUN apt-get update && apt-get install -y --no-install-recommends \
|
| 15 |
+
# software-properties-common \
|
| 16 |
+
# ca-certificates \
|
| 17 |
+
# curl wget git build-essential \
|
| 18 |
+
# libgl1-mesa-glx libglib2.0-0 libsm6 libxext6 libxrender1 \
|
| 19 |
+
# libgomp1 libgcc-s1 \
|
| 20 |
+
# && add-apt-repository ppa:deadsnakes/ppa -y \
|
| 21 |
+
# && apt-get update && apt-get install -y --no-install-recommends \
|
| 22 |
+
# python3.12 python3.12-dev python3.12-venv \
|
| 23 |
+
# && rm -rf /var/lib/apt/lists/*
|
| 24 |
+
|
| 25 |
+
# # Install pip for Python 3.12
|
| 26 |
+
# RUN curl -sS https://bootstrap.pypa.io/get-pip.py -o /tmp/get-pip.py \
|
| 27 |
+
# && python3.12 /tmp/get-pip.py \
|
| 28 |
+
# && rm /tmp/get-pip.py
|
| 29 |
+
|
| 30 |
+
# # Make 'python' and 'pip' point to 3.12
|
| 31 |
+
# RUN ln -sf /usr/bin/python3.12 /usr/bin/python && \
|
| 32 |
+
# ln -sf /usr/local/bin/pip3.12 /usr/local/bin/pip
|
| 33 |
+
|
| 34 |
+
# # ---------------- Writable app data & HF cache ----------------
|
| 35 |
+
# ENV APP_DATA_DIR=/data
|
| 36 |
+
# ENV HF_HOME=/data/hf_home
|
| 37 |
+
# ENV HUGGINGFACE_HUB_CACHE=/data/hf_home
|
| 38 |
+
# ENV TRANSFORMERS_CACHE=/data/hf_home
|
| 39 |
+
# ENV MPLCONFIGDIR=/data/matplotlib
|
| 40 |
+
|
| 41 |
+
# RUN mkdir -p /data/geometry /data/solution /data/weights /data/hf_home /data/matplotlib \
|
| 42 |
+
# && chmod -R 777 /data
|
| 43 |
+
|
| 44 |
+
# # ---------------- Install frpc for Gradio share=True ----------------
|
| 45 |
+
# RUN mkdir -p /data/hf_home/gradio/frpc && \
|
| 46 |
+
# wget https://cdn-media.huggingface.co/frpc-gradio-0.3/frpc_linux_amd64 -O /data/hf_home/gradio/frpc/frpc_linux_amd64_v0.3 && \
|
| 47 |
+
# chmod +x /data/hf_home/gradio/frpc/frpc_linux_amd64_v0.3
|
| 48 |
+
|
| 49 |
+
# # ---------------- Application setup ----------------
|
| 50 |
+
# WORKDIR /app
|
| 51 |
+
|
| 52 |
+
# # Copy requirements first (better caching)
|
| 53 |
+
# COPY requirements.txt .
|
| 54 |
+
|
| 55 |
+
# # Install Python deps
|
| 56 |
+
# RUN pip install --no-cache-dir --upgrade pip setuptools wheel \
|
| 57 |
+
# && pip install --no-cache-dir -r requirements.txt
|
| 58 |
+
|
| 59 |
+
# # Copy the rest of the source
|
| 60 |
+
# COPY . .
|
| 61 |
+
|
| 62 |
+
# # Create cache directory for downloaded repos
|
| 63 |
+
# RUN mkdir -p /app/cache && chmod 777 /app/cache
|
| 64 |
+
|
| 65 |
+
# # Permissions
|
| 66 |
+
# RUN chmod +x app.py
|
| 67 |
+
# RUN chown -R 1000:1000 /app
|
| 68 |
+
|
| 69 |
+
# # Expose Gradio port
|
| 70 |
+
# EXPOSE 7860
|
| 71 |
+
|
| 72 |
+
# # Run app
|
| 73 |
+
# CMD ["python", "app.py"]
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
# Use NVIDIA CUDA base image (Ubuntu 22.04 jammy)
|
| 79 |
+
FROM nvidia/cuda:12.3.2-devel-ubuntu22.04
|
| 80 |
+
|
| 81 |
+
# Non-interactive apt
|
| 82 |
+
ENV DEBIAN_FRONTEND=noninteractive
|
| 83 |
+
ENV PYTHONUNBUFFERED=1
|
| 84 |
+
ENV CUDA_HOME=/usr/local/cuda
|
| 85 |
+
ENV PATH=${CUDA_HOME}/bin:/usr/local/bin:${PATH}
|
| 86 |
+
ENV LD_LIBRARY_PATH=${CUDA_HOME}/lib64:${LD_LIBRARY_PATH}
|
| 87 |
+
|
| 88 |
+
# Proxy (auto-configurable: overridden at runtime if needed)
|
| 89 |
+
ENV http_proxy=""
|
| 90 |
+
ENV https_proxy=""
|
| 91 |
+
ENV HTTP_PROXY=""
|
| 92 |
+
ENV HTTPS_PROXY=""
|
| 93 |
+
|
| 94 |
+
# System deps + Deadsnakes PPA for Python 3.12
|
| 95 |
+
RUN apt-get update && apt-get install -y --no-install-recommends \
|
| 96 |
+
software-properties-common \
|
| 97 |
+
ca-certificates \
|
| 98 |
+
curl wget git build-essential \
|
| 99 |
+
libgl1-mesa-glx libglib2.0-0 libsm6 libxext6 libxrender1 \
|
| 100 |
+
libgomp1 libgcc-s1 \
|
| 101 |
+
&& add-apt-repository ppa:deadsnakes/ppa -y \
|
| 102 |
+
&& apt-get update && apt-get install -y --no-install-recommends \
|
| 103 |
+
python3.12 python3.12-dev python3.12-venv \
|
| 104 |
+
&& rm -rf /var/lib/apt/lists/*
|
| 105 |
+
|
| 106 |
+
# Install pip for Python 3.12
|
| 107 |
+
RUN curl -sS https://bootstrap.pypa.io/get-pip.py -o /tmp/get-pip.py \
|
| 108 |
+
&& python3.12 /tmp/get-pip.py \
|
| 109 |
+
&& rm /tmp/get-pip.py
|
| 110 |
+
|
| 111 |
+
# Make 'python' and 'pip' point to 3.12
|
| 112 |
+
RUN ln -sf /usr/bin/python3.12 /usr/bin/python && \
|
| 113 |
+
ln -sf /usr/local/bin/pip3.12 /usr/local/bin/pip
|
| 114 |
+
|
| 115 |
+
# ---------------- Writable app data & HF cache ----------------
|
| 116 |
+
ENV APP_DATA_DIR=/data
|
| 117 |
+
ENV HF_HOME=/data/hf_home
|
| 118 |
+
ENV HUGGINGFACE_HUB_CACHE=/data/hf_home
|
| 119 |
+
ENV TRANSFORMERS_CACHE=/data/hf_home
|
| 120 |
+
ENV MPLCONFIGDIR=/data/matplotlib
|
| 121 |
+
|
| 122 |
+
RUN mkdir -p /data/geometry /data/solution /data/weights /data/hf_home /data/matplotlib \
|
| 123 |
+
&& chmod -R 777 /data
|
| 124 |
+
|
| 125 |
+
# ---------------- Install frpc for Gradio share=True ----------------
|
| 126 |
+
RUN mkdir -p /data/hf_home/gradio/frpc && \
|
| 127 |
+
wget https://cdn-media.huggingface.co/frpc-gradio-0.3/frpc_linux_amd64 -O /data/hf_home/gradio/frpc/frpc_linux_amd64_v0.3 && \
|
| 128 |
+
chmod +x /data/hf_home/gradio/frpc/frpc_linux_amd64_v0.3
|
| 129 |
+
|
| 130 |
+
# ---------------- Application setup ----------------
|
| 131 |
+
WORKDIR /app
|
| 132 |
+
|
| 133 |
+
# Copy requirements first (better caching)
|
| 134 |
+
COPY requirements.txt .
|
| 135 |
+
|
| 136 |
+
# Install Python deps
|
| 137 |
+
RUN pip install --no-cache-dir --upgrade pip setuptools wheel \
|
| 138 |
+
&& pip install --no-cache-dir -r requirements.txt
|
| 139 |
+
|
| 140 |
+
# Copy the rest of the source
|
| 141 |
+
COPY . .
|
| 142 |
+
|
| 143 |
+
# Create cache directory for downloaded repos
|
| 144 |
+
RUN mkdir -p /app/cache && chmod 777 /app/cache
|
| 145 |
+
|
| 146 |
+
# Permissions
|
| 147 |
+
RUN chmod +x app.py
|
| 148 |
+
RUN chown -R 1000:1000 /app
|
| 149 |
+
|
| 150 |
+
# Expose Gradio port
|
| 151 |
+
EXPOSE 7860
|
| 152 |
+
|
| 153 |
+
# Run app
|
| 154 |
+
CMD ["python", "app.py"]
|
app.py
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
|
| 3 |
+
import os
|
| 4 |
+
import sys
|
| 5 |
+
import tempfile
|
| 6 |
+
from pathlib import Path
|
| 7 |
+
import traceback
|
| 8 |
+
|
| 9 |
+
# Proxy support (office networks often require this)
|
| 10 |
+
proxy = os.environ.get("HTTP_PROXY") or os.environ.get("http_proxy")
|
| 11 |
+
if proxy:
|
| 12 |
+
print(f"π Using proxy: {proxy}")
|
| 13 |
+
else:
|
| 14 |
+
print("π No proxy detected, connecting directly")
|
| 15 |
+
|
| 16 |
+
# Writable base dir
|
| 17 |
+
DATA_DIR = os.environ.get("APP_DATA_DIR", os.path.join(tempfile.gettempdir(), "appdata"))
|
| 18 |
+
os.makedirs(DATA_DIR, exist_ok=True)
|
| 19 |
+
os.environ.setdefault("MPLCONFIGDIR", DATA_DIR)
|
| 20 |
+
|
| 21 |
+
def setup_environment():
|
| 22 |
+
cache_dir = Path("cache")
|
| 23 |
+
cache_dir.mkdir(exist_ok=True)
|
| 24 |
+
if str(cache_dir.absolute()) not in sys.path:
|
| 25 |
+
sys.path.insert(0, str(cache_dir.absolute()))
|
| 26 |
+
return cache_dir
|
| 27 |
+
|
| 28 |
+
def download_private_repo(cache_dir, repo_id, hf_token):
|
| 29 |
+
from huggingface_hub import snapshot_download
|
| 30 |
+
import shutil
|
| 31 |
+
import os
|
| 32 |
+
print(f"π Downloading repo {repo_id}")
|
| 33 |
+
repo_path = snapshot_download(
|
| 34 |
+
repo_id=repo_id,
|
| 35 |
+
token=hf_token,
|
| 36 |
+
repo_type="space",
|
| 37 |
+
local_dir=cache_dir,
|
| 38 |
+
local_dir_use_symlinks=False,
|
| 39 |
+
)
|
| 40 |
+
|
| 41 |
+
# Copy everything from the repository to current working directory
|
| 42 |
+
print(f"π Copying all files and directories from {repo_path} to current directory")
|
| 43 |
+
|
| 44 |
+
# Get all items in the repository
|
| 45 |
+
for item in os.listdir(repo_path):
|
| 46 |
+
src_path = os.path.join(repo_path, item)
|
| 47 |
+
dst_path = item
|
| 48 |
+
|
| 49 |
+
# Skip hidden files and directories (like .git, .gitignore, etc.)
|
| 50 |
+
if item.startswith('.'):
|
| 51 |
+
print(f"βοΈ Skipping hidden item: {item}")
|
| 52 |
+
continue
|
| 53 |
+
|
| 54 |
+
if os.path.isdir(src_path):
|
| 55 |
+
print(f"π Copying directory: {item}")
|
| 56 |
+
if os.path.exists(dst_path):
|
| 57 |
+
shutil.rmtree(dst_path)
|
| 58 |
+
shutil.copytree(src_path, dst_path)
|
| 59 |
+
print(f"β
Directory {item} copied successfully")
|
| 60 |
+
elif os.path.isfile(src_path):
|
| 61 |
+
print(f"π Copying file: {item}")
|
| 62 |
+
shutil.copy2(src_path, dst_path)
|
| 63 |
+
print(f"β
File {item} copied successfully")
|
| 64 |
+
|
| 65 |
+
print(f"π All repository contents copied to current working directory")
|
| 66 |
+
|
| 67 |
+
return repo_path
|
| 68 |
+
|
| 69 |
+
def load_private_app(repo_path):
|
| 70 |
+
sys.path.insert(0, str(repo_path))
|
| 71 |
+
import app as private_app
|
| 72 |
+
if hasattr(private_app, "demo"):
|
| 73 |
+
return private_app.demo
|
| 74 |
+
if hasattr(private_app, "app"):
|
| 75 |
+
return private_app.app
|
| 76 |
+
raise RuntimeError("No demo/app found in private repo")
|
| 77 |
+
|
| 78 |
+
def main():
|
| 79 |
+
hf_token = os.environ.get("HF_TOKEN")
|
| 80 |
+
repo_id = os.environ.get("REPO_ID")
|
| 81 |
+
|
| 82 |
+
if not hf_token or not repo_id:
|
| 83 |
+
raise ValueError("HF_TOKEN and REPO_ID must be set")
|
| 84 |
+
|
| 85 |
+
print(f"π Starting app with repo_id: {repo_id}")
|
| 86 |
+
print(f"π Current working directory: {os.getcwd()}")
|
| 87 |
+
|
| 88 |
+
cache_dir = setup_environment()
|
| 89 |
+
repo_path = download_private_repo(cache_dir, repo_id, hf_token)
|
| 90 |
+
demo = load_private_app(repo_path)
|
| 91 |
+
|
| 92 |
+
|
| 93 |
+
demo.launch(
|
| 94 |
+
server_name="0.0.0.0",
|
| 95 |
+
server_port=7860,
|
| 96 |
+
share=False,
|
| 97 |
+
show_error=True,
|
| 98 |
+
allowed_paths=[str(repo_path), DATA_DIR]
|
| 99 |
+
)
|
| 100 |
+
|
| 101 |
+
|
| 102 |
+
if __name__ == "__main__":
|
| 103 |
+
main()
|
requirements.txt
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
huggingface_hub>=0.16.0
|
| 3 |
+
--index-url https://download.pytorch.org/whl/cu121
|
| 4 |
+
--extra-index-url https://pypi.org/simple
|
| 5 |
+
|
| 6 |
+
torch==2.5.0
|
| 7 |
+
torchvision
|
| 8 |
+
torchaudio
|
| 9 |
+
|
| 10 |
+
torch_geometric
|
| 11 |
+
|
| 12 |
+
-f https://data.pyg.org/whl/torch-2.5.0+cu121.html
|
| 13 |
+
pyg_lib
|
| 14 |
+
torch_scatter
|
| 15 |
+
torch_sparse
|
| 16 |
+
torch_cluster
|
| 17 |
+
torch_spline_conv
|
| 18 |
+
|
| 19 |
+
matplotlib
|
| 20 |
+
vtk
|
| 21 |
+
timm
|
| 22 |
+
einops
|
| 23 |
+
seaborn
|
| 24 |
+
pyvista
|
| 25 |
+
imageio
|
| 26 |
+
pandas
|
| 27 |
+
meshio
|
| 28 |
+
accelerate
|
| 29 |
+
omegaconf
|
| 30 |
+
tensorboard
|
| 31 |
+
lion-pytorch
|
| 32 |
+
scikit-learn
|
| 33 |
+
|
| 34 |
+
gradio==5.44.1
|
| 35 |
+
pathlib2>=2.3.0
|
| 36 |
+
typing-extensions>=4.0.0
|
| 37 |
+
transformers>=4.20.0
|
| 38 |
+
trimesh
|
| 39 |
+
gradio_client==1.12.1
|
| 40 |
+
|