Spaces:
Runtime error
Runtime error
gth commited on
Commit ·
285e32a
1
Parent(s): a4ba717
add PDF reader
Browse files
app.py
CHANGED
|
@@ -11,14 +11,14 @@ HF_TOKEN = os.environ.get("HF_TOKEN")
|
|
| 11 |
REPO_URL = "https://huggingface.co/spaces/gthai/gthUTranslate"
|
| 12 |
CLONE_DIR = "/app/gthUTranslate"
|
| 13 |
|
| 14 |
-
def setup_git_credentials(git_config_file):
|
| 15 |
-
subprocess.run(["git", "config", "--file", git_config_file, "credential.helper", "store"], check=True)
|
| 16 |
-
with open(
|
| 17 |
f.write(f"https://user:{HF_TOKEN}@huggingface.co\n")
|
| 18 |
|
| 19 |
-
def cleanup_git_credentials(git_config_file):
|
| 20 |
-
if os.path.exists(
|
| 21 |
-
os.remove(
|
| 22 |
if os.path.exists(git_config_file):
|
| 23 |
os.remove(git_config_file)
|
| 24 |
|
|
@@ -29,10 +29,11 @@ def clone_repository():
|
|
| 29 |
logging.info(f"Directory {CLONE_DIR} already exists. Removing it.")
|
| 30 |
shutil.rmtree(CLONE_DIR)
|
| 31 |
|
| 32 |
-
with tempfile.
|
| 33 |
-
tmp_config_path =
|
|
|
|
| 34 |
try:
|
| 35 |
-
setup_git_credentials(tmp_config_path)
|
| 36 |
|
| 37 |
logging.info(f"Cloning repository from {REPO_URL} to {CLONE_DIR}")
|
| 38 |
result = subprocess.run(["git", "clone", REPO_URL, CLONE_DIR],
|
|
@@ -49,7 +50,7 @@ def clone_repository():
|
|
| 49 |
logging.error(f"Erreur inattendue : {e}")
|
| 50 |
raise
|
| 51 |
finally:
|
| 52 |
-
cleanup_git_credentials(tmp_config_path)
|
| 53 |
|
| 54 |
def main():
|
| 55 |
clone_repository()
|
|
|
|
| 11 |
REPO_URL = "https://huggingface.co/spaces/gthai/gthUTranslate"
|
| 12 |
CLONE_DIR = "/app/gthUTranslate"
|
| 13 |
|
| 14 |
+
def setup_git_credentials(git_config_file, git_credentials_file):
|
| 15 |
+
subprocess.run(["git", "config", "--file", git_config_file, "credential.helper", f"store --file={git_credentials_file}"], check=True)
|
| 16 |
+
with open(git_credentials_file, "w") as f:
|
| 17 |
f.write(f"https://user:{HF_TOKEN}@huggingface.co\n")
|
| 18 |
|
| 19 |
+
def cleanup_git_credentials(git_config_file, git_credentials_file):
|
| 20 |
+
if os.path.exists(git_credentials_file):
|
| 21 |
+
os.remove(git_credentials_file)
|
| 22 |
if os.path.exists(git_config_file):
|
| 23 |
os.remove(git_config_file)
|
| 24 |
|
|
|
|
| 29 |
logging.info(f"Directory {CLONE_DIR} already exists. Removing it.")
|
| 30 |
shutil.rmtree(CLONE_DIR)
|
| 31 |
|
| 32 |
+
with tempfile.TemporaryDirectory() as tmp_dir:
|
| 33 |
+
tmp_config_path = os.path.join(tmp_dir, 'gitconfig')
|
| 34 |
+
tmp_credentials_path = os.path.join(tmp_dir, 'git-credentials')
|
| 35 |
try:
|
| 36 |
+
setup_git_credentials(tmp_config_path, tmp_credentials_path)
|
| 37 |
|
| 38 |
logging.info(f"Cloning repository from {REPO_URL} to {CLONE_DIR}")
|
| 39 |
result = subprocess.run(["git", "clone", REPO_URL, CLONE_DIR],
|
|
|
|
| 50 |
logging.error(f"Erreur inattendue : {e}")
|
| 51 |
raise
|
| 52 |
finally:
|
| 53 |
+
cleanup_git_credentials(tmp_config_path, tmp_credentials_path)
|
| 54 |
|
| 55 |
def main():
|
| 56 |
clone_repository()
|