Spaces:
Sleeping
Sleeping
pierrelissope
commited on
Commit
·
b665879
1
Parent(s):
6ade7f5
fix: fixed job issues
Browse files- Dockerfile +1 -1
- main.py +61 -7
Dockerfile
CHANGED
|
@@ -15,4 +15,4 @@ COPY --chown=user . /app
|
|
| 15 |
# Changer d'utilisateur
|
| 16 |
USER user
|
| 17 |
|
| 18 |
-
CMD uvicorn main:app --host
|
|
|
|
| 15 |
# Changer d'utilisateur
|
| 16 |
USER user
|
| 17 |
|
| 18 |
+
CMD uvicorn main:app --host 0.0.0.0 --port 7860
|
main.py
CHANGED
|
@@ -1,23 +1,77 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
from fastapi import FastAPI, APIRouter
|
|
|
|
| 5 |
from fastapi.staticfiles import StaticFiles
|
| 6 |
from starlette.responses import FileResponse
|
| 7 |
-
from transformers import pipeline
|
| 8 |
|
|
|
|
| 9 |
app = FastAPI()
|
| 10 |
-
router = APIRouter()
|
| 11 |
|
| 12 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
@router.get("/")
|
| 15 |
async def index() -> FileResponse:
|
| 16 |
return FileResponse(path="front/dist/index.html", media_type="text/html")
|
|
|
|
| 17 |
@router.get("/verification")
|
| 18 |
async def verif() -> FileResponse:
|
| 19 |
return FileResponse(path="front/dist/index.html", media_type="text/html")
|
| 20 |
|
|
|
|
| 21 |
app.include_router(router)
|
| 22 |
-
|
| 23 |
app.mount("/", StaticFiles(directory="front/dist", html=True), name="static")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import time
|
| 2 |
+
import base64
|
| 3 |
+
from pydantic import BaseModel
|
| 4 |
from fastapi import FastAPI, APIRouter
|
| 5 |
+
from fastapi.middleware.cors import CORSMiddleware
|
| 6 |
from fastapi.staticfiles import StaticFiles
|
| 7 |
from starlette.responses import FileResponse
|
|
|
|
| 8 |
|
| 9 |
+
# Création de l'application FastAPI
|
| 10 |
app = FastAPI()
|
|
|
|
| 11 |
|
| 12 |
+
# Configuration du CORS
|
| 13 |
+
origins = [
|
| 14 |
+
"http://localhost:7860", # Exemple d'origine (ajoutez vos origines ici)
|
| 15 |
+
"https://example.com",
|
| 16 |
+
]
|
| 17 |
+
|
| 18 |
+
app.add_middleware(
|
| 19 |
+
CORSMiddleware,
|
| 20 |
+
allow_origins=origins, # Liste des origines autorisées
|
| 21 |
+
allow_credentials=True,
|
| 22 |
+
allow_methods=["*"], # Autorise toutes les méthodes (GET, POST, etc.)
|
| 23 |
+
allow_headers=["*"], # Autorise tous les en-têtes
|
| 24 |
+
)
|
| 25 |
+
|
| 26 |
+
# Modèles Pydantic
|
| 27 |
+
class ImageData(BaseModel):
|
| 28 |
+
image: str
|
| 29 |
|
| 30 |
+
class ImagesData(BaseModel):
|
| 31 |
+
idCard: str
|
| 32 |
+
profileImage: str
|
| 33 |
+
|
| 34 |
+
# Déclaration d'un routeur pour la gestion des fichiers statiques et des autres routes
|
| 35 |
+
router = APIRouter()
|
| 36 |
+
|
| 37 |
+
# Routes pour les fichiers statiques
|
| 38 |
@router.get("/")
|
| 39 |
async def index() -> FileResponse:
|
| 40 |
return FileResponse(path="front/dist/index.html", media_type="text/html")
|
| 41 |
+
|
| 42 |
@router.get("/verification")
|
| 43 |
async def verif() -> FileResponse:
|
| 44 |
return FileResponse(path="front/dist/index.html", media_type="text/html")
|
| 45 |
|
| 46 |
+
# Montée des fichiers statiques à la racine "/"
|
| 47 |
app.include_router(router)
|
|
|
|
| 48 |
app.mount("/", StaticFiles(directory="front/dist", html=True), name="static")
|
| 49 |
+
|
| 50 |
+
# Route pour l'upload d'image en base64
|
| 51 |
+
@app.post("/uploadpdf")
|
| 52 |
+
async def upload_pdf(image_data: ImageData):
|
| 53 |
+
# Extraire le contenu Base64
|
| 54 |
+
header, encoded = image_data.image.split(',', 1) # Séparer le header des données
|
| 55 |
+
binary_data = base64.b64decode(encoded) # Décoder les données
|
| 56 |
+
|
| 57 |
+
# Simulation du traitement avec un délai
|
| 58 |
+
time.sleep(20)
|
| 59 |
+
|
| 60 |
+
return {"message": "Image reçue et sauvegardée"}
|
| 61 |
+
|
| 62 |
+
# Route pour l'upload d'ID et d'image de profil
|
| 63 |
+
@app.post("/uploadids")
|
| 64 |
+
async def upload_ids(images_data: ImagesData):
|
| 65 |
+
# Traiter la carte d'identité
|
| 66 |
+
header, encoded = images_data.idCard.split(',', 1) # Séparer le header des données
|
| 67 |
+
id_card_binary_data = base64.b64decode(encoded)
|
| 68 |
+
|
| 69 |
+
# Traiter l'image de profil
|
| 70 |
+
header, encoded = images_data.profileImage.split(',', 1) # Séparer le header des données
|
| 71 |
+
profile_image_binary_data = base64.b64decode(encoded)
|
| 72 |
+
|
| 73 |
+
# Simulation du traitement avec un délai
|
| 74 |
+
time.sleep(20)
|
| 75 |
+
|
| 76 |
+
return {"message": "Images reçues et sauvegardées"}
|
| 77 |
+
|