mknolan commited on
Commit
f666747
·
verified ·
1 Parent(s): 5b040dc

Upload InternVL2 implementation

Browse files
Files changed (2) hide show
  1. Dockerfile +10 -11
  2. app_internvl2.py +43 -19
Dockerfile CHANGED
@@ -3,14 +3,15 @@ FROM nvidia/cuda:11.8.0-cudnn8-devel-ubuntu22.04
3
  # Set environment variables
4
  ENV DEBIAN_FRONTEND=noninteractive
5
  ENV PYTHONUNBUFFERED=1
6
- ENV HF_HOME=/root/.cache/huggingface
7
- ENV TRANSFORMERS_CACHE=/root/.cache/huggingface/transformers
8
  ENV MPLCONFIGDIR=/tmp/matplotlib
9
 
10
  # Create necessary directories with proper permissions
11
- RUN mkdir -p /root/.cache/huggingface/transformers && \
12
  mkdir -p /tmp/matplotlib && \
13
- chmod -R 777 /root/.cache && \
 
14
  chmod -R 777 /tmp/matplotlib
15
 
16
  # Install system dependencies
@@ -27,11 +28,6 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
27
  # Create a working directory
28
  WORKDIR /app
29
 
30
- # Create and set permissions for Gradio cache directory
31
- RUN mkdir -p /app/gradio_cached_examples && \
32
- chmod 777 /app/gradio_cached_examples && \
33
- chmod 777 /app
34
-
35
  # Copy requirements file
36
  COPY requirements.txt .
37
 
@@ -58,8 +54,11 @@ RUN pip3 install --no-cache-dir --upgrade pip && \
58
  # Copy the application files
59
  COPY . .
60
 
61
- # Set permissions for the entire app directory
62
- RUN chmod -R 777 /app
 
 
 
63
 
64
  # Make port 7860 available for the app
65
  EXPOSE 7860
 
3
  # Set environment variables
4
  ENV DEBIAN_FRONTEND=noninteractive
5
  ENV PYTHONUNBUFFERED=1
6
+ ENV HF_HOME=/app/.cache/huggingface
7
+ ENV TRANSFORMERS_CACHE=/app/.cache/huggingface/transformers
8
  ENV MPLCONFIGDIR=/tmp/matplotlib
9
 
10
  # Create necessary directories with proper permissions
11
+ RUN mkdir -p /app/.cache/huggingface/transformers && \
12
  mkdir -p /tmp/matplotlib && \
13
+ mkdir -p /app/gradio_cached_examples && \
14
+ chmod -R 777 /app && \
15
  chmod -R 777 /tmp/matplotlib
16
 
17
  # Install system dependencies
 
28
  # Create a working directory
29
  WORKDIR /app
30
 
 
 
 
 
 
31
  # Copy requirements file
32
  COPY requirements.txt .
33
 
 
54
  # Copy the application files
55
  COPY . .
56
 
57
+ # Make sure the runtime directories exist and have proper permissions
58
+ RUN mkdir -p gradio_cached_examples && \
59
+ chmod -R 777 gradio_cached_examples && \
60
+ mkdir -p .cache/huggingface/transformers && \
61
+ chmod -R 777 .cache
62
 
63
  # Make port 7860 available for the app
64
  EXPOSE 7860
app_internvl2.py CHANGED
@@ -5,15 +5,36 @@ import time
5
  import numpy as np
6
  import torch
7
  import warnings
 
8
 
9
  # Set environment variables
10
  os.environ["PYTORCH_CUDA_ALLOC_CONF"] = "max_split_size_mb:128"
11
 
12
- # Ensure cache directories exist with proper permissions
13
- cache_dir = os.path.join(os.getcwd(), "gradio_cached_examples")
14
- os.makedirs(cache_dir, exist_ok=True)
15
- if os.path.exists(cache_dir):
16
- os.chmod(cache_dir, 0o777)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
 
18
  # Suppress specific warnings that might be caused by package version mismatches
19
  warnings.filterwarnings("ignore", message=".*The 'nopython' keyword.*")
@@ -175,18 +196,21 @@ def create_interface():
175
  """)
176
 
177
  # Examples
178
- gr.Examples(
179
- examples=[
180
- ["data_temp/page_2.png", "general"],
181
- ["data_temp/page_2.png", "text"],
182
- ["data_temp/page_2.png", "chart"]
183
- ],
184
- inputs=[input_image, analysis_type],
185
- outputs=output_text,
186
- fn=process_image,
187
- cache_examples=True,
188
- examples_dir=cache_dir
189
- )
 
 
 
190
 
191
  return demo
192
 
@@ -195,5 +219,5 @@ if __name__ == "__main__":
195
  # Create the Gradio interface
196
  demo = create_interface()
197
 
198
- # Launch the interface with explicit cache directory
199
- demo.launch(share=False, cache_dir=cache_dir)
 
5
  import numpy as np
6
  import torch
7
  import warnings
8
+ import stat
9
 
10
  # Set environment variables
11
  os.environ["PYTORCH_CUDA_ALLOC_CONF"] = "max_split_size_mb:128"
12
 
13
+ # Ensure all cache directories exist with proper permissions
14
+ def setup_cache_directories():
15
+ # Gradio cache directory
16
+ cache_dir = os.path.join(os.getcwd(), "gradio_cached_examples")
17
+ os.makedirs(cache_dir, exist_ok=True)
18
+
19
+ # HuggingFace cache directories
20
+ hf_cache = os.path.join(os.getcwd(), ".cache", "huggingface")
21
+ transformers_cache = os.path.join(hf_cache, "transformers")
22
+ os.makedirs(hf_cache, exist_ok=True)
23
+ os.makedirs(transformers_cache, exist_ok=True)
24
+
25
+ # Set permissions
26
+ try:
27
+ for directory in [cache_dir, hf_cache, transformers_cache]:
28
+ if os.path.exists(directory):
29
+ os.chmod(directory, stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO) # 0o777
30
+ print(f"Set permissions for {directory}")
31
+ except Exception as e:
32
+ print(f"Warning: Could not set permissions: {str(e)}")
33
+
34
+ return cache_dir
35
+
36
+ # Set up cache directories
37
+ cache_dir = setup_cache_directories()
38
 
39
  # Suppress specific warnings that might be caused by package version mismatches
40
  warnings.filterwarnings("ignore", message=".*The 'nopython' keyword.*")
 
196
  """)
197
 
198
  # Examples
199
+ try:
200
+ gr.Examples(
201
+ examples=[
202
+ ["data_temp/page_2.png", "general"],
203
+ ["data_temp/page_2.png", "text"],
204
+ ["data_temp/page_2.png", "chart"]
205
+ ],
206
+ inputs=[input_image, analysis_type],
207
+ outputs=output_text,
208
+ fn=process_image,
209
+ cache_examples=True,
210
+ examples_dir=cache_dir
211
+ )
212
+ except Exception as e:
213
+ print(f"Warning: Could not load examples: {str(e)}")
214
 
215
  return demo
216
 
 
219
  # Create the Gradio interface
220
  demo = create_interface()
221
 
222
+ # Launch the interface with explicit cache directory and without authentication
223
+ demo.launch(share=False, cache_dir=cache_dir, server_name="0.0.0.0")