Spaces:
Sleeping
Sleeping
| import time | |
| from pydantic import BaseModel | |
| import base64 | |
| from fastapi import FastAPI, APIRouter | |
| from fastapi.middleware.cors import CORSMiddleware | |
| app = FastAPI() | |
| origins = [ | |
| "http://localhost:7860", | |
| "https://example.com", | |
| ] | |
| app.add_middleware( | |
| CORSMiddleware, | |
| allow_origins=origins, | |
| allow_credentials=True, | |
| allow_methods=["*"], | |
| allow_headers=["*"], | |
| ) | |
| class ImageData(BaseModel): | |
| image: str | |
| class ImagesData(BaseModel): | |
| idCard: str | |
| profileImage: str | |
| async def upload_pdf(image_data: ImageData): | |
| header, encoded = image_data.image.split(',', 1) | |
| binary_data = base64.b64decode(encoded) | |
| time.sleep(20); | |
| return {"message": "Image reçue et sauvegardée"} | |
| async def upload_ids(images_data: ImagesData): | |
| header, encoded = images_data.idCard.split(',', 1) | |
| id_card_binary_data = base64.b64decode(encoded) | |
| header, encoded = images_data.idCard.split(',', 1) | |
| profile_image_binary_data = base64.b64decode(encoded) | |
| time.sleep(20); | |
| return {"message": "Image reçue et sauvegardée"} | |