File size: 1,109 Bytes
5823725
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import os
import shutil
import requests

def prepare():
    url = "https://raw.githubusercontent.com/tesseract-ocr/tessdata/main/vie.traineddata"

    # Destination file path
    destination_path = "vie.traineddata"

    try:
        print(f"Downloading from {url}...")
        response = requests.get(url, stream=True)
        response.raise_for_status()  # Raise an HTTPError for bad responses (4xx and 5xx)

        # Write the content to a file
        destination_path = 'vie.traineddata'
        with open(destination_path, "wb") as file:
            for chunk in response.iter_content(chunk_size=8192):  # Download in chunks
                file.write(chunk)

        print(f"File downloaded successfully and saved as {destination_path}")
    except requests.exceptions.RequestException as e:
        print(f"An error occurred: {e}")

    destination_folder = '/usr/share/tesseract-ocr/5/tessdata'
    destination_file = os.path.join(destination_folder, os.path.basename(destination_path))
    shutil.copy(destination_path, destination_file)
    print(f"File copied successfully to {destination_file}")