Spaces:
Sleeping
Sleeping
pierrelissope
commited on
Commit
·
7892632
1
Parent(s):
cc4bf16
fix: separated front and back
Browse files- Dockerfile +0 -4
- back.py +8 -9
- main.py +0 -51
Dockerfile
CHANGED
|
@@ -1,17 +1,13 @@
|
|
| 1 |
FROM python:3.10
|
| 2 |
|
| 3 |
-
# Créer un utilisateur
|
| 4 |
RUN useradd -m -u 1000 user
|
| 5 |
WORKDIR /app
|
| 6 |
|
| 7 |
-
# Copier et installer les dépendances
|
| 8 |
COPY --chown=user ./requirements.txt requirements.txt
|
| 9 |
RUN pip install --no-cache-dir --upgrade -r requirements.txt
|
| 10 |
|
| 11 |
-
# Copier l'application (y compris le dossier front)
|
| 12 |
COPY --chown=user . /app
|
| 13 |
|
| 14 |
-
# Changer d'utilisateur
|
| 15 |
USER user
|
| 16 |
|
| 17 |
CMD uvicorn main:app --host localhost --port 7860
|
|
|
|
| 1 |
FROM python:3.10
|
| 2 |
|
|
|
|
| 3 |
RUN useradd -m -u 1000 user
|
| 4 |
WORKDIR /app
|
| 5 |
|
|
|
|
| 6 |
COPY --chown=user ./requirements.txt requirements.txt
|
| 7 |
RUN pip install --no-cache-dir --upgrade -r requirements.txt
|
| 8 |
|
|
|
|
| 9 |
COPY --chown=user . /app
|
| 10 |
|
|
|
|
| 11 |
USER user
|
| 12 |
|
| 13 |
CMD uvicorn main:app --host localhost --port 7860
|
back.py
CHANGED
|
@@ -7,16 +7,16 @@ from fastapi.middleware.cors import CORSMiddleware
|
|
| 7 |
app = FastAPI()
|
| 8 |
|
| 9 |
origins = [
|
| 10 |
-
"http://localhost:7860",
|
| 11 |
"https://example.com",
|
| 12 |
]
|
| 13 |
|
| 14 |
app.add_middleware(
|
| 15 |
CORSMiddleware,
|
| 16 |
-
allow_origins=origins,
|
| 17 |
allow_credentials=True,
|
| 18 |
-
allow_methods=["*"],
|
| 19 |
-
allow_headers=["*"],
|
| 20 |
)
|
| 21 |
|
| 22 |
class ImageData(BaseModel):
|
|
@@ -28,9 +28,8 @@ class ImagesData(BaseModel):
|
|
| 28 |
|
| 29 |
@app.post("/uploadpdf")
|
| 30 |
async def upload_pdf(image_data: ImageData):
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
binary_data = base64.b64decode(encoded) # Décoder les données
|
| 34 |
|
| 35 |
time.sleep(20);
|
| 36 |
|
|
@@ -38,10 +37,10 @@ async def upload_pdf(image_data: ImageData):
|
|
| 38 |
|
| 39 |
@app.post("/uploadids")
|
| 40 |
async def upload_ids(images_data: ImagesData):
|
| 41 |
-
header, encoded = images_data.idCard.split(',', 1)
|
| 42 |
id_card_binary_data = base64.b64decode(encoded)
|
| 43 |
|
| 44 |
-
header, encoded = images_data.idCard.split(',', 1)
|
| 45 |
profile_image_binary_data = base64.b64decode(encoded)
|
| 46 |
|
| 47 |
time.sleep(20);
|
|
|
|
| 7 |
app = FastAPI()
|
| 8 |
|
| 9 |
origins = [
|
| 10 |
+
"http://localhost:7860",
|
| 11 |
"https://example.com",
|
| 12 |
]
|
| 13 |
|
| 14 |
app.add_middleware(
|
| 15 |
CORSMiddleware,
|
| 16 |
+
allow_origins=origins,
|
| 17 |
allow_credentials=True,
|
| 18 |
+
allow_methods=["*"],
|
| 19 |
+
allow_headers=["*"],
|
| 20 |
)
|
| 21 |
|
| 22 |
class ImageData(BaseModel):
|
|
|
|
| 28 |
|
| 29 |
@app.post("/uploadpdf")
|
| 30 |
async def upload_pdf(image_data: ImageData):
|
| 31 |
+
header, encoded = image_data.image.split(',', 1)
|
| 32 |
+
binary_data = base64.b64decode(encoded)
|
|
|
|
| 33 |
|
| 34 |
time.sleep(20);
|
| 35 |
|
|
|
|
| 37 |
|
| 38 |
@app.post("/uploadids")
|
| 39 |
async def upload_ids(images_data: ImagesData):
|
| 40 |
+
header, encoded = images_data.idCard.split(',', 1)
|
| 41 |
id_card_binary_data = base64.b64decode(encoded)
|
| 42 |
|
| 43 |
+
header, encoded = images_data.idCard.split(',', 1)
|
| 44 |
profile_image_binary_data = base64.b64decode(encoded)
|
| 45 |
|
| 46 |
time.sleep(20);
|
main.py
CHANGED
|
@@ -1,17 +1,10 @@
|
|
| 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")
|
|
@@ -22,47 +15,3 @@ async def verif() -> FileResponse:
|
|
| 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",
|
| 29 |
-
]
|
| 30 |
-
|
| 31 |
-
app.add_middleware(
|
| 32 |
-
CORSMiddleware,
|
| 33 |
-
allow_origins=origins, # Liste des origines autorisées
|
| 34 |
-
allow_credentials=True,
|
| 35 |
-
allow_methods=["*"], # Autorise toutes les méthodes (GET, POST, etc.)
|
| 36 |
-
allow_headers=["*"], # Autorise tous les en-têtes
|
| 37 |
-
)
|
| 38 |
-
|
| 39 |
-
class ImageData(BaseModel):
|
| 40 |
-
image: str
|
| 41 |
-
|
| 42 |
-
class ImagesData(BaseModel):
|
| 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 |
-
|
|
|
|
| 1 |
from fastapi import FastAPI, APIRouter
|
| 2 |
from fastapi.staticfiles import StaticFiles
|
| 3 |
from starlette.responses import FileResponse
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
app = FastAPI()
|
| 6 |
router = APIRouter()
|
| 7 |
|
|
|
|
|
|
|
| 8 |
@router.get("/")
|
| 9 |
async def index() -> FileResponse:
|
| 10 |
return FileResponse(path="front/dist/index.html", media_type="text/html")
|
|
|
|
| 15 |
app.include_router(router)
|
| 16 |
|
| 17 |
app.mount("/", StaticFiles(directory="front/dist", html=True), name="static")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|