Nisha56 commited on
Commit
e84e3d2
·
1 Parent(s): 6dd7eae

auth, LaMa inpainting, PostgreSQL, UI polish, back button, export fix

Browse files
Files changed (5) hide show
  1. Dockerfile +16 -9
  2. database.py +10 -0
  3. grounding.py +1 -1
  4. inpaint.py +2 -2
  5. requirements.txt +0 -0
Dockerfile CHANGED
@@ -1,32 +1,39 @@
1
- FROM python:3.11-slim
2
 
3
  WORKDIR /app
4
 
5
- # install system dependencies needed for opencv and paddleocr
6
  RUN apt-get update && apt-get install -y \
7
  libglib2.0-0 \
8
  libsm6 \
9
  libxext6 \
10
  libxrender-dev \
11
  libgomp1 \
 
12
  git \
 
13
  && rm -rf /var/lib/apt/lists/*
14
 
15
- # copy requirements first — Docker caches this layer
16
- COPY requirements.txt .
17
 
18
- # install Python packages
19
  RUN pip install --no-cache-dir --upgrade pip
 
 
 
 
 
 
 
 
 
20
  RUN pip install --no-cache-dir -r requirements.txt
21
 
22
- # copy all backend code
23
  COPY . .
24
 
25
- # create necessary folders
26
  RUN mkdir -p uploads outputs models
27
 
28
- # expose port
29
  EXPOSE 7860
30
 
31
- # start server — HF Spaces uses port 7860
32
  CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
 
1
+ FROM pytorch/pytorch:2.4.1-cuda12.1-cudnn9-runtime
2
 
3
  WORKDIR /app
4
 
5
+ # system dependencies
6
  RUN apt-get update && apt-get install -y \
7
  libglib2.0-0 \
8
  libsm6 \
9
  libxext6 \
10
  libxrender-dev \
11
  libgomp1 \
12
+ libgl1-mesa-glx \
13
  git \
14
+ wget \
15
  && rm -rf /var/lib/apt/lists/*
16
 
 
 
17
 
 
18
  RUN pip install --no-cache-dir --upgrade pip
19
+
20
+ RUN pip install --no-cache-dir \
21
+ torch==2.4.1+cu121 \
22
+ torchvision==0.19.1+cu121 \
23
+ torchaudio==2.4.1+cu121 \
24
+ --index-url https://download.pytorch.org/whl/cu121
25
+
26
+ # install all other dependencies
27
+ COPY requirements.txt .
28
  RUN pip install --no-cache-dir -r requirements.txt
29
 
30
+ # copy backend code
31
  COPY . .
32
 
33
+ # create runtime directories
34
  RUN mkdir -p uploads outputs models
35
 
36
+ # expose HF Spaces port
37
  EXPOSE 7860
38
 
 
39
  CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
database.py CHANGED
@@ -11,6 +11,16 @@ DB_URL = os.getenv("DATABASE_URL")
11
  engine = create_engine(
12
  DB_URL,
13
  pool_pre_ping=True,
 
 
 
 
 
 
 
 
 
 
14
  )
15
 
16
  SessionLocal = sessionmaker(
 
11
  engine = create_engine(
12
  DB_URL,
13
  pool_pre_ping=True,
14
+ pool_recycle=300,
15
+ pool_size=5,
16
+ max_overflow=2,
17
+ connect_args={
18
+ "connect_timeout": 10,
19
+ "keepalives": 1,
20
+ "keepalives_idle": 30,
21
+ "keepalives_interval": 5,
22
+ "keepalives_count": 5,
23
+ },
24
  )
25
 
26
  SessionLocal = sessionmaker(
grounding.py CHANGED
@@ -36,7 +36,7 @@ def detect_objects(image_path: str, model, text_prompt: str = None) -> list:
36
  # "image . graphic . illustration . icon . button"
37
  # )
38
  text_prompt = (
39
- "product . logo . person . icon . illustration . graphic . shape . cup"
40
  )
41
 
42
  image_pil, image_tensor = load_image(image_path)
 
36
  # "image . graphic . illustration . icon . button"
37
  # )
38
  text_prompt = (
39
+ "product . logo . person . icon . illustration . graphic . shape . cup . arrows"
40
  )
41
 
42
  image_pil, image_tensor = load_image(image_path)
inpaint.py CHANGED
@@ -87,7 +87,7 @@ def inpaint_region(
87
 
88
  result = output.images[0]
89
 
90
- # check if result is black (NaN issue on GTX 1650) — if so, use original
91
  result_arr = np.array(result)
92
  if result_arr.mean() < 10:
93
  print("[INPAINT] WARNING: Black output detected, applying fallback...")
@@ -140,7 +140,7 @@ if __name__ == "__main__":
140
  original = Image.open(TEST_IMAGE)
141
  img_w, img_h = original.size
142
 
143
- # mask the right poster card — x=630, y=46, w=410, h=573 from grounding.py
144
  test_mask = create_mask_from_bbox(TEST_IMAGE, x=630, y=46, w=410, h=573)
145
 
146
  mask_path = os.path.join(BACKEND_DIR, "outputs", "test_mask.jpg")
 
87
 
88
  result = output.images[0]
89
 
90
+ # check if result is black — if so, use original
91
  result_arr = np.array(result)
92
  if result_arr.mean() < 10:
93
  print("[INPAINT] WARNING: Black output detected, applying fallback...")
 
140
  original = Image.open(TEST_IMAGE)
141
  img_w, img_h = original.size
142
 
143
+
144
  test_mask = create_mask_from_bbox(TEST_IMAGE, x=630, y=46, w=410, h=573)
145
 
146
  mask_path = os.path.join(BACKEND_DIR, "outputs", "test_mask.jpg")
requirements.txt CHANGED
Binary files a/requirements.txt and b/requirements.txt differ