File size: 2,397 Bytes
5ce8318
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import os
import subprocess
from pathlib import Path

def download_model_if_not_exists():
    """
    Download model from Hugging Face if the model directory doesn't exist.
    """
    model_dir = Path("./model")
    if not model_dir.exists():
        print("Model directory not found. Downloading from Hugging Face...")
        try:
            # Create model directory
            model_dir.mkdir(parents=True, exist_ok=True)
            
            # Install git-lfs if not already installed
            subprocess.run(["git", "lfs", "install"], check=True)
            
            # Clone the model repository
            subprocess.run([
                "git", "clone", 
                "https://huggingface.co/spaces/dinhanit/triventure_model",
                "temp_model"
            ], check=True)
            
            # Copy model files
            subprocess.run([
                "cp", "-r", 
                "temp_model/model/*", 
                str(model_dir)
            ], check=True)
            
            # Clean up
            subprocess.run(["rm", "-rf", "temp_model"], check=True)
            
            print("Model downloaded successfully!")
        except Exception as e:
            print(f"Error downloading model: {str(e)}")
            raise
    else:
        print("Model directory already exists. Skipping download.") 

def download_image_if_not_exists():
    image_dir = Path("./images")
    if not image_dir.exists():
        print("Image directory not found. Downloading from Hugging Face...")
        try:
            # Create image directory
            image_dir.mkdir(parents=True, exist_ok=True)

            # Clone the image repository
            subprocess.run([
                "git", "clone", 
                "https://huggingface.co/spaces/dinhanit/triventure_image",
                "temp_image"
            ], check=True)

            # Copy image files
            subprocess.run([
                "cp", "-r", 
                "temp_image/images/*", 
                str(image_dir)
            ], check=True)

            # Clean up
            subprocess.run(["rm", "-rf", "temp_image"], check=True)

            print("Image downloaded successfully!")
        except Exception as e:
            print(f"Error downloading image: {str(e)}")
            raise
    else:
        print("Image directory already exists. Skipping download.")