File size: 815 Bytes
5427e5e df464b1 5427e5e df464b1 5427e5e |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
import os
import sys
src_directory = os.path.abspath(os.path.join(os.path.dirname(__file__), "../../..", "src"))
sys.path.append(src_directory)
from fastapi import APIRouter, HTTPException
from schemas.schema import ImageSearch
from app import homepage
router = APIRouter()
@router.post("/search", summary="Find images by text")
def search_image(search_request: ImageSearch):
try:
query = search_request.query_text.strip()
if not query:
raise HTTPException(status_code=400, detail="Query text cannot be empty")
images = homepage.get_images_text_query(query)
if not images:
raise HTTPException(status_code=404, detail="No images found")
return images
except Exception as e:
raise HTTPException(status_code=500, detail=str(e))
|