Spaces:
Sleeping
Sleeping
pierrelissope
commited on
Commit
·
bb3359e
1
Parent(s):
b665879
feat: combine main and back fine
Browse files
main.py
CHANGED
@@ -1,15 +1,28 @@
|
|
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",
|
@@ -23,7 +36,6 @@ app.add_middleware(
|
|
23 |
allow_headers=["*"], # Autorise tous les en-têtes
|
24 |
)
|
25 |
|
26 |
-
# Modèles Pydantic
|
27 |
class ImageData(BaseModel):
|
28 |
image: str
|
29 |
|
@@ -31,47 +43,26 @@ 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 |
-
|
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 |
-
|
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 |
-
|
74 |
-
|
|
|
75 |
|
76 |
-
return {"message": "Images reçues et sauvegardées"}
|
77 |
|
|
|
|
|
|
|
|
|
1 |
from fastapi import FastAPI, APIRouter
|
|
|
2 |
from fastapi.staticfiles import StaticFiles
|
3 |
from starlette.responses import FileResponse
|
4 |
+
from transformers import pipeline
|
5 |
+
from pydantic import BaseModel
|
6 |
+
from fastapi.middleware.cors import CORSMiddleware
|
7 |
+
import time
|
8 |
+
import base64
|
9 |
|
|
|
10 |
app = FastAPI()
|
11 |
+
router = APIRouter()
|
12 |
+
|
13 |
+
# Monter les fichiers statiques
|
14 |
+
|
15 |
+
@router.get("/")
|
16 |
+
async def index() -> FileResponse:
|
17 |
+
return FileResponse(path="front/dist/index.html", media_type="text/html")
|
18 |
+
@router.get("/verification")
|
19 |
+
async def verif() -> FileResponse:
|
20 |
+
return FileResponse(path="front/dist/index.html", media_type="text/html")
|
21 |
+
|
22 |
+
app.include_router(router)
|
23 |
+
|
24 |
+
app.mount("/", StaticFiles(directory="front/dist", html=True), name="static")
|
25 |
|
|
|
26 |
origins = [
|
27 |
"http://localhost:7860", # Exemple d'origine (ajoutez vos origines ici)
|
28 |
"https://example.com",
|
|
|
36 |
allow_headers=["*"], # Autorise tous les en-têtes
|
37 |
)
|
38 |
|
|
|
39 |
class ImageData(BaseModel):
|
40 |
image: str
|
41 |
|
|
|
43 |
idCard: str
|
44 |
profileImage: str
|
45 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
@app.post("/uploadpdf")
|
47 |
async def upload_pdf(image_data: ImageData):
|
48 |
# Extraire le contenu Base64
|
49 |
header, encoded = image_data.image.split(',', 1) # Séparer le header des données
|
50 |
binary_data = base64.b64decode(encoded) # Décoder les données
|
51 |
|
52 |
+
time.sleep(20);
|
|
|
53 |
|
54 |
return {"message": "Image reçue et sauvegardée"}
|
55 |
|
|
|
56 |
@app.post("/uploadids")
|
57 |
async def upload_ids(images_data: ImagesData):
|
|
|
58 |
header, encoded = images_data.idCard.split(',', 1) # Séparer le header des données
|
59 |
id_card_binary_data = base64.b64decode(encoded)
|
60 |
|
61 |
+
header, encoded = images_data.idCard.split(',', 1) # Séparer le header des données
|
|
|
62 |
profile_image_binary_data = base64.b64decode(encoded)
|
63 |
|
64 |
+
time.sleep(20);
|
65 |
+
|
66 |
+
return {"message": "Image reçue et sauvegardée"}
|
67 |
|
|
|
68 |
|