Jobin Thavu Varghese commited on
Commit ·
9cf3bb2
1
Parent(s): ee12ed0
using gemini flash
Browse files- .gitignore +3 -1
- .gradio/certificate.pem +31 -0
- __pycache__/config.cpython-312.pyc +0 -0
- app.py +8 -11
- config.py +17 -0
- requirements.txt +22 -59
- services/__pycache__/interleave.cpython-311.pyc +0 -0
- services/__pycache__/interleave.cpython-312.pyc +0 -0
- services/__pycache__/ocr.cpython-311.pyc +0 -0
- services/__pycache__/ocr.cpython-312.pyc +0 -0
- services/__pycache__/translation.cpython-311.pyc +0 -0
- services/__pycache__/translation.cpython-312.pyc +0 -0
- services/__pycache__/transliteration.cpython-311.pyc +0 -0
- services/__pycache__/transliteration.cpython-312.pyc +0 -0
- services/interleave.py +26 -8
- services/ocr.py +28 -21
- services/translation.py +11 -31
- services/transliteration.py +14 -42
.gitignore
CHANGED
|
@@ -1,2 +1,4 @@
|
|
| 1 |
.venv
|
| 2 |
-
.DS_Store
|
|
|
|
|
|
|
|
|
| 1 |
.venv
|
| 2 |
+
.DS_Store
|
| 3 |
+
services/__pycache__
|
| 4 |
+
.env
|
.gradio/certificate.pem
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
-----BEGIN CERTIFICATE-----
|
| 2 |
+
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
|
| 31 |
+
-----END CERTIFICATE-----
|
__pycache__/config.cpython-312.pyc
ADDED
|
Binary file (792 Bytes). View file
|
|
|
app.py
CHANGED
|
@@ -1,10 +1,9 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from services.ocr import upload_file, ocr, ocr_languages
|
| 3 |
-
from services.interleave import
|
| 4 |
from services.translation import translation_languages, translation
|
| 5 |
-
from services.transliteration import transliterate_languages,
|
| 6 |
|
| 7 |
-
img_path="bmc/qr-code.png"
|
| 8 |
|
| 9 |
html_header = f"""
|
| 10 |
<div style="display:flex; align-items:center; justify-content:space-between;">
|
|
@@ -23,16 +22,15 @@ with gr.Blocks(title="LMX", analytics_enabled=True) as interface:
|
|
| 23 |
gr.HTML(html_header)
|
| 24 |
gr.Button(variant="primary", scale=1, min_width=5, value="☕️ Buy me a coffee", size="lg", link_target="_blank", link="https://buymeacoffee.com/jobvargh")
|
| 25 |
gr.Button(variant="primary", scale=1, min_width=5, value="Github", size="lg", link_target="_blank", link="https://github.com/jobinv12/LMX")
|
| 26 |
-
|
| 27 |
|
| 28 |
with gr.Tab("OCR"):
|
| 29 |
with gr.Row():
|
| 30 |
with gr.Column():
|
| 31 |
-
|
| 32 |
-
ocr_languages = gr.Dropdown(label="Source language", choices=ocr_languages, filterable=True, info="Select source language")
|
| 33 |
ocr_upload_file = gr.UploadButton(label="Upload a Image", file_types=[".png",".jpeg",".webp",".jpg"], file_count="single")
|
| 34 |
ocr_file = gr.Image(height=250, width=700, type="filepath", show_label=False, buttons=[], container=False)
|
| 35 |
-
ocr_upload_file.upload(upload_file, inputs=ocr_upload_file, outputs=[ocr_file,
|
| 36 |
|
| 37 |
with gr.Column():
|
| 38 |
ocr_output = gr.TextArea(label="Output", lines=15 ,interactive=False)
|
|
@@ -41,7 +39,7 @@ with gr.Blocks(title="LMX", analytics_enabled=True) as interface:
|
|
| 41 |
clear_btn = gr.ClearButton(value="Clear", variant="secondary")
|
| 42 |
ocr_submit_btn = gr.Button(value="Run", variant="huggingface")
|
| 43 |
|
| 44 |
-
ocr_submit_btn.click(fn=ocr, inputs=[
|
| 45 |
|
| 46 |
with gr.Tab("Transliteration"):
|
| 47 |
with gr.Row():
|
|
@@ -57,7 +55,7 @@ with gr.Blocks(title="LMX", analytics_enabled=True) as interface:
|
|
| 57 |
clear_btn = gr.ClearButton(value="Clear", variant="secondary")
|
| 58 |
transliteration_submit_btn = gr.Button(value="Run", variant="huggingface")
|
| 59 |
|
| 60 |
-
transliteration_submit_btn.click(fn=
|
| 61 |
|
| 62 |
with gr.Tab("Translation"):
|
| 63 |
with gr.Row():
|
|
@@ -74,7 +72,6 @@ with gr.Blocks(title="LMX", analytics_enabled=True) as interface:
|
|
| 74 |
|
| 75 |
translation_submit_btn.click(fn=translation, inputs=[translation_src_lang, translation_trgt_lang, translation_input_area], outputs=translation_output_area)
|
| 76 |
|
| 77 |
-
|
| 78 |
with gr.Tab("Interleave"):
|
| 79 |
with gr.Row():
|
| 80 |
interleave_input_area = gr.TextArea(label="First Input", type="text")
|
|
@@ -86,7 +83,7 @@ with gr.Blocks(title="LMX", analytics_enabled=True) as interface:
|
|
| 86 |
|
| 87 |
with gr.Row():
|
| 88 |
interleave_output_area = gr.TextArea(label="Output", interactive=False, type="text")
|
| 89 |
-
interleave_submit_btn.click(fn=
|
| 90 |
|
| 91 |
with gr.Row():
|
| 92 |
gr.HTML(html_template=html_footer)
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from services.ocr import upload_file, ocr, ocr_languages
|
| 3 |
+
from services.interleave import interleave_text
|
| 4 |
from services.translation import translation_languages, translation
|
| 5 |
+
from services.transliteration import transliterate_languages, indic_transliteration
|
| 6 |
|
|
|
|
| 7 |
|
| 8 |
html_header = f"""
|
| 9 |
<div style="display:flex; align-items:center; justify-content:space-between;">
|
|
|
|
| 22 |
gr.HTML(html_header)
|
| 23 |
gr.Button(variant="primary", scale=1, min_width=5, value="☕️ Buy me a coffee", size="lg", link_target="_blank", link="https://buymeacoffee.com/jobvargh")
|
| 24 |
gr.Button(variant="primary", scale=1, min_width=5, value="Github", size="lg", link_target="_blank", link="https://github.com/jobinv12/LMX")
|
|
|
|
| 25 |
|
| 26 |
with gr.Tab("OCR"):
|
| 27 |
with gr.Row():
|
| 28 |
with gr.Column():
|
| 29 |
+
ocr_image_url = gr.Textbox(interactive=False, visible=False)
|
| 30 |
+
ocr_languages = gr.Dropdown(label="Source language", choices=ocr_languages, filterable=True, info="Select source language", visible=False)
|
| 31 |
ocr_upload_file = gr.UploadButton(label="Upload a Image", file_types=[".png",".jpeg",".webp",".jpg"], file_count="single")
|
| 32 |
ocr_file = gr.Image(height=250, width=700, type="filepath", show_label=False, buttons=[], container=False)
|
| 33 |
+
ocr_upload_file.upload(upload_file, inputs=ocr_upload_file, outputs=[ocr_file, ocr_image_url])
|
| 34 |
|
| 35 |
with gr.Column():
|
| 36 |
ocr_output = gr.TextArea(label="Output", lines=15 ,interactive=False)
|
|
|
|
| 39 |
clear_btn = gr.ClearButton(value="Clear", variant="secondary")
|
| 40 |
ocr_submit_btn = gr.Button(value="Run", variant="huggingface")
|
| 41 |
|
| 42 |
+
ocr_submit_btn.click(fn=ocr, inputs=[ocr_image_url, ocr_languages], outputs=ocr_output)
|
| 43 |
|
| 44 |
with gr.Tab("Transliteration"):
|
| 45 |
with gr.Row():
|
|
|
|
| 55 |
clear_btn = gr.ClearButton(value="Clear", variant="secondary")
|
| 56 |
transliteration_submit_btn = gr.Button(value="Run", variant="huggingface")
|
| 57 |
|
| 58 |
+
transliteration_submit_btn.click(fn=indic_transliteration, inputs=[transliteration_src_lang, transliteration_trgt_lang, transliteration_input_area], outputs=transliteration_output_area)
|
| 59 |
|
| 60 |
with gr.Tab("Translation"):
|
| 61 |
with gr.Row():
|
|
|
|
| 72 |
|
| 73 |
translation_submit_btn.click(fn=translation, inputs=[translation_src_lang, translation_trgt_lang, translation_input_area], outputs=translation_output_area)
|
| 74 |
|
|
|
|
| 75 |
with gr.Tab("Interleave"):
|
| 76 |
with gr.Row():
|
| 77 |
interleave_input_area = gr.TextArea(label="First Input", type="text")
|
|
|
|
| 83 |
|
| 84 |
with gr.Row():
|
| 85 |
interleave_output_area = gr.TextArea(label="Output", interactive=False, type="text")
|
| 86 |
+
interleave_submit_btn.click(fn=interleave_text, inputs=[interleave_input_area, interleave_input2_area], outputs=[interleave_output_area])
|
| 87 |
|
| 88 |
with gr.Row():
|
| 89 |
gr.HTML(html_template=html_footer)
|
config.py
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from dotenv import load_dotenv
|
| 2 |
+
from langchain_google_genai import ChatGoogleGenerativeAI
|
| 3 |
+
import os
|
| 4 |
+
|
| 5 |
+
load_dotenv()
|
| 6 |
+
|
| 7 |
+
model = ChatGoogleGenerativeAI(
|
| 8 |
+
model = "gemini-2.5-flash",
|
| 9 |
+
temperature = 1.0,
|
| 10 |
+
max_tokens = None,
|
| 11 |
+
timeout = 10,
|
| 12 |
+
max_retries=1
|
| 13 |
+
)
|
| 14 |
+
|
| 15 |
+
HF_BUCKET_NAME = os.environ.get("HF_BUCKET_NAME")
|
| 16 |
+
HF_BUCKET_URL = os.environ.get("HF_BUCKET_URL")
|
| 17 |
+
HF_BUCKET_TOKEN = os.environ.get("HF_BUCKET_TOKEN")
|
requirements.txt
CHANGED
|
@@ -1,28 +1,21 @@
|
|
| 1 |
aiofiles==24.1.0
|
| 2 |
-
aiohappyeyeballs==2.6.1
|
| 3 |
-
aiohttp==3.13.3
|
| 4 |
-
aiosignal==1.4.0
|
| 5 |
-
alabaster==1.0.0
|
| 6 |
annotated-doc==0.0.4
|
| 7 |
annotated-types==0.7.0
|
| 8 |
-
anyio==4.
|
| 9 |
-
attrs==26.1.0
|
| 10 |
-
babel==2.18.0
|
| 11 |
brotli==1.2.0
|
| 12 |
certifi==2026.2.25
|
| 13 |
cffi==2.0.0
|
| 14 |
charset-normalizer==3.4.6
|
| 15 |
click==8.3.1
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
dill==0.4.1
|
| 20 |
-
docutils==0.22.4
|
| 21 |
-
fastapi==0.135.1
|
| 22 |
ffmpy==1.0.0
|
| 23 |
filelock==3.25.2
|
| 24 |
-
|
| 25 |
fsspec==2026.2.0
|
|
|
|
|
|
|
| 26 |
gradio==6.9.0
|
| 27 |
gradio-client==2.3.0
|
| 28 |
groovy==0.1.2
|
|
@@ -30,82 +23,52 @@ h11==0.16.0
|
|
| 30 |
hf-xet==1.4.2
|
| 31 |
httpcore==1.0.9
|
| 32 |
httpx==0.28.1
|
| 33 |
-
huggingface-hub==
|
| 34 |
idna==3.11
|
| 35 |
-
imagesize==2.0.0
|
| 36 |
-
indic-nlp-library-itt==0.1.1
|
| 37 |
-
indictranstoolkit==1.1.1
|
| 38 |
jinja2==3.1.6
|
| 39 |
-
|
| 40 |
-
|
|
|
|
|
|
|
|
|
|
| 41 |
markdown-it-py==4.0.0
|
| 42 |
markupsafe==3.0.3
|
| 43 |
mdurl==0.1.2
|
| 44 |
-
mlx==0.31.1
|
| 45 |
-
mlx-lm==0.31.1
|
| 46 |
-
mlx-vlm==0.4.0
|
| 47 |
-
morfessor==2.0.6
|
| 48 |
-
mpmath==1.3.0
|
| 49 |
-
multidict==6.7.1
|
| 50 |
-
multiprocess==0.70.19
|
| 51 |
-
networkx==3.6.1
|
| 52 |
numpy==2.4.3
|
| 53 |
-
opencv-python==4.13.0.92
|
| 54 |
orjson==3.11.7
|
| 55 |
packaging==26.0
|
| 56 |
pandas==3.0.1
|
| 57 |
pillow==12.1.1
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
protobuf==7.34.0
|
| 61 |
-
pyarrow==23.0.1
|
| 62 |
pycparser==3.0
|
| 63 |
pydantic==2.12.5
|
| 64 |
pydantic-core==2.41.5
|
| 65 |
pydub==0.25.1
|
| 66 |
pygments==2.19.2
|
| 67 |
python-dateutil==2.9.0.post0
|
|
|
|
| 68 |
python-multipart==0.0.22
|
| 69 |
pytz==2026.1.post1
|
| 70 |
pyyaml==6.0.3
|
| 71 |
-
regex==2026.2.28
|
| 72 |
requests==2.32.5
|
|
|
|
| 73 |
rich==14.3.3
|
| 74 |
-
roman-numerals==4.1.0
|
| 75 |
-
sacrebleu==2.6.0
|
| 76 |
-
sacremoses==0.1.1
|
| 77 |
safehttpx==0.1.7
|
| 78 |
-
safetensors==0.7.0
|
| 79 |
semantic-version==2.10.0
|
| 80 |
-
sentencepiece==0.2.1
|
| 81 |
-
setuptools==82.0.1
|
| 82 |
shellingham==1.5.4
|
| 83 |
six==1.17.0
|
| 84 |
-
|
| 85 |
-
soundfile==0.13.1
|
| 86 |
-
sphinx==9.1.0
|
| 87 |
-
sphinx-argparse==0.5.2
|
| 88 |
-
sphinx-rtd-theme==3.1.0
|
| 89 |
-
sphinxcontrib-applehelp==2.0.0
|
| 90 |
-
sphinxcontrib-devhelp==2.0.0
|
| 91 |
-
sphinxcontrib-htmlhelp==2.1.0
|
| 92 |
-
sphinxcontrib-jquery==4.1
|
| 93 |
-
sphinxcontrib-jsmath==1.0.1
|
| 94 |
-
sphinxcontrib-qthelp==2.0.0
|
| 95 |
-
sphinxcontrib-serializinghtml==2.0.0
|
| 96 |
starlette==0.52.1
|
| 97 |
-
|
| 98 |
-
tabulate==0.10.0
|
| 99 |
-
tokenizers==0.21.4
|
| 100 |
tomlkit==0.13.3
|
| 101 |
-
torch==2.10.0
|
| 102 |
-
torchvision==0.25.0
|
| 103 |
tqdm==4.67.3
|
| 104 |
-
transformers==4.53.2
|
| 105 |
typer==0.24.1
|
| 106 |
typing-extensions==4.15.0
|
| 107 |
typing-inspection==0.4.2
|
| 108 |
urllib3==2.6.3
|
|
|
|
| 109 |
uvicorn==0.42.0
|
|
|
|
| 110 |
xxhash==3.6.0
|
| 111 |
-
|
|
|
|
| 1 |
aiofiles==24.1.0
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
annotated-doc==0.0.4
|
| 3 |
annotated-types==0.7.0
|
| 4 |
+
anyio==4.13.0
|
|
|
|
|
|
|
| 5 |
brotli==1.2.0
|
| 6 |
certifi==2026.2.25
|
| 7 |
cffi==2.0.0
|
| 8 |
charset-normalizer==3.4.6
|
| 9 |
click==8.3.1
|
| 10 |
+
cryptography==46.0.5
|
| 11 |
+
distro==1.9.0
|
| 12 |
+
fastapi==0.135.2
|
|
|
|
|
|
|
|
|
|
| 13 |
ffmpy==1.0.0
|
| 14 |
filelock==3.25.2
|
| 15 |
+
filetype==1.2.0
|
| 16 |
fsspec==2026.2.0
|
| 17 |
+
google-auth==2.49.1
|
| 18 |
+
google-genai==1.68.0
|
| 19 |
gradio==6.9.0
|
| 20 |
gradio-client==2.3.0
|
| 21 |
groovy==0.1.2
|
|
|
|
| 23 |
hf-xet==1.4.2
|
| 24 |
httpcore==1.0.9
|
| 25 |
httpx==0.28.1
|
| 26 |
+
huggingface-hub==1.7.2
|
| 27 |
idna==3.11
|
|
|
|
|
|
|
|
|
|
| 28 |
jinja2==3.1.6
|
| 29 |
+
jsonpatch==1.33
|
| 30 |
+
jsonpointer==3.1.1
|
| 31 |
+
langchain-core==1.2.21
|
| 32 |
+
langchain-google-genai==4.2.1
|
| 33 |
+
langsmith==0.7.22
|
| 34 |
markdown-it-py==4.0.0
|
| 35 |
markupsafe==3.0.3
|
| 36 |
mdurl==0.1.2
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
numpy==2.4.3
|
|
|
|
| 38 |
orjson==3.11.7
|
| 39 |
packaging==26.0
|
| 40 |
pandas==3.0.1
|
| 41 |
pillow==12.1.1
|
| 42 |
+
pyasn1==0.6.3
|
| 43 |
+
pyasn1-modules==0.4.2
|
|
|
|
|
|
|
| 44 |
pycparser==3.0
|
| 45 |
pydantic==2.12.5
|
| 46 |
pydantic-core==2.41.5
|
| 47 |
pydub==0.25.1
|
| 48 |
pygments==2.19.2
|
| 49 |
python-dateutil==2.9.0.post0
|
| 50 |
+
python-dotenv==1.2.2
|
| 51 |
python-multipart==0.0.22
|
| 52 |
pytz==2026.1.post1
|
| 53 |
pyyaml==6.0.3
|
|
|
|
| 54 |
requests==2.32.5
|
| 55 |
+
requests-toolbelt==1.0.0
|
| 56 |
rich==14.3.3
|
|
|
|
|
|
|
|
|
|
| 57 |
safehttpx==0.1.7
|
|
|
|
| 58 |
semantic-version==2.10.0
|
|
|
|
|
|
|
| 59 |
shellingham==1.5.4
|
| 60 |
six==1.17.0
|
| 61 |
+
sniffio==1.3.1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
starlette==0.52.1
|
| 63 |
+
tenacity==9.1.4
|
|
|
|
|
|
|
| 64 |
tomlkit==0.13.3
|
|
|
|
|
|
|
| 65 |
tqdm==4.67.3
|
|
|
|
| 66 |
typer==0.24.1
|
| 67 |
typing-extensions==4.15.0
|
| 68 |
typing-inspection==0.4.2
|
| 69 |
urllib3==2.6.3
|
| 70 |
+
uuid-utils==0.14.1
|
| 71 |
uvicorn==0.42.0
|
| 72 |
+
websockets==16.0
|
| 73 |
xxhash==3.6.0
|
| 74 |
+
zstandard==0.25.0
|
services/__pycache__/interleave.cpython-311.pyc
DELETED
|
Binary file (1.59 kB)
|
|
|
services/__pycache__/interleave.cpython-312.pyc
CHANGED
|
Binary files a/services/__pycache__/interleave.cpython-312.pyc and b/services/__pycache__/interleave.cpython-312.pyc differ
|
|
|
services/__pycache__/ocr.cpython-311.pyc
DELETED
|
Binary file (3.52 kB)
|
|
|
services/__pycache__/ocr.cpython-312.pyc
CHANGED
|
Binary files a/services/__pycache__/ocr.cpython-312.pyc and b/services/__pycache__/ocr.cpython-312.pyc differ
|
|
|
services/__pycache__/translation.cpython-311.pyc
DELETED
|
Binary file (378 Bytes)
|
|
|
services/__pycache__/translation.cpython-312.pyc
CHANGED
|
Binary files a/services/__pycache__/translation.cpython-312.pyc and b/services/__pycache__/translation.cpython-312.pyc differ
|
|
|
services/__pycache__/transliteration.cpython-311.pyc
DELETED
|
Binary file (1.32 kB)
|
|
|
services/__pycache__/transliteration.cpython-312.pyc
CHANGED
|
Binary files a/services/__pycache__/transliteration.cpython-312.pyc and b/services/__pycache__/transliteration.cpython-312.pyc differ
|
|
|
services/interleave.py
CHANGED
|
@@ -1,11 +1,29 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
]
|
| 8 |
|
| 9 |
-
|
| 10 |
|
| 11 |
-
return
|
|
|
|
| 1 |
+
from config import model
|
| 2 |
+
|
| 3 |
+
# def interleave_text(first_input_text:str, second_input_text:str) -> str:
|
| 4 |
+
# first_input = [
|
| 5 |
+
# line.strip() for line in first_input_text.splitlines() if line.strip()
|
| 6 |
+
# ]
|
| 7 |
+
# second_input = [
|
| 8 |
+
# line.strip() for line in second_input_text.splitlines() if line.strip()
|
| 9 |
+
# ]
|
| 10 |
+
|
| 11 |
+
# result = "\n\n".join(f"{x}\n{y}" for x, y in zip(first_input, second_input))
|
| 12 |
+
|
| 13 |
+
# return result
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
def interleave_text(first_input_text:str, second_input_text:str) -> str:
|
| 17 |
+
|
| 18 |
+
messages = [
|
| 19 |
+
(
|
| 20 |
+
"system", "You are a helpful assistant that interleave text between to inputs. Interleave the user inputs."
|
| 21 |
+
),
|
| 22 |
+
(
|
| 23 |
+
"human", f"{first_input_text} {second_input_text}"
|
| 24 |
+
)
|
| 25 |
]
|
| 26 |
|
| 27 |
+
response = model.invoke(messages)
|
| 28 |
|
| 29 |
+
return response.content
|
services/ocr.py
CHANGED
|
@@ -1,10 +1,9 @@
|
|
| 1 |
import os
|
| 2 |
from datetime import datetime
|
| 3 |
import shutil
|
| 4 |
-
|
| 5 |
-
from
|
| 6 |
-
from
|
| 7 |
-
from mlx_vlm.utils import load_config
|
| 8 |
|
| 9 |
ocr_languages = [
|
| 10 |
"English", "Afrikaans", "Amharic", "Arabic", "Assamese", "Azerbaijani",
|
|
@@ -34,16 +33,6 @@ ocr_languages = [
|
|
| 34 |
"Vietnamese", "Yiddish", "Yoruba"
|
| 35 |
]
|
| 36 |
|
| 37 |
-
model_id = "mlx-community/olmOCR-2-7B-1025-8bit"
|
| 38 |
-
|
| 39 |
-
try:
|
| 40 |
-
# Load the model
|
| 41 |
-
model, processor = load(model_id, trust_remote_code=True)
|
| 42 |
-
config = load_config(model_id)
|
| 43 |
-
print("olmocr2 model loaded successfully")
|
| 44 |
-
except Exception as e:
|
| 45 |
-
print(f"Failed to load deepseekocr2 model {e}")
|
| 46 |
-
|
| 47 |
def upload_file(file):
|
| 48 |
|
| 49 |
if file is None:
|
|
@@ -61,14 +50,32 @@ def upload_file(file):
|
|
| 61 |
|
| 62 |
shutil.copy(file, dest_path)
|
| 63 |
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
|
| 68 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
|
| 70 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
|
| 72 |
-
|
| 73 |
|
| 74 |
-
return
|
|
|
|
| 1 |
import os
|
| 2 |
from datetime import datetime
|
| 3 |
import shutil
|
| 4 |
+
from huggingface_hub import batch_bucket_files
|
| 5 |
+
from langchain_core.messages import HumanMessage
|
| 6 |
+
from config import model, HF_BUCKET_NAME, HF_BUCKET_URL, HF_BUCKET_TOKEN
|
|
|
|
| 7 |
|
| 8 |
ocr_languages = [
|
| 9 |
"English", "Afrikaans", "Amharic", "Arabic", "Assamese", "Azerbaijani",
|
|
|
|
| 33 |
"Vietnamese", "Yiddish", "Yoruba"
|
| 34 |
]
|
| 35 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
def upload_file(file):
|
| 37 |
|
| 38 |
if file is None:
|
|
|
|
| 50 |
|
| 51 |
shutil.copy(file, dest_path)
|
| 52 |
|
| 53 |
+
store_file = batch_bucket_files(
|
| 54 |
+
bucket_id=HF_BUCKET_NAME,
|
| 55 |
+
add=[
|
| 56 |
+
(dest_path, new_filename)
|
| 57 |
+
],
|
| 58 |
+
token=HF_BUCKET_TOKEN
|
| 59 |
+
)
|
| 60 |
|
| 61 |
+
file_url = f"{HF_BUCKET_URL}/{new_filename}"
|
| 62 |
+
|
| 63 |
+
return dest_path, file_url
|
| 64 |
+
|
| 65 |
+
def ocr(image_url:str, language:str) -> str:
|
| 66 |
|
| 67 |
+
messages = [
|
| 68 |
+
HumanMessage(
|
| 69 |
+
content=[
|
| 70 |
+
{"type": "text", "text": "Extract the content of this document into well-formatted markdown. No Intro. Extract the user file. "},
|
| 71 |
+
{
|
| 72 |
+
"type": "image_url",
|
| 73 |
+
"image_url": image_url
|
| 74 |
+
}
|
| 75 |
+
]
|
| 76 |
+
)
|
| 77 |
+
]
|
| 78 |
|
| 79 |
+
response = model.invoke(messages)
|
| 80 |
|
| 81 |
+
return response.content
|
services/translation.py
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
-
import
|
| 2 |
-
|
| 3 |
|
| 4 |
translation_languages: list = ['English', 'Abkhaz', 'Acehnese', 'Acholi',
|
| 5 |
'Afar', 'Afrikaans', 'Albanian', 'Alur',
|
|
@@ -310,14 +310,6 @@ languages_iso_codes: dict = {
|
|
| 310 |
"Zulu": "zu"
|
| 311 |
}
|
| 312 |
|
| 313 |
-
model_id = "google/translategemma-4b-it"
|
| 314 |
-
|
| 315 |
-
try:
|
| 316 |
-
processor = AutoProcessor.from_pretrained(model_id)
|
| 317 |
-
model = AutoModelForImageTextToText.from_pretrained(model_id, device_map="auto")
|
| 318 |
-
print("Translation model loaded successfully")
|
| 319 |
-
except Exception as e:
|
| 320 |
-
print(f"Failed to load translation model {e}")
|
| 321 |
|
| 322 |
def translation(src_lang:str, trgt_lang:str, text:str) -> str:
|
| 323 |
|
|
@@ -325,28 +317,16 @@ def translation(src_lang:str, trgt_lang:str, text:str) -> str:
|
|
| 325 |
trgt_lang_iso = languages_iso_codes[trgt_lang]
|
| 326 |
|
| 327 |
messages = [
|
| 328 |
-
|
| 329 |
-
"
|
| 330 |
-
|
| 331 |
-
|
| 332 |
-
|
| 333 |
-
|
| 334 |
-
"target_lang_code": trgt_lang_iso,
|
| 335 |
-
"text": text,
|
| 336 |
-
}
|
| 337 |
-
],
|
| 338 |
-
}
|
| 339 |
]
|
| 340 |
|
| 341 |
-
|
| 342 |
-
messages, tokenize=True, add_generation_prompt=True, return_dict=True, return_tensors="pt"
|
| 343 |
-
).to(model.device, dtype=torch.bfloat16)
|
| 344 |
-
input_len = len(inputs['input_ids'][0])
|
| 345 |
-
|
| 346 |
-
with torch.inference_mode():
|
| 347 |
-
generation = model.generate(**inputs, do_sample=False, max_new_tokens=2000)
|
| 348 |
|
| 349 |
-
|
| 350 |
-
decoded = processor.decode(generation, skip_special_tokens=True)
|
| 351 |
|
| 352 |
-
|
|
|
|
| 1 |
+
from config import model
|
| 2 |
+
|
| 3 |
|
| 4 |
translation_languages: list = ['English', 'Abkhaz', 'Acehnese', 'Acholi',
|
| 5 |
'Afar', 'Afrikaans', 'Albanian', 'Alur',
|
|
|
|
| 310 |
"Zulu": "zu"
|
| 311 |
}
|
| 312 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 313 |
|
| 314 |
def translation(src_lang:str, trgt_lang:str, text:str) -> str:
|
| 315 |
|
|
|
|
| 317 |
trgt_lang_iso = languages_iso_codes[trgt_lang]
|
| 318 |
|
| 319 |
messages = [
|
| 320 |
+
(
|
| 321 |
+
"system", f"You are a helpful assistant that translates {src_lang_iso} to {trgt_lang_iso}. Translate the user sentence."
|
| 322 |
+
),
|
| 323 |
+
(
|
| 324 |
+
"human", f"{text}"
|
| 325 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 326 |
]
|
| 327 |
|
| 328 |
+
response = model.invoke(messages)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 329 |
|
| 330 |
+
return response.content
|
|
|
|
| 331 |
|
| 332 |
+
|
services/transliteration.py
CHANGED
|
@@ -1,9 +1,4 @@
|
|
| 1 |
-
import
|
| 2 |
-
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
|
| 3 |
-
from IndicTransToolkit.processor import IndicProcessor
|
| 4 |
-
|
| 5 |
-
DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
|
| 6 |
-
|
| 7 |
|
| 8 |
transliterate_languages: list = [
|
| 9 |
"English",
|
|
@@ -63,43 +58,20 @@ transliteration_iso_codes: dict = {
|
|
| 63 |
"Urdu": "urd_Arab"
|
| 64 |
}
|
| 65 |
|
| 66 |
-
def indic_transliteration(
|
| 67 |
-
|
| 68 |
-
model_id = model_name
|
| 69 |
-
try:
|
| 70 |
-
tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True)
|
| 71 |
-
model = AutoModelForSeq2SeqLM.from_pretrained(model_id,trust_remote_code=True,torch_dtype=torch.bfloat16).to(DEVICE)
|
| 72 |
-
print(f"{model_id} model loaded sucessfully.")
|
| 73 |
-
except Exception as e:
|
| 74 |
-
print(f"Failed to load {model_id} model.")
|
| 75 |
-
|
| 76 |
-
ip = IndicProcessor(inference=True)
|
| 77 |
-
|
| 78 |
-
batch = ip.preprocess_batch(
|
| 79 |
-
[text],
|
| 80 |
-
src_lang=src_lang,
|
| 81 |
-
tgt_lang=trgt_lang
|
| 82 |
-
)
|
| 83 |
-
|
| 84 |
-
inputs = tokenizer(batch, truncation=True, padding="longest", return_tensors="pt", return_attention_mask=True).to(DEVICE)
|
| 85 |
-
|
| 86 |
-
with torch.no_grad():
|
| 87 |
-
generated_tokens = model.generate(**inputs, use_cache=True, min_length=0, max_length=2048, num_beams=5, num_return_sequences=1)
|
| 88 |
-
|
| 89 |
-
generated_tokens = tokenizer.batch_decode(generated_tokens, skip_special_tokens=True, clean_up_tokenization_spaces=True)
|
| 90 |
-
|
| 91 |
-
translations = ip.postprocess_batch(generated_tokens, lang=trgt_lang)
|
| 92 |
|
| 93 |
-
|
|
|
|
| 94 |
|
| 95 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
|
| 97 |
-
|
| 98 |
-
trgt_lang_iso:str = transliteration_iso_codes.get(trgt_lang)
|
| 99 |
|
| 100 |
-
|
| 101 |
-
return indic_transliteration("ai4bharat/indictrans2-en-indic-1B", src_lang_iso, trgt_lang_iso, text)
|
| 102 |
-
elif "eng_Latn" not in src_lang_iso and "eng_Latn" in trgt_lang_iso:
|
| 103 |
-
return indic_transliteration("ai4bharat/indictrans2-indic-en-1B", src_lang_iso, trgt_lang_iso, text)
|
| 104 |
-
else:
|
| 105 |
-
return indic_transliteration("ai4bharat/indictrans2-indic-indic-1B", src_lang_iso, trgt_lang_iso, text)
|
|
|
|
| 1 |
+
from config import model
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
transliterate_languages: list = [
|
| 4 |
"English",
|
|
|
|
| 58 |
"Urdu": "urd_Arab"
|
| 59 |
}
|
| 60 |
|
| 61 |
+
def indic_transliteration(src_lang:str, trgt_lang:str, text:str) -> str:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
|
| 63 |
+
src_lang_iso = transliteration_iso_codes[src_lang]
|
| 64 |
+
trgt_lang_iso = transliteration_iso_codes[trgt_lang]
|
| 65 |
|
| 66 |
+
messages = [
|
| 67 |
+
(
|
| 68 |
+
"system", f"You are a helpful assistant that transliterates {src_lang_iso} to {trgt_lang_iso}. Transliterate the user sentence."
|
| 69 |
+
),
|
| 70 |
+
(
|
| 71 |
+
"human", f"{text}"
|
| 72 |
+
)
|
| 73 |
+
]
|
| 74 |
|
| 75 |
+
response = model.invoke(messages)
|
|
|
|
| 76 |
|
| 77 |
+
return response.content
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|