File size: 7,064 Bytes
7439772 ae7c243 04c2e43 b3477e4 4bf8bf0 04c2e43 b776334 d3384dd 07b5fef 36e9b92 558d12f 07b5fef b776334 0302af3 b776334 cd7cb7e b776334 3374c1f 172800a ccfc6a3 7439772 ae7c243 bf2aadd ae7c243 b776334 7439772 459afd1 d9ab0a3 7439772 b776334 8e95c41 77fd540 8e95c41 ae7c243 1962c0b b18954f 8e79bf9 1962c0b 8e79bf9 ae7c243 7439772 172800a ae7c243 04c2e43 bf2aadd 04c2e43 b776334 04c2e43 b776334 04c2e43 1962c0b 8e79bf9 1962c0b 8e79bf9 04c2e43 b3477e4 dc9dbb4 3dc47c3 adb1b0c dc9dbb4 edc8b0b dc9dbb4 87438c8 dc9dbb4 b2fcc02 87438c8 b2fcc02 adb1b0c dc9dbb4 b2fcc02 dc9dbb4 b2fcc02 3374c1f de2e266 3374c1f de2e266 3374c1f de2e266 3374c1f de2e266 3374c1f |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
import streamlit as st
from polish import polish_sentence_to_latin
from hungarian import hungarian_sentence_to_latin
from turkish import turkish_sentence_to_latin
from serbo_croatian import serbian_sentence_to_latin
from romanian import romanian_sentence_to_latin
from essential_generators import DocumentGenerator
# from googletrans import Translator
# from googletrans_temp import Translator
import string
import re
from deep_translator import GoogleTranslator
def random_sentence(lang):
gen = DocumentGenerator()
translator = Translator()
sentence=gen.sentence() #Generates a random but coherent sentence in English
return str(translator.translate(sentence,dest=lang).text) #Translates the sentence to target language
tab1, tab2, tab3, tab4, tab5= st.tabs(["Polish/Polski", "Hungarian/Magyar", "Turkish/Türkçe", "Serbo-Croatian-Bosnian", "Romanian"])
# tab1, tab3, tab4= st.tabs(["Polish/Polski", "Turkish/Türkçe", "Serbo-Croatian-Bosnian"])
# tab1, tab2, tab3 = st.tabs(["Polish/Polski", "Hungarian/Magyar", "Turkish/Türkçe"])
with tab1:
st.header("Polish Transliteration")
input_string_polish = st.text_area("Enter a Polish word/sentence to transliterate:")
polish_examples = ['Dziękuję bardzo!', 'Wszystkiego najlepszego!', 'Jarosław, Przemyśl']
selected_example_po = st.selectbox('Choose an example as demo', ['None', "Generate a random sentence"] + polish_examples)
if selected_example_po != 'None':
input_string_polish = selected_example_po
if selected_example_po == "Generate a random sentence" :
input_string_polish = random_sentence('pl')
if st.button("Transliterate Polish"):
if input_string_polish:
output_string = polish_sentence_to_latin(input_string_polish)
st.subheader("Transliterated Output:")
if selected_example_po == "Generate a random sentence" :
# st.write("Polish:"+input_string_polish+'Output:'+output_string)
st.write(input_string_polish)
st.write(output_string)
else:
st.write(output_string)
else:
st.warning("Please enter a string.")
with tab2:
st.header("Hungarian Transliteration")
input_string_hungarian = st.text_area("Enter a Hungarian word/sentence to transliterate:")
hungarian_examples = ['Köszönöm szépen!', 'Nagyon szépen köszönjük','Budapest, Magyarország']
selected_example_hu = st.selectbox('Choose an example as demo', ['None', "Generate a random sentence"] + hungarian_examples)
if selected_example_hu != 'None':
input_string_hungarian = selected_example_hu
if selected_example_hu == "Generate a random sentence" :
input_string_hungarian = random_sentence('hu')
if st.button("Transliterate Hungarian"):
if input_string_hungarian:
output_string = hungarian_sentence_to_latin(input_string_hungarian)
st.subheader("Transliterated Output:")
if selected_example_hu == "Generate a random sentence" :
st.write(input_string_hungarian)
st.write(output_string)
else:
st.write(output_string)
else:
st.warning("Please enter a string.")
with tab3:
st.header("Turkish Transliteration")
input_string_turkish = st.text_area("Enter a Turkish word/sentence to transliterate:")
turkish_examples = ["Müzik, ruhumuzu besler ve duygularımızı ifade etmemize yardımcı olur.", "İhtiyaçlarınıza uygun özel bir çözüm sunabiliriz",
"Türkiye'nin güzel şehirlerinden biri olan İstanbul'u ziyaret etmek istiyorum."]
selected_example_tu = st.selectbox('Choose an example as demo', ['None', "Generate a random sentence"] + turkish_examples)
if selected_example_tu != 'None':
input_string_turkish = selected_example_tu
if selected_example_tu == "Generate a random sentence" :
input_string_turkish = random_sentence('tr')
if st.button("Transliterate Turkish"):
if input_string_turkish:
output_string = turkish_sentence_to_latin(input_string_turkish)
st.subheader("Transliterated Output:")
if selected_example_tu == "Generate a random sentence" :
st.write(input_string_turkish)
st.write(output_string)
else:
st.write(output_string)
else:
st.warning("Please enter a string.")
with tab4:
st.header("Serbo-Croatian-Bosnian Transliteration")
input_string_serbian = st.text_area("Enter a Serbian/Croatian/Bosnian word/sentence in Latin or Cyrillic to transliterate:")
serbian_examples = ["Српски језик је богат ћириличким алфабетом са словима као ш, ж, њ, ч, and ћ.",
"Čini se da hrvatski jezik ima mnogo složenih znakova",
"Bosna je najbolja zemlja na svijetu"]
selected_example_sr = st.selectbox('Choose an example as demo', ['None',"Generate a random sentence"]+serbian_examples)
if selected_example_sr != 'None':
input_string_serbian = selected_example_sr
if selected_example_sr == "Generate a random sentence":
input_string_serbian = random_sentence("sr")
if st.button("Transliterate Serbo-Croatian-Bosnian"):
if input_string_serbian:
output_string = serbian_sentence_to_latin(input_string_serbian)
st.subheader("Transliterated Output:")
if selected_example_sr == "Generate a random sentence" :
st.write(input_string_serbian)
st.write(output_string)
else:
st.write(output_string)
else:
st.warning("Please enter a string.")
with tab5:
st.header("Romanian Tranlisteration")
input_string_romanian = st.text_area("Enter a Romanian word/sentence for transliteration into simple Latin")
romanian_examples = ["România este situată lângă Marea Neagră", "Moldova a folosit grafia chirilică pentru a scrie limba moldovenească",
"Va multumim pentru vizita"]
selected_example_ro = st.selectbox("Choose an example as demo", ['None', "Generate a random sentence"]+romanian_examples)
if selected_example_ro != 'None':
input_string_romanian = selected_example_ro
if selected_example_ro == "Generate a random sentence" :
input_string_romanian = random_sentence('ro')
if st.button("Transliterate Romanian"):
if input_string_romanian:
output_string = romanian_sentence_to_latin(input_string_romanian)
st.subheader("Transliterated Output:")
if selected_example_ro == "Generate a random sentence" :
st.write(input_string_romanian)
st.write(output_string)
else:
st.write(output_string)
else:
st.warning("Please enter a string.")
|