Spaces:
Running
Running
added folder
Browse files
comic_panel_extractor/server.py
CHANGED
|
@@ -16,6 +16,7 @@ import traceback
|
|
| 16 |
from pathlib import Path
|
| 17 |
import shutil
|
| 18 |
import time
|
|
|
|
| 19 |
|
| 20 |
current_path = os.path.abspath(os.path.join(os.path.dirname(__file__)))
|
| 21 |
|
|
@@ -117,25 +118,26 @@ async def convert_comic(file: UploadFile = File(...)):
|
|
| 117 |
print(f"[DEBUG] Setting config.output_folder to: {config.output_folder}")
|
| 118 |
|
| 119 |
_, _, all_panel_path = ComicPanelExtractor(config, reset=False).extract_panels_from_comic()
|
| 120 |
-
all_panel_path = [f'/{
|
| 121 |
|
| 122 |
return {
|
| 123 |
"success": True,
|
| 124 |
"message": f"Extracted {len(all_panel_path)} panels",
|
| 125 |
-
"panels": all_panel_path
|
| 126 |
-
"folder": specific_output_folder
|
| 127 |
}
|
| 128 |
|
| 129 |
except Exception as e:
|
| 130 |
print(f"Error processing image: {str(e)} {traceback.format_exc()}")
|
| 131 |
raise HTTPException(status_code=500, detail=f"Error processing image: {str(e)} {traceback.format_exc()}")
|
| 132 |
|
| 133 |
-
@app.get("/api_outputs/{filename}")
|
| 134 |
async def get_output_file(folder: str, filename: str):
|
| 135 |
-
file_path =
|
| 136 |
if not os.path.exists(file_path):
|
| 137 |
raise HTTPException(status_code=404, detail="File not found")
|
| 138 |
-
|
|
|
|
|
|
|
| 139 |
|
| 140 |
def main():
|
| 141 |
import uvicorn
|
|
|
|
| 16 |
from pathlib import Path
|
| 17 |
import shutil
|
| 18 |
import time
|
| 19 |
+
import mimetypes
|
| 20 |
|
| 21 |
current_path = os.path.abspath(os.path.join(os.path.dirname(__file__)))
|
| 22 |
|
|
|
|
| 118 |
print(f"[DEBUG] Setting config.output_folder to: {config.output_folder}")
|
| 119 |
|
| 120 |
_, _, all_panel_path = ComicPanelExtractor(config, reset=False).extract_panels_from_comic()
|
| 121 |
+
all_panel_path = [f'/{"/".join(path.split("/")[-3:])}' for path in all_panel_path]
|
| 122 |
|
| 123 |
return {
|
| 124 |
"success": True,
|
| 125 |
"message": f"Extracted {len(all_panel_path)} panels",
|
| 126 |
+
"panels": all_panel_path
|
|
|
|
| 127 |
}
|
| 128 |
|
| 129 |
except Exception as e:
|
| 130 |
print(f"Error processing image: {str(e)} {traceback.format_exc()}")
|
| 131 |
raise HTTPException(status_code=500, detail=f"Error processing image: {str(e)} {traceback.format_exc()}")
|
| 132 |
|
| 133 |
+
@app.get("/api_outputs/{folder}/{filename}")
|
| 134 |
async def get_output_file(folder: str, filename: str):
|
| 135 |
+
file_path = f'{output_folder}/{folder}/{filename}'
|
| 136 |
if not os.path.exists(file_path):
|
| 137 |
raise HTTPException(status_code=404, detail="File not found")
|
| 138 |
+
|
| 139 |
+
mime_type, _ = mimetypes.guess_type(file_path)
|
| 140 |
+
return FileResponse(file_path, media_type=mime_type, filename=filename)
|
| 141 |
|
| 142 |
def main():
|
| 143 |
import uvicorn
|
comic_panel_extractor/static/index.html
CHANGED
|
@@ -428,7 +428,7 @@
|
|
| 428 |
|
| 429 |
if (data.success) {
|
| 430 |
showMessage(data.message, 'success');
|
| 431 |
-
displayPanels(data.panels
|
| 432 |
} else {
|
| 433 |
showMessage(data.message || 'An error occurred', 'error');
|
| 434 |
}
|
|
@@ -479,7 +479,7 @@
|
|
| 479 |
}
|
| 480 |
});
|
| 481 |
|
| 482 |
-
function displayPanels(panels
|
| 483 |
panelsGrid.innerHTML = '';
|
| 484 |
|
| 485 |
if (panels.length === 0) {
|
|
@@ -494,7 +494,7 @@
|
|
| 494 |
panelCard.innerHTML = `
|
| 495 |
<img src="${panel}" alt="Panel ${index + 1}" onclick="openModal('${panel}')">
|
| 496 |
<div class="panel-title">Panel ${index + 1}</div>
|
| 497 |
-
<a href="${panel}
|
| 498 |
Download
|
| 499 |
</a>
|
| 500 |
`;
|
|
|
|
| 428 |
|
| 429 |
if (data.success) {
|
| 430 |
showMessage(data.message, 'success');
|
| 431 |
+
displayPanels(data.panels);
|
| 432 |
} else {
|
| 433 |
showMessage(data.message || 'An error occurred', 'error');
|
| 434 |
}
|
|
|
|
| 479 |
}
|
| 480 |
});
|
| 481 |
|
| 482 |
+
function displayPanels(panels) {
|
| 483 |
panelsGrid.innerHTML = '';
|
| 484 |
|
| 485 |
if (panels.length === 0) {
|
|
|
|
| 494 |
panelCard.innerHTML = `
|
| 495 |
<img src="${panel}" alt="Panel ${index + 1}" onclick="openModal('${panel}')">
|
| 496 |
<div class="panel-title">Panel ${index + 1}</div>
|
| 497 |
+
<a href="${panel}" download="${panel}" class="panel-download">
|
| 498 |
Download
|
| 499 |
</a>
|
| 500 |
`;
|