face_analyze / app.py
phucbienvan
update
42e42f7
Raw History Blame Contribute Delete
1.38 kB
import sys
import os
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
import uvicorn
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from app.schemas.request_response import ImageRequest, SkinAnalysisResponse
from app.services.analysis_service import analyze_skin_from_url
# Rename the variable to avoid confusion with the module name
application = FastAPI(
title="Skin Analyzer API",
description="API for analyzing skin conditions from facial images",
version="1.0.0"
)
application.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
@application.get("/")
async def root():
return {"message": "Welcome to Skin Analyzer API"}
@application.post("/analyze", response_model=SkinAnalysisResponse)
async def analyze_skin(request: ImageRequest):
"""
Analyze skin conditions from an image URL
"""
try:
return await analyze_skin_from_url(request.image_url)
except Exception as e:
import logging
logging.error(f"Error processing request: {e}")
from fastapi import HTTPException
raise HTTPException(status_code=500, detail=str(e))
if __name__ == "__main__":
# Update the reference to use the new variable name
uvicorn.run("app.main:app", host="0.0.0.0", port=7860)