Spaces:
Running
Running
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}") |