Spaces:
Running
Running
analytics nav fix
Browse files- py_backend/app/main.py +1 -1
- py_backend/app/routers/upload.py +25 -7
py_backend/app/main.py
CHANGED
|
@@ -17,7 +17,7 @@ from app.routers.prompts import router as prompts_router
|
|
| 17 |
from app.routers.admin import router as admin_router
|
| 18 |
from app.routers.schemas import router as schemas_router
|
| 19 |
|
| 20 |
-
app = FastAPI(title="PromptAid Vision")
|
| 21 |
|
| 22 |
app.add_middleware(
|
| 23 |
CORSMiddleware,
|
|
|
|
| 17 |
from app.routers.admin import router as admin_router
|
| 18 |
from app.routers.schemas import router as schemas_router
|
| 19 |
|
| 20 |
+
app = FastAPI(title="PromptAid Vision", redirect_slashes=False)
|
| 21 |
|
| 22 |
app.add_middleware(
|
| 23 |
CORSMiddleware,
|
py_backend/app/routers/upload.py
CHANGED
|
@@ -2,6 +2,7 @@ from fastapi import APIRouter, UploadFile, Form, Depends, HTTPException, Respons
|
|
| 2 |
from pydantic import BaseModel
|
| 3 |
import io
|
| 4 |
from sqlalchemy.orm import Session
|
|
|
|
| 5 |
from .. import crud, schemas, storage, database
|
| 6 |
from ..config import settings
|
| 7 |
from ..services.image_preprocessor import ImagePreprocessor
|
|
@@ -94,13 +95,30 @@ def convert_image_to_dict(img, image_url):
|
|
| 94 |
@router.get("/", response_model=List[schemas.ImageOut])
|
| 95 |
def list_images(db: Session = Depends(get_db)):
|
| 96 |
"""Get all images with their caption data"""
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 104 |
|
| 105 |
@router.get("/{image_id}", response_model=schemas.ImageOut)
|
| 106 |
def get_image(image_id: str, db: Session = Depends(get_db)):
|
|
|
|
| 2 |
from pydantic import BaseModel
|
| 3 |
import io
|
| 4 |
from sqlalchemy.orm import Session
|
| 5 |
+
from sqlalchemy import text
|
| 6 |
from .. import crud, schemas, storage, database
|
| 7 |
from ..config import settings
|
| 8 |
from ..services.image_preprocessor import ImagePreprocessor
|
|
|
|
| 95 |
@router.get("/", response_model=List[schemas.ImageOut])
|
| 96 |
def list_images(db: Session = Depends(get_db)):
|
| 97 |
"""Get all images with their caption data"""
|
| 98 |
+
try:
|
| 99 |
+
print(f"DEBUG: Checking database connection")
|
| 100 |
+
# Test database connection
|
| 101 |
+
db.execute(text("SELECT 1"))
|
| 102 |
+
print(f"DEBUG: Database connection OK")
|
| 103 |
+
|
| 104 |
+
print(f"DEBUG: Fetching images from database")
|
| 105 |
+
images = crud.get_images(db)
|
| 106 |
+
print(f"DEBUG: Found {len(images)} images")
|
| 107 |
+
|
| 108 |
+
result = []
|
| 109 |
+
for img in images:
|
| 110 |
+
try:
|
| 111 |
+
img_dict = convert_image_to_dict(img, f"/api/images/{img.image_id}/file")
|
| 112 |
+
result.append(schemas.ImageOut(**img_dict))
|
| 113 |
+
except Exception as e:
|
| 114 |
+
print(f"ERROR: Failed to process image {img.image_id}: {e}")
|
| 115 |
+
continue
|
| 116 |
+
|
| 117 |
+
print(f"DEBUG: Returning {len(result)} processed images")
|
| 118 |
+
return result
|
| 119 |
+
except Exception as e:
|
| 120 |
+
print(f"ERROR: Failed to fetch images: {e}")
|
| 121 |
+
raise HTTPException(status_code=500, detail=f"Failed to fetch images: {str(e)}")
|
| 122 |
|
| 123 |
@router.get("/{image_id}", response_model=schemas.ImageOut)
|
| 124 |
def get_image(image_id: str, db: Session = Depends(get_db)):
|