Spaces:
Runtime error
Runtime error
gth commited on
Commit ·
2c9f53d
1
Parent(s): 63990f7
add PDF
Browse files- Dockerfile +3 -5
- app.py +22 -15
Dockerfile
CHANGED
|
@@ -1,19 +1,17 @@
|
|
| 1 |
FROM python:3.9-slim
|
| 2 |
|
| 3 |
-
# Install Tesseract
|
| 4 |
RUN apt-get update && apt-get install -y \
|
| 5 |
tesseract-ocr \
|
| 6 |
libtesseract-dev \
|
|
|
|
| 7 |
&& rm -rf /var/lib/apt/lists/*
|
| 8 |
|
| 9 |
-
RUN apt-get update && apt-get install -y git
|
| 10 |
-
|
| 11 |
WORKDIR /app
|
| 12 |
|
| 13 |
COPY . /app
|
| 14 |
|
| 15 |
-
|
| 16 |
-
# Installer les dépendances Python
|
| 17 |
RUN pip install --no-cache-dir -r requirements.txt
|
| 18 |
|
| 19 |
EXPOSE 7861
|
|
|
|
| 1 |
FROM python:3.9-slim
|
| 2 |
|
| 3 |
+
# Install Tesseract and Git
|
| 4 |
RUN apt-get update && apt-get install -y \
|
| 5 |
tesseract-ocr \
|
| 6 |
libtesseract-dev \
|
| 7 |
+
git \
|
| 8 |
&& rm -rf /var/lib/apt/lists/*
|
| 9 |
|
|
|
|
|
|
|
| 10 |
WORKDIR /app
|
| 11 |
|
| 12 |
COPY . /app
|
| 13 |
|
| 14 |
+
# Install Python dependencies
|
|
|
|
| 15 |
RUN pip install --no-cache-dir -r requirements.txt
|
| 16 |
|
| 17 |
EXPOSE 7861
|
app.py
CHANGED
|
@@ -2,6 +2,7 @@ import os
|
|
| 2 |
import subprocess
|
| 3 |
import sys
|
| 4 |
import logging
|
|
|
|
| 5 |
|
| 6 |
logging.basicConfig(level=logging.INFO)
|
| 7 |
|
|
@@ -13,16 +14,21 @@ logging.info(f"Token is present : {'Yes' if hf_token else 'No'}")
|
|
| 13 |
|
| 14 |
if not os.path.exists(clone_dir):
|
| 15 |
try:
|
| 16 |
-
#
|
| 17 |
-
|
| 18 |
-
"
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
#
|
| 23 |
-
subprocess.run(
|
| 24 |
-
|
| 25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
except subprocess.CalledProcessError as e:
|
| 27 |
logging.error(f"Error when cloning : {e}")
|
| 28 |
logging.error(f"Output of the command : {e.output}")
|
|
@@ -30,14 +36,15 @@ if not os.path.exists(clone_dir):
|
|
| 30 |
except Exception as e:
|
| 31 |
logging.error(f"Unexpected Errors : {e}")
|
| 32 |
raise
|
|
|
|
|
|
|
|
|
|
| 33 |
|
| 34 |
-
#
|
| 35 |
sys.path.append(clone_dir)
|
| 36 |
|
| 37 |
-
#
|
| 38 |
from gthUTranslate.app import demo
|
| 39 |
|
| 40 |
-
|
| 41 |
-
# Lauch app
|
| 42 |
if __name__ == "__main__":
|
| 43 |
-
demo.launch(server_name="0.0.0.0", server_port=7861)
|
|
|
|
| 2 |
import subprocess
|
| 3 |
import sys
|
| 4 |
import logging
|
| 5 |
+
import tempfile
|
| 6 |
|
| 7 |
logging.basicConfig(level=logging.INFO)
|
| 8 |
|
|
|
|
| 14 |
|
| 15 |
if not os.path.exists(clone_dir):
|
| 16 |
try:
|
| 17 |
+
# Utiliser un fichier de configuration Git temporaire pour éviter les problèmes de permissions
|
| 18 |
+
with tempfile.NamedTemporaryFile(delete=False) as gitconfig:
|
| 19 |
+
gitconfig.write(b"[credential]\n\thelper = store\n")
|
| 20 |
+
gitconfig.write(f"https://user:{hf_token}@huggingface.co\n".encode())
|
| 21 |
+
gitconfig_path = gitconfig.name
|
| 22 |
+
|
| 23 |
+
# Utiliser la configuration Git temporaire pour cloner le dépôt
|
| 24 |
+
subprocess.run([
|
| 25 |
+
"git", "clone", repo_url, clone_dir,
|
| 26 |
+
"--config", f"credential.helper=store",
|
| 27 |
+
"--config", f"http.https://huggingface.co/.extraheader=Authorization: Bearer {hf_token}"
|
| 28 |
+
], check=True, capture_output=True, text=True, env={"GIT_CONFIG_GLOBAL": gitconfig_path})
|
| 29 |
+
|
| 30 |
+
logging.info("Clonage réussi")
|
| 31 |
+
|
| 32 |
except subprocess.CalledProcessError as e:
|
| 33 |
logging.error(f"Error when cloning : {e}")
|
| 34 |
logging.error(f"Output of the command : {e.output}")
|
|
|
|
| 36 |
except Exception as e:
|
| 37 |
logging.error(f"Unexpected Errors : {e}")
|
| 38 |
raise
|
| 39 |
+
finally:
|
| 40 |
+
if os.path.exists(gitconfig_path):
|
| 41 |
+
os.remove(gitconfig_path)
|
| 42 |
|
| 43 |
+
# Ajouter le répertoire du repo au chemin Python
|
| 44 |
sys.path.append(clone_dir)
|
| 45 |
|
| 46 |
+
# Importer et lancer l'application
|
| 47 |
from gthUTranslate.app import demo
|
| 48 |
|
|
|
|
|
|
|
| 49 |
if __name__ == "__main__":
|
| 50 |
+
demo.launch(server_name="0.0.0.0", server_port=7861)
|