youssef commited on
Commit
426a08c
Β·
1 Parent(s): f5765c8

change sdk

Browse files
Files changed (4) hide show
  1. Dockerfile +53 -29
  2. README.md +1 -2
  3. app.py +29 -0
  4. src/video_processor/processor.py +9 -1
Dockerfile CHANGED
@@ -1,34 +1,58 @@
1
  FROM nvidia/cuda:12.3.2-cudnn9-devel-ubuntu22.04
2
-
3
- # Set environment variables
4
  ENV DEBIAN_FRONTEND=noninteractive
5
- ENV PYTHONUNBUFFERED=1
6
- ENV FLASH_ATTENTION_SKIP_CUDA_BUILD=TRUE
7
-
8
- # Install system dependencies
9
- RUN apt-get update && apt-get install -y \
10
- python3.10 \
11
- python3-pip \
12
- python3.10-dev \
13
- build-essential \
14
- ninja-build \
15
  git \
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
  && rm -rf /var/lib/apt/lists/*
17
 
18
- # Create and set working directory
19
- WORKDIR /app
20
-
21
- # Copy requirements first to leverage Docker cache
22
- COPY requirements.txt .
23
-
24
- # Install Python dependencies
25
- RUN pip3 install --no-cache-dir -r requirements.txt
26
-
27
- # Install flash-attention
28
- RUN pip3 install --no-cache-dir flash-attn --no-build-isolation
29
-
30
- # Copy the rest of the application
31
- COPY . .
32
-
33
- # Set the default command
34
- CMD ["python3", "-m", "src.video_processor.processor"]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  FROM nvidia/cuda:12.3.2-cudnn9-devel-ubuntu22.04
 
 
2
  ENV DEBIAN_FRONTEND=noninteractive
3
+ RUN apt-get update && \
4
+ apt-get upgrade -y && \
5
+ apt-get install -y --no-install-recommends \
 
 
 
 
 
 
 
6
  git \
7
+ git-lfs \
8
+ wget \
9
+ curl \
10
+ # python build dependencies \
11
+ build-essential \
12
+ libssl-dev \
13
+ zlib1g-dev \
14
+ libbz2-dev \
15
+ libreadline-dev \
16
+ libsqlite3-dev \
17
+ libncursesw5-dev \
18
+ xz-utils \
19
+ tk-dev \
20
+ libxml2-dev \
21
+ libxmlsec1-dev \
22
+ libffi-dev \
23
+ liblzma-dev \
24
+ # gradio dependencies \
25
+ ffmpeg \
26
+ && apt-get clean \
27
  && rm -rf /var/lib/apt/lists/*
28
 
29
+ RUN useradd -m -u 1000 user
30
+ USER user
31
+ ENV HOME=/home/user \
32
+ PATH=/home/user/.local/bin:${PATH}
33
+ WORKDIR ${HOME}/app
34
+
35
+ RUN curl https://pyenv.run | bash
36
+ ENV PATH=${HOME}/.pyenv/shims:${HOME}/.pyenv/bin:${PATH}
37
+ ARG PYTHON_VERSION=3.10.12
38
+ RUN pyenv install ${PYTHON_VERSION} && \
39
+ pyenv global ${PYTHON_VERSION} && \
40
+ pyenv rehash && \
41
+ pip install --no-cache-dir -U pip setuptools wheel && \
42
+ pip install packaging ninja
43
+
44
+ COPY --chown=1000 ./requirements.txt /tmp/requirements.txt
45
+ RUN pip install --no-cache-dir --upgrade -r /tmp/requirements.txt && \
46
+ pip install flash-attn --no-build-isolation
47
+
48
+ COPY --chown=1000 . ${HOME}/app
49
+ ENV PYTHONPATH=${HOME}/app \
50
+ PYTHONUNBUFFERED=1 \
51
+ GRADIO_ALLOW_FLAGGING=never \
52
+ GRADIO_NUM_PORTS=1 \
53
+ GRADIO_SERVER_NAME=0.0.0.0 \
54
+ GRADIO_THEME=huggingface \
55
+ SYSTEM=spaces \
56
+ FLASH_ATTENTION_SKIP_CUDA_BUILD=TRUE
57
+
58
+ CMD ["python", "app.py"]
README.md CHANGED
@@ -3,8 +3,7 @@ title: Smollvm
3
  emoji: 🌍
4
  colorFrom: pink
5
  colorTo: gray
6
- sdk: gradio
7
- sdk_version: 5.17.1
8
  app_file: src/app.py
9
  pinned: false
10
  short_description: test
 
3
  emoji: 🌍
4
  colorFrom: pink
5
  colorTo: gray
6
+ sdk: docker
 
7
  app_file: src/app.py
8
  pinned: false
9
  short_description: test
app.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from src.video_processor.processor import VideoAnalyzer
3
+ import logging
4
+
5
+ logging.basicConfig(level=logging.INFO)
6
+ logger = logging.getLogger(__name__)
7
+
8
+ def process_video(video_path):
9
+ try:
10
+ analyzer = VideoAnalyzer()
11
+ result = analyzer.process_video(video_path)
12
+ return result[0]["description"]
13
+ except Exception as e:
14
+ logger.error(f"Error processing video: {str(e)}", exc_info=True)
15
+ return f"Error processing video: {str(e)}"
16
+
17
+ # Create Gradio interface
18
+ demo = gr.Interface(
19
+ fn=process_video,
20
+ inputs=gr.Video(label="Upload your video"),
21
+ outputs=gr.Textbox(label="Video Analysis", lines=10),
22
+ title="Video Analysis with SmolVLM",
23
+ description="Upload a video to get a detailed analysis of its content, including actions, events, timestamps, and important details.",
24
+ examples=[], # You can add example videos here
25
+ cache_examples=False
26
+ )
27
+
28
+ if __name__ == "__main__":
29
+ demo.launch()
src/video_processor/processor.py CHANGED
@@ -5,7 +5,15 @@ import logging
5
 
6
  logger = logging.getLogger(__name__)
7
 
8
- DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
 
 
 
 
 
 
 
 
9
  logger.info(f"Using device: {DEVICE}")
10
 
11
  class VideoAnalyzer:
 
5
 
6
  logger = logging.getLogger(__name__)
7
 
8
+ def _grab_best_device(use_gpu=True):
9
+ if torch.cuda.device_count() > 0 and use_gpu:
10
+ device = "cuda"
11
+ else:
12
+ device = "cpu"
13
+ return device
14
+
15
+ DEVICE = _grab_best_device()
16
+
17
  logger.info(f"Using device: {DEVICE}")
18
 
19
  class VideoAnalyzer: