Spaces:
Running
Running
delete issue
Browse files
Dockerfile
CHANGED
|
@@ -29,8 +29,8 @@ ENV HOME=/home/user \
|
|
| 29 |
# Copy app code
|
| 30 |
COPY --chown=user . .
|
| 31 |
|
| 32 |
-
# Install the package
|
| 33 |
-
RUN pip install --no-cache-dir --user
|
| 34 |
|
| 35 |
# Entry point
|
| 36 |
-
CMD ["
|
|
|
|
| 29 |
# Copy app code
|
| 30 |
COPY --chown=user . .
|
| 31 |
|
| 32 |
+
# Install the package from the current directory
|
| 33 |
+
RUN pip install --no-cache-dir --user .
|
| 34 |
|
| 35 |
# Entry point
|
| 36 |
+
CMD ["serve-comic-panel-extractor"]
|
comic_panel_extractor/llm_panel_extractor.py
CHANGED
|
@@ -7,6 +7,7 @@ from . import utils
|
|
| 7 |
import os
|
| 8 |
import shutil
|
| 9 |
import requests
|
|
|
|
| 10 |
|
| 11 |
class LLMPanelExtractor:
|
| 12 |
"""Handles image preprocessing operations."""
|
|
@@ -149,14 +150,17 @@ class LLMPanelExtractor:
|
|
| 149 |
|
| 150 |
return current_processed_image_path, existing_boxes
|
| 151 |
|
| 152 |
-
def extract_panel_via_llm(input_image_path, config=None):
|
| 153 |
"""Main function to extract panels using various image processing techniques."""
|
| 154 |
# Initialize configuration
|
| 155 |
extractor_config = config or Config()
|
| 156 |
extractor_config.org_input_path = input_image_path
|
| 157 |
|
| 158 |
# Clean output folder
|
| 159 |
-
|
|
|
|
|
|
|
|
|
|
| 160 |
|
| 161 |
# Initialize extractor
|
| 162 |
panel_extractor = LLMPanelExtractor(extractor_config)
|
|
|
|
| 7 |
import os
|
| 8 |
import shutil
|
| 9 |
import requests
|
| 10 |
+
from pathlib import Path
|
| 11 |
|
| 12 |
class LLMPanelExtractor:
|
| 13 |
"""Handles image preprocessing operations."""
|
|
|
|
| 150 |
|
| 151 |
return current_processed_image_path, existing_boxes
|
| 152 |
|
| 153 |
+
def extract_panel_via_llm(input_image_path, config=None, reset=True):
|
| 154 |
"""Main function to extract panels using various image processing techniques."""
|
| 155 |
# Initialize configuration
|
| 156 |
extractor_config = config or Config()
|
| 157 |
extractor_config.org_input_path = input_image_path
|
| 158 |
|
| 159 |
# Clean output folder
|
| 160 |
+
if reset:
|
| 161 |
+
if Path(extractor_config.output_folder).exists():
|
| 162 |
+
shutil.rmtree(extractor_config.output_folder, ignore_errors=True)
|
| 163 |
+
Path(extractor_config.output_folder).mkdir(exist_ok=True)
|
| 164 |
|
| 165 |
# Initialize extractor
|
| 166 |
panel_extractor = LLMPanelExtractor(extractor_config)
|
comic_panel_extractor/main.py
CHANGED
|
@@ -17,6 +17,7 @@ class ComicPanelExtractor:
|
|
| 17 |
|
| 18 |
def __init__(self, config: Config, reset: bool = True):
|
| 19 |
self.config = config
|
|
|
|
| 20 |
if reset:
|
| 21 |
if Path(self.config.output_folder).exists():
|
| 22 |
shutil.rmtree(self.config.output_folder)
|
|
@@ -34,7 +35,7 @@ class ComicPanelExtractor:
|
|
| 34 |
with Image.open(self.config.input_path) as original_image:
|
| 35 |
original_width, original_height = original_image.size
|
| 36 |
from .llm_panel_extractor import extract_panel_via_llm
|
| 37 |
-
all_path, detected_boxes, all_processed_boxes = extract_panel_via_llm(self.config.input_path, self.config)
|
| 38 |
if utils.box_covered_ratio(all_processed_boxes, (original_width, original_height)) < 0.95:
|
| 39 |
print("LLM failed.")
|
| 40 |
return None, None, all_path
|
|
|
|
| 17 |
|
| 18 |
def __init__(self, config: Config, reset: bool = True):
|
| 19 |
self.config = config
|
| 20 |
+
self.reset = reset
|
| 21 |
if reset:
|
| 22 |
if Path(self.config.output_folder).exists():
|
| 23 |
shutil.rmtree(self.config.output_folder)
|
|
|
|
| 35 |
with Image.open(self.config.input_path) as original_image:
|
| 36 |
original_width, original_height = original_image.size
|
| 37 |
from .llm_panel_extractor import extract_panel_via_llm
|
| 38 |
+
all_path, detected_boxes, all_processed_boxes = extract_panel_via_llm(self.config.input_path, self.config, self.reset)
|
| 39 |
if utils.box_covered_ratio(all_processed_boxes, (original_width, original_height)) < 0.95:
|
| 40 |
print("LLM failed.")
|
| 41 |
return None, None, all_path
|
comic_panel_extractor/server.py
CHANGED
|
@@ -90,8 +90,8 @@ async def convert_comic(file: UploadFile = File(...)):
|
|
| 90 |
file_id = os.path.splitext(file.filename)[0]
|
| 91 |
specific_output_folder = f'{output_folder}/{file_id}'
|
| 92 |
|
| 93 |
-
shutil.rmtree(specific_output_folder, ignore_errors=True)
|
| 94 |
-
Path(specific_output_folder).mkdir(exist_ok=True)
|
| 95 |
file_path = f'{specific_output_folder}/{file.filename}'
|
| 96 |
|
| 97 |
# Save uploaded file
|
|
|
|
| 90 |
file_id = os.path.splitext(file.filename)[0]
|
| 91 |
specific_output_folder = f'{output_folder}/{file_id}'
|
| 92 |
|
| 93 |
+
# shutil.rmtree(specific_output_folder, ignore_errors=True)
|
| 94 |
+
# Path(specific_output_folder).mkdir(exist_ok=True)
|
| 95 |
file_path = f'{specific_output_folder}/{file.filename}'
|
| 96 |
|
| 97 |
# Save uploaded file
|