File size: 1,813 Bytes
873030d
4670dfa
 
 
137b7f1
 
1792bb4
137b7f1
4670dfa
137b7f1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e2e9c74
 
 
137b7f1
 
 
 
 
 
 
 
 
 
 
 
 
 
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
FROM python:3.9-slim

WORKDIR /app

# Install git
RUN apt-get update && apt-get install -y git && rm -rf /var/lib/apt/lists/*

# Copy requirements and install
COPY requirements.txt requirements.txt
RUN echo "DEBUG: Installing packages from requirements.txt" && \
    pip install --no-cache-dir -r requirements.txt && \
    echo "DEBUG: Finished installing packages."

# Clone the nanoVLM repository which contains generate.py and the models directory
# This also ensures the 'models' module is available for VisionLanguageModel import
RUN echo "DEBUG: Cloning huggingface/nanoVLM repository..." && \
    git clone https://github.com/huggingface/nanoVLM.git /app/nanoVLM && \
    echo "DEBUG: nanoVLM repository cloned to /app/nanoVLM."

# Add a test image to the Space.
# You need to create a simple 'test_image.jpg' and add it to the root of your Space repo.
COPY ./test_image.jpg /app/test_image.jpg
RUN if [ ! -f /app/test_image.jpg ]; then echo "ERROR: test_image.jpg not found!"; exit 1; fi

# Set Python path to include the nanoVLM models directory, so `from models...` works
ENV PYTHONPATH="/app/nanoVLM:${PYTHONPATH}"

# Define a writable cache directory for Hugging Face downloads
ENV HF_HOME=/app/.cache/huggingface

# Create cache directory with write permissions
RUN mkdir -p $HF_HOME && chmod -R 777 $HF_HOME

# The generate.py script is at /app/nanoVLM/generate.py
# It takes arguments like --model_path, --image_path, --prompt, --device
# We will run it directly. Its output will go to the Space's container logs.
CMD ["python", "-u", "/app/nanoVLM/generate.py", \
     "--model_path", "lusxvr/nanoVLM-222M", \
     "--image_path", "/app/test_image.jpg", \
     "--prompt", "describe this image in detail", \
     "--device", "cpu", \
     "--num_generations", "1", \
     "--max_new_tokens", "50"]