Spaces:
Running
on
Zero
Running
on
Zero
Commit
·
5e65e89
1
Parent(s):
cd9f86b
- app.py +38 -13
- en_dv_latin.py +5 -4
app.py
CHANGED
@@ -133,7 +133,7 @@ with gr.Blocks(theme=gr.themes.Default(), css=css) as demo:
|
|
133 |
|
134 |
"ޔޫރޮޕާ ލީގު ކާމިޔާބު ކޮށްގެން އަންނަ ސީޒަންގައި ޗެމްޕިއަންސް ލީގު ކުޅެން ލިބުމަކީ، އަހަރެމެންގެ ކްލަބްގެ ބައިވަރު ކަންކަން ބަދަލު ކުރެވިދާނެ ކަމެއް، ކުރިއަށް އޮތް ހޫނު މޫސުމުގެ ޓްރާންސްފާގައި ވެސް،" ޔުނައިޓެޑްގެ ކޯޗު އަމޯރިމް ބުންޏެވެ.
|
135 |
|
136 |
-
"ޔޫރޮޕާ ލީގުން މޮޅުވެގެން އަހަރެމެންގެ މައްސަލަތަކެއް ހައްލެއް ނުވާނެ. މޮޅުވެގެން ލިބޭނީ ޗެމްޕިއަންސް ލީގުގެ ޖާގައަކާއި ހަރަދު ކުރާނެ ފައިސާ. އެކަމަކު އަސްލު މައްސަލަތައް އަދިވެސް ހުރީ. އަހަރެމެންގެ ކޮންސިސްޓެންޓް ވާން ޖެހޭ. ރަނގަޅު ނިންމުންތައް ނިންމައި، ރަނގަޅު ރެކްރޫޓްމަންޓް ސިސްޓަމަކާއި ރަނގަޅު އެކަޑަމީއެއް ބޭނުންވޭ.
|
137 |
|
138 |
އިނގިރޭސި ޕްރިމިއާ ލީގުގެ 14 ވަނައިގައި އޮތް މެންޗެސްޓާ ޔުނައިޓެޑަށް، އަންނަ ސީޒަންގައި ޔޫރަޕްގެ މުބާރާތެއް ކުޅެވެން އޮތް ހަމައެކަނި ގޮތަކ ޔޫރޮޕާ ލީގު ކާމިޔާބު ކުރުމެވެ.
|
139 |
|
@@ -290,16 +290,25 @@ All outputs generated are synthetic, created using fine-tuned models for experim
|
|
290 |
with gr.Tab("Translation Tasks"):
|
291 |
gr.Markdown("# <center>Dhivehi Translation</center>")
|
292 |
gr.Markdown("Select a translation direction and enter text to translate between Dhivehi, English and Latin script.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
293 |
with gr.Row():
|
294 |
instruction = gr.Dropdown(
|
295 |
-
choices=
|
296 |
label="Translation Direction",
|
297 |
-
value=
|
298 |
)
|
299 |
with gr.Row():
|
300 |
input_text = gr.Textbox(lines=2, label="Text to Translate", rtl=True, elem_classes="textbox1")
|
301 |
-
with gr.Row():
|
302 |
-
model_choice = gr.Dropdown(choices=list(MODEL_OPTIONS_TRANSLATE.keys()), value=list(MODEL_OPTIONS_TRANSLATE.keys())[0], label="Model")
|
303 |
with gr.Row():
|
304 |
generated_response = gr.Textbox(label="Translated Text", rtl=True, elem_classes="textbox1")
|
305 |
with gr.Row():
|
@@ -315,21 +324,37 @@ All outputs generated are synthetic, created using fine-tuned models for experim
|
|
315 |
inputs=[instruction, input_text, model_choice,max_tokens_slider, num_beams_slider, rep_penalty_slider, ngram_slider],
|
316 |
outputs=generated_response
|
317 |
)
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
[
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
326 |
)
|
|
|
327 |
gr.Markdown("""\
|
328 |
**Notes:**
|
329 |
- Supports translation between Dhivehi, English and Latin script
|
330 |
- Model trained on news articles and common phrases
|
331 |
- Translation quality may vary based on the domain of the text
|
332 |
""")
|
|
|
333 |
# Launch the app
|
334 |
if __name__ == "__main__":
|
335 |
#demo.launch(server_name="0.0.0.0", server_port=7811)
|
|
|
133 |
|
134 |
"ޔޫރޮޕާ ލީގު ކާމިޔާބު ކޮށްގެން އަންނަ ސީޒަންގައި ޗެމްޕިއަންސް ލީގު ކުޅެން ލިބުމަކީ، އަހަރެމެންގެ ކްލަބްގެ ބައިވަރު ކަންކަން ބަދަލު ކުރެވިދާނެ ކަމެއް، ކުރިއަށް އޮތް ހޫނު މޫސުމުގެ ޓްރާންސްފާގައި ވެސް،" ޔުނައިޓެޑްގެ ކޯޗު އަމޯރިމް ބުންޏެވެ.
|
135 |
|
136 |
+
"ޔޫރޮޕާ ލީގުން މޮޅުވެގެން އަހަރެމެންގެ މައްސަލަތަކެއް ހައްލެއް ނުވާނެ. މޮޅުވެގެން ލިބޭނީ ޗެމްޕިއަންސް ލީގުގެ ޖާގައަކާއި ހަރަދު ކުރާނެ ފައިސާ. އެކަމަކު އަސްލު މައްސަލަތައް އަދިވެސް ހުރީ. އަހަރެމެންގެ ކޮންސިސްޓެންޓް ވާން ޖެހޭ. ރަނގަޅު ނިންމުންތައް ނިންމައި، ރަނގަޅު ރެކްރޫޓްމަންޓް ސިސްޓަމަކާއި ރަނގަޅު އެކަޑަމީއެއް ބޭނުންވޭ. މިއ މި ކުލަބްގެ އަސްލު މަގާމަށް ދިޔުމަށްޓަކައި ހައްލު ކުރަން ޖެހޭ ކަންކަން."
|
137 |
|
138 |
އިނގިރޭސި ޕްރިމިއާ ލީގުގެ 14 ވަނައިގައި އޮތް މެންޗެސްޓާ ޔުނައިޓެޑަށް، އަންނަ ސީޒަންގައި ޔޫރަޕްގެ މުބާރާތެއް ކުޅެވެން އޮތް ހަމައެކަނި ގޮތަކ ޔޫރޮޕާ ލީގު ކާމިޔާބު ކުރުމެވެ.
|
139 |
|
|
|
290 |
with gr.Tab("Translation Tasks"):
|
291 |
gr.Markdown("# <center>Dhivehi Translation</center>")
|
292 |
gr.Markdown("Select a translation direction and enter text to translate between Dhivehi, English and Latin script.")
|
293 |
+
# Set up initial choices and examples based on default model
|
294 |
+
default_model = list(MODEL_OPTIONS_TRANSLATE.keys())[0]
|
295 |
+
if "MT5-B-Dhivehi-English" in default_model:
|
296 |
+
initial_choices = ["2dv", "2en"]
|
297 |
+
initial_value = "2dv"
|
298 |
+
else:
|
299 |
+
initial_choices = ["en2dv:", "dv2en:", "dv2latin:", "latin2dv:"]
|
300 |
+
initial_value = "en2dv:"
|
301 |
+
|
302 |
+
with gr.Row():
|
303 |
+
model_choice = gr.Dropdown(choices=list(MODEL_OPTIONS_TRANSLATE.keys()), value=default_model, label="Model")
|
304 |
with gr.Row():
|
305 |
instruction = gr.Dropdown(
|
306 |
+
choices=initial_choices,
|
307 |
label="Translation Direction",
|
308 |
+
value=initial_value
|
309 |
)
|
310 |
with gr.Row():
|
311 |
input_text = gr.Textbox(lines=2, label="Text to Translate", rtl=True, elem_classes="textbox1")
|
|
|
|
|
312 |
with gr.Row():
|
313 |
generated_response = gr.Textbox(label="Translated Text", rtl=True, elem_classes="textbox1")
|
314 |
with gr.Row():
|
|
|
324 |
inputs=[instruction, input_text, model_choice,max_tokens_slider, num_beams_slider, rep_penalty_slider, ngram_slider],
|
325 |
outputs=generated_response
|
326 |
)
|
327 |
+
|
328 |
+
with gr.Row():
|
329 |
+
gr.Examples(
|
330 |
+
examples=[
|
331 |
+
"ދުނިޔޭގެ އެކި ކަންކޮޅުތަކުން މިލިއަން މީހުން މައްކާއަށް ޖަމާވެފައި",
|
332 |
+
"Concerns over prepayment of GST raised in parliament",
|
333 |
+
"ވައިބާރުވުމުން ކުޅުދުއްފުށީ އެއާޕޯޓަށް ނުޖެއްސިގެން މޯލްޑިވިއަންގެ ބޯޓެއް އެނބުރި މާލެއަށް",
|
334 |
+
"Paakisthaanuge skoolu bahakah dhin hamalaaehgai thin kuhjakaai bodu dhe meehaku maruvehje"
|
335 |
+
],
|
336 |
+
inputs=input_text,
|
337 |
+
)
|
338 |
+
|
339 |
+
def update_choices(model_name):
|
340 |
+
if "MT5-B-Dhivehi-English" in model_name:
|
341 |
+
return gr.update(choices=["2dv", "2en"], value="2dv")
|
342 |
+
else:
|
343 |
+
return gr.update(choices=["en2dv:", "dv2en:", "dv2latin:", "latin2dv:"], value="en2dv:")
|
344 |
+
|
345 |
+
model_choice.change(
|
346 |
+
fn=update_choices,
|
347 |
+
inputs=[model_choice],
|
348 |
+
outputs=[instruction]
|
349 |
)
|
350 |
+
|
351 |
gr.Markdown("""\
|
352 |
**Notes:**
|
353 |
- Supports translation between Dhivehi, English and Latin script
|
354 |
- Model trained on news articles and common phrases
|
355 |
- Translation quality may vary based on the domain of the text
|
356 |
""")
|
357 |
+
|
358 |
# Launch the app
|
359 |
if __name__ == "__main__":
|
360 |
#demo.launch(server_name="0.0.0.0", server_port=7811)
|
en_dv_latin.py
CHANGED
@@ -1,13 +1,14 @@
|
|
1 |
import random
|
2 |
import numpy as np
|
3 |
import torch
|
4 |
-
from transformers import
|
5 |
import spaces
|
6 |
|
7 |
|
8 |
# Available models
|
9 |
MODEL_OPTIONS_TRANSLATE = {
|
10 |
-
"
|
|
|
11 |
}
|
12 |
|
13 |
# Cache for loaded models/tokenizers
|
@@ -16,8 +17,8 @@ MODEL_CACHE = {}
|
|
16 |
def get_model_and_tokenizer(model_dir):
|
17 |
if model_dir not in MODEL_CACHE:
|
18 |
print(f"Loading model: {model_dir}")
|
19 |
-
tokenizer =
|
20 |
-
model =
|
21 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
22 |
print(f"Moving model to device: {device}")
|
23 |
model.to(device)
|
|
|
1 |
import random
|
2 |
import numpy as np
|
3 |
import torch
|
4 |
+
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
5 |
import spaces
|
6 |
|
7 |
|
8 |
# Available models
|
9 |
MODEL_OPTIONS_TRANSLATE = {
|
10 |
+
"Flan-T5-B-Dhivehi-Latin Model": "alakxender/flan-t5-base-dhivehi-en-latin",
|
11 |
+
"MT5-B-Dhivehi-English Model": "alakxender/mt5-base-dv-en",
|
12 |
}
|
13 |
|
14 |
# Cache for loaded models/tokenizers
|
|
|
17 |
def get_model_and_tokenizer(model_dir):
|
18 |
if model_dir not in MODEL_CACHE:
|
19 |
print(f"Loading model: {model_dir}")
|
20 |
+
tokenizer = AutoTokenizer.from_pretrained(model_dir)
|
21 |
+
model = AutoModelForSeq2SeqLM.from_pretrained(model_dir)
|
22 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
23 |
print(f"Moving model to device: {device}")
|
24 |
model.to(device)
|