Spaces:
Sleeping
Sleeping
Update setup.py
Browse files
setup.py
CHANGED
|
@@ -1,34 +1,54 @@
|
|
| 1 |
import os
|
| 2 |
import subprocess
|
| 3 |
import sys
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
def setup_indiclid():
|
| 6 |
-
"""Setup IndicLID
|
|
|
|
| 7 |
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
# Create directories
|
| 11 |
os.makedirs("models", exist_ok=True)
|
| 12 |
-
os.chdir("models")
|
| 13 |
|
| 14 |
-
#
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
"https://github.com/AI4Bharat/IndicLID/releases/download/v1.0/indiclid-bert.zip",
|
| 17 |
-
"https://github.com/AI4Bharat/IndicLID/releases/download/v1.0/indiclid-ftn.zip",
|
| 18 |
"https://github.com/AI4Bharat/IndicLID/releases/download/v1.0/indiclid-ftr.zip"
|
| 19 |
]
|
| 20 |
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
print(f"
|
| 27 |
-
|
| 28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
-
os.chdir(
|
| 31 |
-
print("
|
|
|
|
| 32 |
|
| 33 |
if __name__ == "__main__":
|
| 34 |
setup_indiclid()
|
|
|
|
| 1 |
import os
|
| 2 |
import subprocess
|
| 3 |
import sys
|
| 4 |
+
import zipfile
|
| 5 |
+
import urllib.request
|
| 6 |
+
import shutil
|
| 7 |
+
from pathlib import Path
|
| 8 |
|
| 9 |
def setup_indiclid():
|
| 10 |
+
"""Setup IndicLID with proper class file"""
|
| 11 |
+
print("π Setting up IndicLID...")
|
| 12 |
|
| 13 |
+
# Create directory structure
|
| 14 |
+
os.makedirs("ai4bharat", exist_ok=True)
|
|
|
|
| 15 |
os.makedirs("models", exist_ok=True)
|
|
|
|
| 16 |
|
| 17 |
+
# Create __init__.py
|
| 18 |
+
with open("ai4bharat/__init__.py", "w") as f:
|
| 19 |
+
f.write("# AI4Bharat package\n")
|
| 20 |
+
|
| 21 |
+
# The IndicLID.py file should be created separately (above)
|
| 22 |
+
# Download model files
|
| 23 |
+
print("π€ Downloading IndicLID models...")
|
| 24 |
+
model_urls = [
|
| 25 |
"https://github.com/AI4Bharat/IndicLID/releases/download/v1.0/indiclid-bert.zip",
|
| 26 |
+
"https://github.com/AI4Bharat/IndicLID/releases/download/v1.0/indiclid-ftn.zip",
|
| 27 |
"https://github.com/AI4Bharat/IndicLID/releases/download/v1.0/indiclid-ftr.zip"
|
| 28 |
]
|
| 29 |
|
| 30 |
+
current_dir = os.getcwd()
|
| 31 |
+
os.chdir("models")
|
| 32 |
+
|
| 33 |
+
for url in model_urls:
|
| 34 |
+
filename = url.split("/")[-1]
|
| 35 |
+
print(f"π₯ Downloading {filename}...")
|
| 36 |
+
try:
|
| 37 |
+
urllib.request.urlretrieve(url, filename)
|
| 38 |
+
print(f"β
Downloaded {filename}")
|
| 39 |
+
|
| 40 |
+
print(f"π¦ Extracting {filename}...")
|
| 41 |
+
with zipfile.ZipFile(filename, 'r') as zip_ref:
|
| 42 |
+
zip_ref.extractall('.')
|
| 43 |
+
os.remove(filename)
|
| 44 |
+
print(f"β
Extracted {filename}")
|
| 45 |
+
|
| 46 |
+
except Exception as e:
|
| 47 |
+
print(f"β Error with {filename}: {e}")
|
| 48 |
|
| 49 |
+
os.chdir(current_dir)
|
| 50 |
+
print("π IndicLID setup completed!")
|
| 51 |
+
return True
|
| 52 |
|
| 53 |
if __name__ == "__main__":
|
| 54 |
setup_indiclid()
|