from fastapi import FastAPI, File, UploadFile from fastapi.responses import HTMLResponse from transformers import AutoImageProcessor, AutoModelForImageClassification, pipeline from PIL import Image import io import uvicorn import base64 app = FastAPI() # Chargement des modèles def load_models(): return { "chest_classifier": pipeline("image-classification", model="codewithdark/vit-chest-xray") } models = load_models() def image_to_base64(image): buffered = io.BytesIO() image.save(buffered, format="PNG") img_str = base64.b64encode(buffered.getvalue()).decode() return f"data:image/png;base64,{img_str}" COMMON_STYLES = """ body { font-family: system-ui, -apple-system, sans-serif; background: #f0f2f5; margin: 0; padding: 20px; color: #1a1a1a; } ::-webkit-scrollbar { width: 8px; height: 8px; } ::-webkit-scrollbar-track { background: transparent; } ::-webkit-scrollbar-thumb { background-color: rgba(156, 163, 175, 0.5); border-radius: 4px; } .container { max-width: 1200px; margin: 0 auto; background: white; padding: 20px; border-radius: 10px; box-shadow: 0 2px 4px rgba(0,0,0,0.1); } .button { background: #2d2d2d; color: white; border: none; padding: 12px 30px; border-radius: 8px; cursor: pointer; font-size: 1.1em; transition: all 0.3s ease; position: relative; } .button:hover { background: #404040; } @keyframes progress { 0% { width: 0; } 100% { width: 100%; } } @keyframes blink { 0% { opacity: 1; } 50% { opacity: 0; } 100% { opacity: 1; } } #loading { display: none; color: white; margin-top: 10px; animation: blink 1s infinite; text-align: center; } .button-progress { position: absolute; bottom: 0; left: 0; height: 4px; background: rgba(255, 255, 255, 0.5); width: 0; } .button:active .button-progress { animation: progress 2s linear forwards; } img { max-width: 100%; height: auto; border-radius: 8px; } """ @app.get("/", response_class=HTMLResponse) async def main(): content = f"""
{str(e)}