Commit
·
b776334
1
Parent(s):
aac72b2
Adding option for random sentences in both all the languages.
Browse files
app.py
CHANGED
@@ -35,20 +35,32 @@ from polish import polish_sentence_to_latin
|
|
35 |
from hungarian import hungarian_sentence_to_latin
|
36 |
from turkish import turkish_sentence_to_latin
|
37 |
|
|
|
|
|
|
|
38 |
import re
|
39 |
from nltk.tokenize import word_tokenize
|
40 |
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
tab1, tab2, tab3= st.tabs(["Polish/Polski", "Hungarian/Magyar", "Turkish/Türkçe"])
|
42 |
|
43 |
with tab1:
|
44 |
st.header("Polish Transliteration")
|
45 |
input_string_polish = st.text_input("Enter a Polish word/sentence to transliterate:")
|
46 |
polish_examples = ['Dziękuję bardzo!', 'Wszystkiego najlepszego!', 'Jarosław, Przemyśl']
|
47 |
-
selected_example_po = st.selectbox('Choose an example as demo', ['None'] + polish_examples)
|
48 |
|
49 |
if selected_example_po != 'None':
|
50 |
input_string_polish = selected_example_po
|
51 |
|
|
|
|
|
|
|
52 |
if st.button("Transliterate Polish"):
|
53 |
if input_string_polish:
|
54 |
output_string = polish_sentence_to_latin(input_string_polish)
|
@@ -61,11 +73,14 @@ with tab2:
|
|
61 |
st.header("Hungarian Transliteration")
|
62 |
input_string_hungarian = st.text_input("Enter a Hungarian word/sentence to transliterate:")
|
63 |
hungarian_examples = ['Köszönöm szépen!', 'Nagyon szépen köszönjük','Budapest, Magyarország']
|
64 |
-
selected_example_hu = st.selectbox('Choose an example as demo', ['None'] + hungarian_examples)
|
65 |
|
66 |
if selected_example_hu != 'None':
|
67 |
input_string_hungarian = selected_example_hu
|
68 |
|
|
|
|
|
|
|
69 |
if st.button("Transliterate Hungarian"):
|
70 |
if input_string_hungarian:
|
71 |
output_string = hungarian_sentence_to_latin(input_string_hungarian)
|
@@ -80,16 +95,18 @@ with tab3:
|
|
80 |
input_string_turkish = st.text_input("Enter a Turkish word/sentence to transliterate:")
|
81 |
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",
|
82 |
"Türkiye'nin güzel şehirlerinden biri olan İstanbul'u ziyaret etmek istiyorum."]
|
83 |
-
selected_example_tu = st.selectbox('Choose an example as demo', ['None'] + turkish_examples)
|
84 |
|
85 |
if selected_example_tu != 'None':
|
86 |
input_string_turkish = selected_example_tu
|
87 |
|
|
|
|
|
|
|
88 |
if st.button("Transliterate Turkish"):
|
89 |
if input_string_turkish:
|
90 |
output_string = turkish_sentence_to_latin(input_string_turkish)
|
91 |
st.subheader("Transliterated Output:")
|
92 |
st.write(output_string)
|
93 |
else:
|
94 |
-
st.warning("Please enter a string.")
|
95 |
-
|
|
|
35 |
from hungarian import hungarian_sentence_to_latin
|
36 |
from turkish import turkish_sentence_to_latin
|
37 |
|
38 |
+
from essential_generators import DocumentGenerator
|
39 |
+
from googletrans import Translator
|
40 |
+
|
41 |
import re
|
42 |
from nltk.tokenize import word_tokenize
|
43 |
|
44 |
+
def random_sentence(lang):
|
45 |
+
translator = Translator()
|
46 |
+
sentence=gen.sentence() #Generates a random but coherent sentence in English
|
47 |
+
return translator.translate(sentence,dest=lang) #Translates the sentence to target language
|
48 |
+
|
49 |
+
|
50 |
tab1, tab2, tab3= st.tabs(["Polish/Polski", "Hungarian/Magyar", "Turkish/Türkçe"])
|
51 |
|
52 |
with tab1:
|
53 |
st.header("Polish Transliteration")
|
54 |
input_string_polish = st.text_input("Enter a Polish word/sentence to transliterate:")
|
55 |
polish_examples = ['Dziękuję bardzo!', 'Wszystkiego najlepszego!', 'Jarosław, Przemyśl']
|
56 |
+
selected_example_po = st.selectbox('Choose an example as demo', ['None', "Generate a random sentence"] + polish_examples)
|
57 |
|
58 |
if selected_example_po != 'None':
|
59 |
input_string_polish = selected_example_po
|
60 |
|
61 |
+
if selected_example_po == "Generate a random sentence" :
|
62 |
+
input_string_polish = random_sentence('pl')
|
63 |
+
|
64 |
if st.button("Transliterate Polish"):
|
65 |
if input_string_polish:
|
66 |
output_string = polish_sentence_to_latin(input_string_polish)
|
|
|
73 |
st.header("Hungarian Transliteration")
|
74 |
input_string_hungarian = st.text_input("Enter a Hungarian word/sentence to transliterate:")
|
75 |
hungarian_examples = ['Köszönöm szépen!', 'Nagyon szépen köszönjük','Budapest, Magyarország']
|
76 |
+
selected_example_hu = st.selectbox('Choose an example as demo', ['None', "Generate a random sentence"] + hungarian_examples)
|
77 |
|
78 |
if selected_example_hu != 'None':
|
79 |
input_string_hungarian = selected_example_hu
|
80 |
|
81 |
+
if selected_example_hu == "Generate a random sentence" :
|
82 |
+
input_string_hungarian = random_sentence('hu')
|
83 |
+
|
84 |
if st.button("Transliterate Hungarian"):
|
85 |
if input_string_hungarian:
|
86 |
output_string = hungarian_sentence_to_latin(input_string_hungarian)
|
|
|
95 |
input_string_turkish = st.text_input("Enter a Turkish word/sentence to transliterate:")
|
96 |
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",
|
97 |
"Türkiye'nin güzel şehirlerinden biri olan İstanbul'u ziyaret etmek istiyorum."]
|
98 |
+
selected_example_tu = st.selectbox('Choose an example as demo', ['None', "Generate a random sentence"] + turkish_examples)
|
99 |
|
100 |
if selected_example_tu != 'None':
|
101 |
input_string_turkish = selected_example_tu
|
102 |
|
103 |
+
if selected_example_tu == "Generate a random sentence" :
|
104 |
+
input_string_turkish = random_sentence('tr')
|
105 |
+
|
106 |
if st.button("Transliterate Turkish"):
|
107 |
if input_string_turkish:
|
108 |
output_string = turkish_sentence_to_latin(input_string_turkish)
|
109 |
st.subheader("Transliterated Output:")
|
110 |
st.write(output_string)
|
111 |
else:
|
112 |
+
st.warning("Please enter a string.")
|
|