File size: 1,678 Bytes
f1c8651
 
 
 
 
 
66f64fe
 
f1c8651
 
 
 
6d22f9b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
afc4fb1
66f64fe
f1c8651
 
66f64fe
 
 
f1c8651
26c1b70
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
# Use an official Python runtime as a parent image
FROM python:3.9-slim

# Set the working directory in the container
WORKDIR /code

# Copy the requirements.txt file into the container at /code
COPY requirements.txt /code/requirements.txt

# Install any dependencies specified in requirements.txt
RUN pip install --no-cache-dir -r requirements.txt

# Apply the patch to remove flash-attn dependency and download the Florence-2-base-ft model and processor
RUN python -c "\
import os; \
from unittest.mock import patch; \
from transformers import AutoModelForCausalLM, AutoProcessor; \
from transformers.dynamic_module_utils import get_imports; \
def fixed_get_imports(filename: os.PathLike) -> list[str]: \
    if not str(filename).endswith('/modeling_florence2.py'): \
        return get_imports(filename); \
    imports = get_imports(filename); \
    if 'flash_attn' in imports: \
        imports.remove('flash_attn'); \
    return imports; \
with patch('transformers.dynamic_module_utils.get_imports', fixed_get_imports): \
    model = AutoModelForCausalLM.from_pretrained('microsoft/Florence-2-base-ft', trust_remote_code=True); \
    processor = AutoProcessor.from_pretrained('microsoft/Florence-2-base-ft', trust_remote_code=True); \
    model.save_pretrained('/code/florence_model'); \
    processor.save_pretrained('/code/florence_processor');"

# Copy the current directory contents into the container at /code
COPY . .

# Copy the numberPlate_model_2 folder to /code/numberPlate_model_2
COPY numberPlate_model_2 /code/numberPlate_model_2

# Command to run the FastAPI app using Uvicorn with live-reload
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]