Spaces:
Runtime error
Runtime error
wip
Browse files- app.py +5 -1
- packages.txt +4 -0
- requirements.txt +4 -1
- setup.py +97 -0
app.py
CHANGED
|
@@ -1,11 +1,11 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import os
|
|
|
|
| 3 |
|
| 4 |
temp_folder = 'tmp'
|
| 5 |
|
| 6 |
|
| 7 |
def upload_file(filepath, source_lang, target_lang, translator_version):
|
| 8 |
-
|
| 9 |
if translator_version == "v1":
|
| 10 |
from src.salamandraTA7b_translator_external_aligner import SalamandraTA7bTranslatorExternalAligner
|
| 11 |
from src.aligner import Aligner
|
|
@@ -60,4 +60,8 @@ with gr.Blocks() as demo:
|
|
| 60 |
[u, d, status_text])
|
| 61 |
d.click(download_file, None, [u, d])
|
| 62 |
if __name__ == "__main__":
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
demo.launch(server_name="0.0.0.0", server_port=7860)
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import os
|
| 3 |
+
import setup
|
| 4 |
|
| 5 |
temp_folder = 'tmp'
|
| 6 |
|
| 7 |
|
| 8 |
def upload_file(filepath, source_lang, target_lang, translator_version):
|
|
|
|
| 9 |
if translator_version == "v1":
|
| 10 |
from src.salamandraTA7b_translator_external_aligner import SalamandraTA7bTranslatorExternalAligner
|
| 11 |
from src.aligner import Aligner
|
|
|
|
| 60 |
[u, d, status_text])
|
| 61 |
d.click(download_file, None, [u, d])
|
| 62 |
if __name__ == "__main__":
|
| 63 |
+
# check if fastalign needs to be built, ie it's the first time this app is being run
|
| 64 |
+
if not os.path.exists("fast_align"):
|
| 65 |
+
setup.main()
|
| 66 |
+
|
| 67 |
demo.launch(server_name="0.0.0.0", server_port=7860)
|
packages.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
libgomp1
|
| 2 |
+
openjdk-21-jre-headless
|
| 3 |
+
cmake
|
| 4 |
+
build-essential
|
requirements.txt
CHANGED
|
@@ -11,4 +11,7 @@ torch~=2.8.0
|
|
| 11 |
huggingface-hub~=0.36.0
|
| 12 |
vllm~=0.11.0
|
| 13 |
iso-639~=0.4.5
|
| 14 |
-
accelerate~=1.11.0
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
huggingface-hub~=0.36.0
|
| 12 |
vllm~=0.11.0
|
| 13 |
iso-639~=0.4.5
|
| 14 |
+
accelerate~=1.11.0
|
| 15 |
+
gradio_client~=1.8.0
|
| 16 |
+
gdown~=5.2.0
|
| 17 |
+
GitPython~=3.1.45
|
setup.py
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import shutil
|
| 3 |
+
import zipfile
|
| 4 |
+
import subprocess
|
| 5 |
+
import requests
|
| 6 |
+
|
| 7 |
+
import sys
|
| 8 |
+
|
| 9 |
+
from git import Repo
|
| 10 |
+
import gdown
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
def run(cmd, cwd=None):
|
| 14 |
+
"""Run a system command with error checking."""
|
| 15 |
+
print(f"Running: {cmd}")
|
| 16 |
+
subprocess.run(cmd, check=True, cwd=cwd)
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
def check_needs_building():
|
| 20 |
+
return not os.path.exists("fast_align") or not os.path.exists("atools") or not os.path.isdir(
|
| 21 |
+
"okapi-apps_gtk2-linux-x86_64_1.47.0")
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
def main():
|
| 25 |
+
# -------------------------------------------------------------------
|
| 26 |
+
# 1. Clone and compile fast_align
|
| 27 |
+
# -------------------------------------------------------------------
|
| 28 |
+
|
| 29 |
+
print("Cloning fast_align repository...")
|
| 30 |
+
Repo.clone_from("https://github.com/clab/fast_align.git", "fast_align_src")
|
| 31 |
+
|
| 32 |
+
# Create build directory
|
| 33 |
+
build_dir = "fast_align_src/build"
|
| 34 |
+
os.makedirs(build_dir, exist_ok=True)
|
| 35 |
+
|
| 36 |
+
print("Running CMake...")
|
| 37 |
+
run(["cmake", "-DCMAKE_POLICY_VERSION_MINIMUM=3.5", ".."], cwd=build_dir)
|
| 38 |
+
|
| 39 |
+
print("Running make...")
|
| 40 |
+
run(["make"], cwd=build_dir)
|
| 41 |
+
|
| 42 |
+
# Copy binaries
|
| 43 |
+
shutil.copy("fast_align_src/build/fast_align", ".")
|
| 44 |
+
shutil.copy("fast_align_src/build/atools", ".")
|
| 45 |
+
|
| 46 |
+
# Cleanup
|
| 47 |
+
shutil.rmtree("fast_align_src")
|
| 48 |
+
|
| 49 |
+
# -------------------------------------------------------------------
|
| 50 |
+
# 2. Download fast_align config files
|
| 51 |
+
# -------------------------------------------------------------------
|
| 52 |
+
|
| 53 |
+
print("Downloading fast_align_config.zip using gdown...")
|
| 54 |
+
gdown.download(
|
| 55 |
+
"https://drive.google.com/uc?id=1OS-qbYLAgLJ2n4cpk9usNdTcNARjNaSr",
|
| 56 |
+
"fast_align_config.zip",
|
| 57 |
+
quiet=False
|
| 58 |
+
)
|
| 59 |
+
|
| 60 |
+
print("Unzipping config...")
|
| 61 |
+
with zipfile.ZipFile("fast_align_config.zip", "r") as z:
|
| 62 |
+
z.extractall(".")
|
| 63 |
+
|
| 64 |
+
os.remove("fast_align_config.zip")
|
| 65 |
+
|
| 66 |
+
# -------------------------------------------------------------------
|
| 67 |
+
# 3. Download Okapi Tikal
|
| 68 |
+
# -------------------------------------------------------------------
|
| 69 |
+
|
| 70 |
+
url = "https://okapiframework.org/binaries/main/1.47.0/okapi-apps_gtk2-linux-x86_64_1.47.0.zip"
|
| 71 |
+
outfile = "okapi-apps_gtk2-linux-x86_64_1.47.0.zip"
|
| 72 |
+
|
| 73 |
+
print("Downloading Okapi Tikal...")
|
| 74 |
+
with requests.get(url, stream=True) as r:
|
| 75 |
+
r.raise_for_status()
|
| 76 |
+
with open(outfile, "wb") as f:
|
| 77 |
+
for chunk in r.iter_content(chunk_size=8192):
|
| 78 |
+
f.write(chunk)
|
| 79 |
+
|
| 80 |
+
print("Unzipping Okapi Tikal...")
|
| 81 |
+
with zipfile.ZipFile(outfile, "r") as z:
|
| 82 |
+
z.extractall("okapi-apps_gtk2-linux-x86_64_1.47.0")
|
| 83 |
+
|
| 84 |
+
os.remove(outfile)
|
| 85 |
+
|
| 86 |
+
# -------------------------------------------------------------------
|
| 87 |
+
# 4. Install PspaCy model
|
| 88 |
+
# -------------------------------------------------------------------
|
| 89 |
+
|
| 90 |
+
print("Downloading spaCy model...")
|
| 91 |
+
run([sys.executable, "-m", "spacy", "download", "xx_ent_wiki_sm"])
|
| 92 |
+
|
| 93 |
+
print("\n All building tasks completed successfully!")
|
| 94 |
+
|
| 95 |
+
|
| 96 |
+
if __name__ == '__main__':
|
| 97 |
+
main()
|