Spaces:
Sleeping
Sleeping
AdarshRajDS commited on
Commit ·
521f9db
1
Parent(s): f3ce440
Add endpoint to list all extracted images
Browse files- app/api/routes/images.py +23 -0
- app/main.py +5 -0
app/api/routes/images.py
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import APIRouter
|
| 2 |
+
from pathlib import Path
|
| 3 |
+
import os
|
| 4 |
+
|
| 5 |
+
router = APIRouter(prefix="/images", tags=["Images"])
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
@router.get("/all")
|
| 9 |
+
def list_images():
|
| 10 |
+
|
| 11 |
+
BASE_DATA_DIR = os.getenv("HF_HOME", ".")
|
| 12 |
+
OUTPUT_DIR = os.path.join(BASE_DATA_DIR, "outputs")
|
| 13 |
+
|
| 14 |
+
if not os.path.exists(OUTPUT_DIR):
|
| 15 |
+
return {"images": []}
|
| 16 |
+
|
| 17 |
+
image_urls = [
|
| 18 |
+
f"outputs/{file.name}"
|
| 19 |
+
for file in Path(OUTPUT_DIR).glob("*")
|
| 20 |
+
if file.suffix.lower() in [".png", ".jpg", ".jpeg"]
|
| 21 |
+
]
|
| 22 |
+
|
| 23 |
+
return {"images": image_urls}
|
app/main.py
CHANGED
|
@@ -4,6 +4,9 @@ from fastapi.staticfiles import StaticFiles
|
|
| 4 |
|
| 5 |
from app.api.routes import rag, visualize, grading, upload
|
| 6 |
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
# ✅ Use persistent storage on HF, local folder otherwise
|
| 9 |
BASE_DATA_DIR = os.getenv("HF_HOME", ".")
|
|
@@ -20,6 +23,8 @@ app.include_router(rag.router)
|
|
| 20 |
app.include_router(visualize.router)
|
| 21 |
app.include_router(grading.router)
|
| 22 |
app.include_router(upload.router)
|
|
|
|
|
|
|
| 23 |
|
| 24 |
|
| 25 |
# ✅ Mount the real path (not hardcoded "outputs")
|
|
|
|
| 4 |
|
| 5 |
from app.api.routes import rag, visualize, grading, upload
|
| 6 |
|
| 7 |
+
from app.api.routes import images
|
| 8 |
+
|
| 9 |
+
|
| 10 |
|
| 11 |
# ✅ Use persistent storage on HF, local folder otherwise
|
| 12 |
BASE_DATA_DIR = os.getenv("HF_HOME", ".")
|
|
|
|
| 23 |
app.include_router(visualize.router)
|
| 24 |
app.include_router(grading.router)
|
| 25 |
app.include_router(upload.router)
|
| 26 |
+
app.include_router(images.router)
|
| 27 |
+
|
| 28 |
|
| 29 |
|
| 30 |
# ✅ Mount the real path (not hardcoded "outputs")
|