TSjB commited on
Commit
a90d6e8
·
verified ·
1 Parent(s): 1000145

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -15
app.py CHANGED
@@ -12,6 +12,7 @@ DATA_PATH = "TSjB/dictionary_krc_rus"
12
  # LANGUAGE = pd.DataFrame({"language": ["Къарачай-Малкъар тил", "Русский язык", "English", "Türk dili"], "token": ["krc_Cyrl", "rus_Cyrl", "eng_Latn", "tur_Latn"]})
13
  LANGUAGE = pd.DataFrame({"language": ["Къарачай-Малкъар тил", "Русский язык"], "token": ["krc_Cyrl", "rus_Cyrl"]})
14
  DIALECT = pd.DataFrame({"dialect": ["дж\ч", "ж\ч", "з\ц"], "short_name": ["qrc", "hlm", "mqr"]})
 
15
 
16
  SYSTEM_LANG = "rus"
17
  # NAMES = pd.DataFrame({
@@ -22,11 +23,11 @@ SYSTEM_LANG = "rus"
22
  # "eng": ["# Qarachay-Malqar translator", "from", "to", "Write here...", "Translated text is here", "Qarachay-Malqar dialect", "Translate", "The first translator. Created by [Bogdan Tewunalany](https://t.me/bogdan_tewunalany), [Ali Berberov](https://t.me/ali_berberov)\n\nSince the model was trained in pairs of Russian and Qarachay-Malqar, the Qarachay-Malqar translation for other languages may be worse."]
23
  # })
24
  NAMES = pd.DataFrame({
25
- "id": ["title", "from", "to", "your_sent", "transl_sent", "dialect", "translate", "annotation"],
26
- "krc": ["# Къарачай-Малкъар сёзлюк бла кёчюрюўчю", "тилден", "тилге", "Мында джаз...", "Кёчюрюлгени", "Къарачай-Малкъарны диалекти", "Кёчюр","Къарачай-малкъар, орус тиллени арасында биринчи кёчюрюўчюдю. Сёзлюк да ичине салыннганды.\n\n[Богдан Теўуналаны](https://t.me/bogdan_tewunalany), [Али Берберлени](https://t.me/ali_berberov) къурагъандыла\n\nСоинвестированиени эмда спонсорлукъ болушлукъну юсюнден [Али Берберовгъа](https://t.me/ali_berberov) соругъуз"],
27
- "rus": ["# Карачаево-балкарский словарь и переводчик", "из", "на", "Напишите здесь...", "Переведённый текст", "Карачаево-балкарский диалект", "Перевести","Первый переводчик между карачаево-балкарским и русским языками. Также встроен словарь для отдельных слов или коротких фраз.\n\nРазработчики: [Богдан Теунаев](https://t.me/bogdan_tewunalany), [Али Берберов](https://t.me/ali_berberov)\n\nПо вопросам соинвестирования и спонсорской поддержки обращайтесь к [Али Берберову](https://t.me/ali_berberov)"],
28
- "tur": ["# Karaçayca-Balkarca sözlük ve çevirmen", "dilden", "dile", "Buraya yaz...", "Çevrilmiş metin burada", "Karaçay-Malkar lehçesi", "Tercüme edin", "Karaçay-Balkarca ve Rusça dilleri arasındaki ilk çevirmen. Tek tek kelimeler veya kısa ifadeler için bir sözlük de yerleşiktir.\n\nGeliştiriciler: [Bogdan Tewunalanı](https://t.me/bogdan_tewunalany), [Ali Berberov](https://t.me/ali_berberov)\n\nOrtak yatırım ve sponsorluk ile ilgili sorularınız için [Ali Berberov](https://t.me/ali_berberov) ile iletişime geçin"],
29
- "eng": ["# Qarachay-Malqar dictionary and translator", "from", "to", "Write here...", "Translated text is here", "Qarachay-Malqar dialect", "Translate", "The first translator between Qarachay-Malqar and Russian languages. A dictionary for individual words or short phrases is also built in.\n\nDevelopers: [Bogdan Tewunalany](https://t.me/bogdan_tewunalany), [Ali Berberov](https://t.me/ali_berberov)\n\nFor co-investment and sponsorship, please contact [Ali Berberov] (https://t.me/ali_berberov)"]
30
  })
31
 
32
 
@@ -420,28 +421,38 @@ def dictionaryDisp(from_, text):
420
 
421
 
422
  # 8. Output function
423
- def out(text, from_, to, dialect):
 
 
424
  if dialect == "" or dialect is None:
425
  dialect = "дж\ч"
426
  if from_ == "" or from_ is None:
427
  from_ = "Русский язык"
428
  if to == "" or to is None:
429
  to = "Къарачай-Малкъар тил"
 
 
 
430
 
431
  from_ = "".join(LANGUAGE[LANGUAGE.language == from_].token.to_list())
432
  to = "".join(LANGUAGE[LANGUAGE.language == to].token.to_list())
433
  dialect = "".join(DIALECT[DIALECT.dialect == dialect].short_name.to_list())
 
434
 
435
- str_ = dictionaryDisp(from_, text)
436
-
437
- if(len(str_) == 0):
 
 
 
438
  str_ = translateProcess(text, from_, to, dialect)
439
- # str_ = "myaf"
440
 
441
  return(str_)
442
 
443
  # 9. Definition ui
444
  _title = "".join(NAMES[NAMES.id == "title"][SYSTEM_LANG].to_list())
 
445
  _from = "".join(NAMES[NAMES.id == "from"][SYSTEM_LANG].to_list())
446
  _to = "".join(NAMES[NAMES.id == "to"][SYSTEM_LANG].to_list())
447
  _your_sent = "".join(NAMES[NAMES.id == "your_sent"][SYSTEM_LANG].to_list())
@@ -453,10 +464,17 @@ _annotation = "".join(NAMES[NAMES.id == "annotation"][SYSTEM_LANG].to_list())
453
  with gr.Blocks() as demo:
454
  gr.Markdown(_title)
455
  with gr.Row():
456
- choice_input = gr.Dropdown(
457
- # choices = LANGUAGE.language.to_list(), label=_from, value = "Русский язык", filterable = False)
458
- choices = LANGUAGE.language.to_list(), label=_from, value = "Русский язык")
459
-
 
 
 
 
 
 
 
460
  with gr.Column():
461
  with gr.Row():
462
  choice_output = gr.Dropdown(
@@ -474,11 +492,12 @@ with gr.Blocks() as demo:
474
 
475
  text_button = gr.Button(_translate, variant = 'primary')
476
 
477
- text_button.click(out, inputs=[text_input, choice_input, choice_output, dialect], outputs=[text_output]) # text, from, to, dialect
478
 
479
  gr.Markdown(_annotation)
480
 
481
  # 10. Launch
 
482
  demo.launch()
483
 
484
 
 
12
  # LANGUAGE = pd.DataFrame({"language": ["Къарачай-Малкъар тил", "Русский язык", "English", "Türk dili"], "token": ["krc_Cyrl", "rus_Cyrl", "eng_Latn", "tur_Latn"]})
13
  LANGUAGE = pd.DataFrame({"language": ["Къарачай-Малкъар тил", "Русский язык"], "token": ["krc_Cyrl", "rus_Cyrl"]})
14
  DIALECT = pd.DataFrame({"dialect": ["дж\ч", "ж\ч", "з\ц"], "short_name": ["qrc", "hlm", "mqr"]})
15
+ TYPE = pd.DataFrame({"krc": ["Кёчюрюўчю", "Сёзлюк"], "rus": ["Переводчик", "Словарь"], "eng": ["Translator", "Dictionary"], "tur": ["Çevirmen", "Sözlük."], "short_name": ["translator", "dictionary"]})
16
 
17
  SYSTEM_LANG = "rus"
18
  # NAMES = pd.DataFrame({
 
23
  # "eng": ["# Qarachay-Malqar translator", "from", "to", "Write here...", "Translated text is here", "Qarachay-Malqar dialect", "Translate", "The first translator. Created by [Bogdan Tewunalany](https://t.me/bogdan_tewunalany), [Ali Berberov](https://t.me/ali_berberov)\n\nSince the model was trained in pairs of Russian and Qarachay-Malqar, the Qarachay-Malqar translation for other languages may be worse."]
24
  # })
25
  NAMES = pd.DataFrame({
26
+ "id": ["title", "type", "from", "to", "your_sent", "transl_sent", "dialect", "translate", "annotation", "word_absence"],
27
+ "krc": ["# Къарачай-Малкъар сёзлюк бла кёчюрюўчю", "Тюрлюсю", "тилден", "тилге", "Мында джаз...", "Кёчюрюлгени", "Къарачай-Малкъарны диалекти", "Кёчюр","Къарачай-малкъар, орус тиллени арасында биринчи кёчюрюўчюдю. Сёзлюк да ичине салыннганды.\n\n[Богдан Теўуналаны](https://t.me/bogdan_tewunalany), [Али Берберлени](https://t.me/ali_berberov) къурагъандыла\n\nСоинвестированиени эмда спонсорлукъ болушлукъну юсюнден [Али Берберовгъа](https://t.me/ali_berberov) соругъуз", "Сорулгъаны сёзлюкде табылмагъанды."],
28
+ "rus": ["# Карачаево-балкарский словарь и переводчик", "Тип", "из", "на", "Напишите здесь...", "Переведённый текст", "Карачаево-балкарский диалект", "Перевести","Первый переводчик между карачаево-балкарским и русским языками. Также встроен словарь для отдельных слов или коротких фраз.\n\nРазработчики: [Богдан Теунаев](https://t.me/bogdan_tewunalany), [Али Берберов](https://t.me/ali_berberov)\n\nПо вопросам соинвестирования и спонсорской поддержки обращайтесь к [Али Берберову](https://t.me/ali_berberov)", "Запрашиваемое в словаре не найдено."],
29
+ "tur": ["# Karaçayca-Balkarca sözlük ve çevirmen", "Tür", "dilden", "dile", "Buraya yaz...", "Çevrilmiş metin burada", "Karaçay-Malkar lehçesi", "Tercüme edin", "Karaçay-Balkarca ve Rusça dilleri arasındaki ilk çevirmen. Tek tek kelimeler veya kısa ifadeler için bir sözlük de yerleşiktir.\n\nGeliştiriciler: [Bogdan Tewunalanı](https://t.me/bogdan_tewunalany), [Ali Berberov](https://t.me/ali_berberov)\n\nOrtak yatırım ve sponsorluk ile ilgili sorularınız için [Ali Berberov](https://t.me/ali_berberov) ile iletişime geçin", "Sorge sözlükte bulunmuyor."],
30
+ "eng": ["# Qarachay-Malqar dictionary and translator", "Type", "from", "to", "Write here...", "Translated text is here", "Qarachay-Malqar dialect", "Translate", "The first translator between Qarachay-Malqar and Russian languages. A dictionary for individual words or short phrases is also built in.\n\nDevelopers: [Bogdan Tewunalany](https://t.me/bogdan_tewunalany), [Ali Berberov](https://t.me/ali_berberov)\n\nFor co-investment and sponsorship, please contact [Ali Berberov] (https://t.me/ali_berberov)", "The requested was not found in the dictionary."]
31
  })
32
 
33
 
 
421
 
422
 
423
  # 8. Output function
424
+ def out(text, from_, to, dialect, type_):
425
+ type_col = SYSTEM_LANG
426
+
427
  if dialect == "" or dialect is None:
428
  dialect = "дж\ч"
429
  if from_ == "" or from_ is None:
430
  from_ = "Русский язык"
431
  if to == "" or to is None:
432
  to = "Къарачай-Малкъар тил"
433
+ if type_ == "" or type_ is None:
434
+ type_ = "Кёчюрюўчю"
435
+ type_col = "krc"
436
 
437
  from_ = "".join(LANGUAGE[LANGUAGE.language == from_].token.to_list())
438
  to = "".join(LANGUAGE[LANGUAGE.language == to].token.to_list())
439
  dialect = "".join(DIALECT[DIALECT.dialect == dialect].short_name.to_list())
440
+ type_ = "".join(TYPE[TYPE[type_col] == type_].short_name.to_list())
441
 
442
+
443
+ if type_ == "dictionary":
444
+ str_ = dictionaryDisp(from_, text)
445
+ if(len(str_) == 0):
446
+ str_ = NAMES[NAMES.id == "word_absence"][SYSTEM_LANG].values[0]
447
+ elif type_ == "translator":
448
  str_ = translateProcess(text, from_, to, dialect)
449
+ # str_ = "myaf"
450
 
451
  return(str_)
452
 
453
  # 9. Definition ui
454
  _title = "".join(NAMES[NAMES.id == "title"][SYSTEM_LANG].to_list())
455
+ _type = "".join(NAMES[NAMES.id == "type"][SYSTEM_LANG].to_list())
456
  _from = "".join(NAMES[NAMES.id == "from"][SYSTEM_LANG].to_list())
457
  _to = "".join(NAMES[NAMES.id == "to"][SYSTEM_LANG].to_list())
458
  _your_sent = "".join(NAMES[NAMES.id == "your_sent"][SYSTEM_LANG].to_list())
 
464
  with gr.Blocks() as demo:
465
  gr.Markdown(_title)
466
  with gr.Row():
467
+
468
+ with gr.Column():
469
+ with gr.Row():
470
+ choice_type = gr.Dropdown(
471
+ choices = TYPE[SYSTEM_LANG].to_list(), label=_type, value = TYPE[SYSTEM_LANG][0])
472
+
473
+ choice_input = gr.Dropdown(
474
+ choices = LANGUAGE.language.to_list(), label=_from, value = "Русский язык")
475
+
476
+
477
+
478
  with gr.Column():
479
  with gr.Row():
480
  choice_output = gr.Dropdown(
 
492
 
493
  text_button = gr.Button(_translate, variant = 'primary')
494
 
495
+ text_button.click(out, inputs=[text_input, choice_input, choice_output, dialect, choice_type], outputs=[text_output]) # text, from, to, dialect
496
 
497
  gr.Markdown(_annotation)
498
 
499
  # 10. Launch
500
+ # demo.launch(inbrowser=True)
501
  demo.launch()
502
 
503