Instructions to use openpecha/aligner with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use openpecha/aligner with Transformers:
# Load model directly from transformers import AutoTokenizer, AutoModelForSeq2SeqLM tokenizer = AutoTokenizer.from_pretrained("openpecha/aligner") model = AutoModelForSeq2SeqLM.from_pretrained("openpecha/aligner") - Notebooks
- Google Colab
- Kaggle
Update handler.py
Browse files- handler.py +11 -11
handler.py
CHANGED
|
@@ -23,9 +23,9 @@ git_clone_command = "git clone https://github.com/OpenPecha/tibetan-aligner"
|
|
| 23 |
# Run the command using subprocess
|
| 24 |
try:
|
| 25 |
subprocess.run(git_clone_command, shell=True, check=True)
|
| 26 |
-
|
| 27 |
except subprocess.CalledProcessError as e:
|
| 28 |
-
|
| 29 |
|
| 30 |
|
| 31 |
ALIGNER_SCRIPT_DIR = Path("./tibetan-aligner").resolve()
|
|
@@ -43,7 +43,7 @@ GITHUB_ORG = "MonlamAI"
|
|
| 43 |
MAI_TM_PUBLISH_TODO_REPO = "MonlamAI_TMs_Publish_TODO"
|
| 44 |
GITHUB_API_ENDPOINT = f"https://api.github.com/orgs/{GITHUB_ORG}/repos"
|
| 45 |
|
| 46 |
-
DEBUG =
|
| 47 |
|
| 48 |
quiet = "-q" if DEBUG else ""
|
| 49 |
def make_dir_executable(dir_path: Path):
|
|
@@ -106,7 +106,7 @@ def convert_raw_align_to_tm(align_fn: Path, tm_path: Path):
|
|
| 106 |
|
| 107 |
def load_alignment(fn: Path):
|
| 108 |
content = fn.read_text()
|
| 109 |
-
|
| 110 |
if not content:
|
| 111 |
return []
|
| 112 |
|
|
@@ -172,7 +172,7 @@ def add_to_publish_todo_repo(org, repo_name, file_path, access_token):
|
|
| 172 |
response = requests.get(url, headers=headers)
|
| 173 |
|
| 174 |
if response.status_code == 200:
|
| 175 |
-
|
| 176 |
return
|
| 177 |
|
| 178 |
payload = {"message": f"Add {file_path}", "content": ""}
|
|
@@ -180,10 +180,10 @@ def add_to_publish_todo_repo(org, repo_name, file_path, access_token):
|
|
| 180 |
response = requests.put(url, headers=headers, json=payload)
|
| 181 |
|
| 182 |
if response.status_code == 201:
|
| 183 |
-
|
| 184 |
else:
|
| 185 |
-
|
| 186 |
-
|
| 187 |
|
| 188 |
|
| 189 |
def create_tm(align_fn: Path, text_pair: Dict[str, str]):
|
|
@@ -246,10 +246,10 @@ def align(text_pair):
|
|
| 246 |
output_dir = Path(tmpdir)
|
| 247 |
bo_fn = download_file(text_pair["bo_file_url"], output_fn=output_dir / "bo.tx")
|
| 248 |
en_fn = download_file(text_pair["en_file_url"], output_fn=output_dir / "en.tx")
|
| 249 |
-
|
| 250 |
-
|
| 251 |
aligned_fn = _run_align_script(bo_fn, en_fn, output_dir)
|
| 252 |
-
|
| 253 |
repo_url = create_tm(aligned_fn, text_pair=text_pair)
|
| 254 |
return {"tm_repo_url": repo_url}
|
| 255 |
|
|
|
|
| 23 |
# Run the command using subprocess
|
| 24 |
try:
|
| 25 |
subprocess.run(git_clone_command, shell=True, check=True)
|
| 26 |
+
print("Git clone successful!")
|
| 27 |
except subprocess.CalledProcessError as e:
|
| 28 |
+
print(f"Error while running Git clone command: {e}")
|
| 29 |
|
| 30 |
|
| 31 |
ALIGNER_SCRIPT_DIR = Path("./tibetan-aligner").resolve()
|
|
|
|
| 43 |
MAI_TM_PUBLISH_TODO_REPO = "MonlamAI_TMs_Publish_TODO"
|
| 44 |
GITHUB_API_ENDPOINT = f"https://api.github.com/orgs/{GITHUB_ORG}/repos"
|
| 45 |
|
| 46 |
+
DEBUG = True
|
| 47 |
|
| 48 |
quiet = "-q" if DEBUG else ""
|
| 49 |
def make_dir_executable(dir_path: Path):
|
|
|
|
| 106 |
|
| 107 |
def load_alignment(fn: Path):
|
| 108 |
content = fn.read_text()
|
| 109 |
+
print("Content !!! \n\n"+content)
|
| 110 |
if not content:
|
| 111 |
return []
|
| 112 |
|
|
|
|
| 172 |
response = requests.get(url, headers=headers)
|
| 173 |
|
| 174 |
if response.status_code == 200:
|
| 175 |
+
print(f"[INFO] '{file_path}' already added.")
|
| 176 |
return
|
| 177 |
|
| 178 |
payload = {"message": f"Add {file_path}", "content": ""}
|
|
|
|
| 180 |
response = requests.put(url, headers=headers, json=payload)
|
| 181 |
|
| 182 |
if response.status_code == 201:
|
| 183 |
+
print(f"[INFO] '{file_path}' added to publish todo")
|
| 184 |
else:
|
| 185 |
+
print(f"[ERROR] Failed to add '{file_path}'.")
|
| 186 |
+
print(f"[ERROR] Response: {response.text}")
|
| 187 |
|
| 188 |
|
| 189 |
def create_tm(align_fn: Path, text_pair: Dict[str, str]):
|
|
|
|
| 246 |
output_dir = Path(tmpdir)
|
| 247 |
bo_fn = download_file(text_pair["bo_file_url"], output_fn=output_dir / "bo.tx")
|
| 248 |
en_fn = download_file(text_pair["en_file_url"], output_fn=output_dir / "en.tx")
|
| 249 |
+
print("bo_fn: ", bo_fn)
|
| 250 |
+
print("en_fn: ", en_fn)
|
| 251 |
aligned_fn = _run_align_script(bo_fn, en_fn, output_dir)
|
| 252 |
+
print("aligned_fn: ", aligned_fn)
|
| 253 |
repo_url = create_tm(aligned_fn, text_pair=text_pair)
|
| 254 |
return {"tm_repo_url": repo_url}
|
| 255 |
|