Spaces:
Sleeping
Sleeping
Commit
·
78b545e
1
Parent(s):
e19d9bd
fix
Browse files- Dockerfile +11 -20
- __pycache__/main.cpython-312.pyc +0 -0
- main.py +7 -6
- prj.css → static/prj.css +0 -0
- prj.js → static/prj.js +0 -0
- translation.png → static/translation.png +0 -0
- prj.html → templates/prj.html +2 -2
Dockerfile
CHANGED
|
@@ -1,25 +1,16 @@
|
|
| 1 |
-
#
|
| 2 |
-
|
| 3 |
-
# Créer un répertoire pour les assets si nécessaire
|
| 4 |
-
RUN mkdir -p /app/assete
|
| 5 |
-
|
| 6 |
-
# Définit le répertoire de travail
|
| 7 |
-
WORKDIR /app
|
| 8 |
-
|
| 9 |
|
|
|
|
| 10 |
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
COPY prj.js /app/
|
| 15 |
-
COPY prj.css /app/
|
| 16 |
-
COPY requirements.txt /app/
|
| 17 |
-
|
| 18 |
-
# Installer les dépendances Python
|
| 19 |
-
RUN pip install --upgrade pip
|
| 20 |
-
RUN pip install -r requirements.txt
|
| 21 |
|
|
|
|
| 22 |
|
|
|
|
|
|
|
| 23 |
|
| 24 |
-
|
| 25 |
-
CMD ["uvicorn", "
|
|
|
|
| 1 |
+
# Read the doc: https://huggingface.co/docs/hub/spaces-sdks-docker
|
| 2 |
+
# you will also find guides on how best to write your Dockerfile
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
+
FROM python:3.10-slim
|
| 5 |
|
| 6 |
+
RUN useradd -m -u 1000 user
|
| 7 |
+
USER user
|
| 8 |
+
ENV PATH="/home/user/.local/bin:$PATH"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
+
WORKDIR /app
|
| 11 |
|
| 12 |
+
COPY --chown=user ./requirements.txt requirements.txt
|
| 13 |
+
RUN pip install --no-cache-dir --upgrade -r requirements.txt
|
| 14 |
|
| 15 |
+
COPY --chown=user . /app
|
| 16 |
+
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|
__pycache__/main.cpython-312.pyc
ADDED
|
Binary file (9.45 kB). View file
|
|
|
main.py
CHANGED
|
@@ -15,6 +15,7 @@ from langdetect import detect
|
|
| 15 |
from fastapi.staticfiles import StaticFiles
|
| 16 |
from fastapi.responses import HTMLResponse
|
| 17 |
from fastapi import Request
|
|
|
|
| 18 |
app = FastAPI()
|
| 19 |
|
| 20 |
app.add_middleware(
|
|
@@ -141,13 +142,13 @@ def translate_text(text, source_lang, target_lang):
|
|
| 141 |
|
| 142 |
return None # Pas de modèle disponible
|
| 143 |
|
|
|
|
|
|
|
|
|
|
| 144 |
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
async def serve_frontend():
|
| 149 |
-
with open("prj.html", "r", encoding="utf-8") as f:
|
| 150 |
-
return f.read()
|
| 151 |
|
| 152 |
@app.post("/translate")
|
| 153 |
|
|
|
|
| 15 |
from fastapi.staticfiles import StaticFiles
|
| 16 |
from fastapi.responses import HTMLResponse
|
| 17 |
from fastapi import Request
|
| 18 |
+
from fastapi.templating import Jinja2Templates
|
| 19 |
app = FastAPI()
|
| 20 |
|
| 21 |
app.add_middleware(
|
|
|
|
| 142 |
|
| 143 |
return None # Pas de modèle disponible
|
| 144 |
|
| 145 |
+
templates = Jinja2Templates(directory="templates")
|
| 146 |
+
# Mount static files (CSS, JS, images)
|
| 147 |
+
app.mount("/static", StaticFiles(directory="static"), name="static")
|
| 148 |
|
| 149 |
+
@app.get("/")
|
| 150 |
+
async def read_root(request: Request):
|
| 151 |
+
return templates.TemplateResponse("prj.html", {"request": request})
|
|
|
|
|
|
|
|
|
|
| 152 |
|
| 153 |
@app.post("/translate")
|
| 154 |
|
prj.css → static/prj.css
RENAMED
|
File without changes
|
prj.js → static/prj.js
RENAMED
|
File without changes
|
translation.png → static/translation.png
RENAMED
|
File without changes
|
prj.html → templates/prj.html
RENAMED
|
@@ -4,7 +4,7 @@
|
|
| 4 |
<meta charset="UTF-8">
|
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
<title>Traduction IA</title>
|
| 7 |
-
<link rel="stylesheet" href="
|
| 8 |
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;600&display=swap" rel="stylesheet">
|
| 9 |
<link href="https://fonts.googleapis.com/css2?family=Montserrat:wght@400;500;600;700&display=swap" rel="stylesheet">
|
| 10 |
</head>
|
|
@@ -37,7 +37,7 @@
|
|
| 37 |
<div id="resultat" class="resultat-box"></div>
|
| 38 |
</div>
|
| 39 |
|
| 40 |
-
<script src="
|
| 41 |
|
| 42 |
</body>
|
| 43 |
</html>
|
|
|
|
| 4 |
<meta charset="UTF-8">
|
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
<title>Traduction IA</title>
|
| 7 |
+
<link rel="stylesheet" href="/static/prj.css">
|
| 8 |
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;600&display=swap" rel="stylesheet">
|
| 9 |
<link href="https://fonts.googleapis.com/css2?family=Montserrat:wght@400;500;600;700&display=swap" rel="stylesheet">
|
| 10 |
</head>
|
|
|
|
| 37 |
<div id="resultat" class="resultat-box"></div>
|
| 38 |
</div>
|
| 39 |
|
| 40 |
+
<script src="/static/prj.js" ></script>
|
| 41 |
|
| 42 |
</body>
|
| 43 |
</html>
|