miike-ai/vscode-python312
0
1FROM ubuntu:22.042 3# Prevent interactive prompts4ENV DEBIAN_FRONTEND=noninteractive5ENV PYTHONUNBUFFERED=16ENV HF_HUB_ENABLE_HF_TRANSFER=17ENV CUDA_HOME=/usr/local/cuda8ENV PATH=/usr/local/cuda/bin:${PATH}9ENV LD_LIBRARY_PATH=/usr/local/cuda/lib64:${LD_LIBRARY_PATH}10 11# Install base system dependencies12RUN apt-get update && apt-get install -y \13 wget \14 curl \15 git \16 vim \17 tmux \18 htop \19 build-essential \20 software-properties-common \21 ca-certificates \22 gnupg \23 lsb-release \24 sudo \25 openssh-server \26 nginx \27 supervisor \28 python3.11 \29 python3.11-dev \30 python3-pip \31 && rm -rf /var/lib/apt/lists/*32 33# Add NVIDIA package repositories34RUN wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/x86_64/cuda-keyring_1.1-1_all.deb && \35 dpkg -i cuda-keyring_1.1-1_all.deb && \36 apt-get update37 38# Install CUDA 12.839RUN apt-get install -y cuda-toolkit-12-8 && \40 rm -rf /var/lib/apt/lists/*41 42# Install cuDNN43RUN apt-get update && apt-get install -y \44 libcudnn9-cuda-12 \45 libcudnn9-dev-cuda-12 \46 && rm -rf /var/lib/apt/lists/*47 48# Set Python 3.11 as default49RUN update-alternatives --install /usr/bin/python python /usr/bin/python3.11 1 && \50 update-alternatives --install /usr/bin/pip pip /usr/bin/pip3 151 52# Upgrade pip53RUN python -m pip install --upgrade pip setuptools wheel54 55# Install PyTorch with CUDA 12.8 support56RUN pip install torch==2.5.1+cu128 torchvision torchaudio --index-url https://download.pytorch.org/whl/cu12857 58# Create non-root user for HF Spaces compatibility59RUN useradd -m -u 1000 user && \60 echo "user ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers61 62# Install code-server (VSCode in browser)63RUN curl -fsSL https://code-server.dev/install.sh | sh64 65# Install Ollama66RUN curl -fsSL https://ollama.com/install.sh | sh67 68# Install hf_transfer first69RUN pip install hf_transfer70 71# Install core ML packages72RUN pip install \73 accelerate \74 transformers \75 datasets \76 peft \77 bitsandbytes \78 safetensors \79 sentencepiece \80 protobuf \81 scipy \82 einops \83 wandb \84 tensorboard \85 gradio \86 streamlit87 88# Install vLLM89RUN pip install vllm90 91# Install Flash Attention 292RUN pip install ninja packaging && \93 pip install flash-attn --no-build-isolation94 95# Install Triton for 5090 support96RUN pip install triton97 98# Clone and install Unsloth with patches99RUN git clone https://github.com/unslothai/unsloth.git /tmp/unsloth && \100 cd /tmp/unsloth && \101 pip install -e . && \102 cd / && \103 rm -rf /tmp/unsloth/.git104 105# Clone and install Axolotl106RUN git clone https://github.com/axolotl-ai-cloud/axolotl /tmp/axolotl && \107 cd /tmp/axolotl && \108 pip install -e . && \109 cd / && \110 rm -rf /tmp/axolotl/.git111 112# Install Node.js for Open-WebUI113RUN curl -fsSL https://deb.nodesource.com/setup_20.x | bash - && \114 apt-get install -y nodejs && \115 rm -rf /var/lib/apt/lists/*116 117# Clone and setup Open-WebUI118RUN git clone https://github.com/open-webui/open-webui.git /opt/open-webui && \119 cd /opt/open-webui && \120 npm install && \121 npm run build122 123# Create directories with proper permissions124RUN mkdir -p /home/user/app /home/user/.cache /home/user/.config && \125 chown -R user:user /home/user126 127# Configure code-server for user128RUN mkdir -p /home/user/.config/code-server && \129 echo "bind-addr: 0.0.0.0:8080\nauth: none\ncert: false" > /home/user/.config/code-server/config.yaml && \130 chown -R user:user /home/user/.config131 132# Setup SSH133RUN mkdir /var/run/sshd && \134 echo 'user:spaces' | chpasswd && \135 sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin no/' /etc/ssh/sshd_config136 137# Create supervisor config138RUN mkdir -p /etc/supervisor/conf.d139RUN cat > /etc/supervisor/conf.d/services.conf << 'EOF'140[supervisord]141nodaemon=true142user=root143 144[program:code-server]145command=sudo -u user code-server --bind-addr 0.0.0.0:8080 --auth none146autostart=true147autorestart=true148stderr_logfile=/var/log/code-server.err.log149stdout_logfile=/var/log/code-server.out.log150 151[program:ollama]152command=ollama serve153autostart=true154autorestart=true155environment=OLLAMA_HOST="0.0.0.0",HOME="/home/user"156stderr_logfile=/var/log/ollama.err.log157stdout_logfile=/var/log/ollama.out.log158 159[program:open-webui]160command=cd /opt/open-webui && npm start161autostart=true162autorestart=true163environment=PORT="3000",OLLAMA_BASE_URL="http://localhost:11434"164stderr_logfile=/var/log/open-webui.err.log165stdout_logfile=/var/log/open-webui.out.log166user=user167EOF168 169# Create Gradio app for HF Spaces170RUN cat > /home/user/app/app.py << 'EOF'171import gradio as gr172import subprocess173import os174 175def get_services_status():176 services = {177 "VSCode": "http://localhost:8080",178 "Ollama API": "http://localhost:11434", 179 "Open-WebUI": "http://localhost:3000",180 "vLLM": "http://localhost:8000"181 }182 183 status = "# ๐ ML Stack Services Status\n\n"184 for service, url in services.items():185 status += f"- **{service}**: {url}\n"186 187 # Get GPU info188 try:189 gpu_info = subprocess.check_output(['nvidia-smi', '--query-gpu=name,memory.total', '--format=csv,noheader'], text=True)190 status += f"\n## ๐ฎ GPU Status\n```\n{gpu_info}```"191 except:192 status += "\n## โ ๏ธ No GPUs detected"193 194 return status195 196def launch_vllm(model_name):197 try:198 cmd = f"python -m vllm.entrypoints.openai.api_server --model {model_name} --host 0.0.0.0 --port 8000"199 subprocess.Popen(cmd, shell=True)200 return f"โ
Launching vLLM with model: {model_name}"201 except Exception as e:202 return f"โ Error: {str(e)}"203 204def pull_ollama_model(model_name):205 try:206 result = subprocess.run(['ollama', 'pull', model_name], capture_output=True, text=True)207 return f"โ
{result.stdout}\n{result.stderr}"208 except Exception as e:209 return f"โ Error: {str(e)}"210 211# Create Gradio interface212with gr.Blocks(title="ML Stack Control Panel") as demo:213 gr.Markdown("# ๐ฎ RunPod ML Stack Control Panel")214 215 with gr.Tab("Status"):216 status_btn = gr.Button("๐ Refresh Status")217 status_output = gr.Markdown()218 status_btn.click(get_services_status, outputs=status_output)219 220 with gr.Tab("vLLM"):221 model_input = gr.Textbox(label="Model Name", value="meta-llama/Llama-2-7b-hf")222 vllm_btn = gr.Button("๐ Launch vLLM")223 vllm_output = gr.Textbox(label="Output")224 vllm_btn.click(launch_vllm, inputs=model_input, outputs=vllm_output)225 226 with gr.Tab("Ollama"):227 ollama_model = gr.Textbox(label="Model Name", value="llama3.2")228 ollama_btn = gr.Button("๐ฅ Pull Model")229 ollama_output = gr.Textbox(label="Output")230 ollama_btn.click(pull_ollama_model, inputs=ollama_model, outputs=ollama_output)231 232 # Load initial status233 demo.load(get_services_status, outputs=status_output)234 235if __name__ == "__main__":236 # Start supervisor in background237 subprocess.Popen(["/usr/bin/supervisord", "-c", "/etc/supervisor/supervisord.conf"])238 239 # Launch Gradio240 demo.launch(server_name="0.0.0.0", server_port=7860, share=False)241EOF242 243# Create startup script244RUN cat > /home/user/app/start.sh << 'EOF'245#!/bin/bash246cd /home/user/app247python app.py248EOF249RUN chmod +x /home/user/app/start.sh250 251# Fix permissions252RUN chown -R user:user /home/user /opt/open-webui253 254# Expose ports255EXPOSE 22 # SSH256EXPOSE 7860 # Gradio (HF Spaces default)257EXPOSE 8080 # Code-server258EXPOSE 11434 # Ollama259EXPOSE 8000 # vLLM260EXPOSE 3000 # Open-WebUI261 262# Switch to user263USER user264WORKDIR /home/user/app265 266# Set the entrypoint for HF Spaces267CMD ["python", "app.py"]