File size: 2,026 Bytes
0c00649
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st 
import os



MORSE_CODE_DICT = {"0": "-----","1": ".----","2": "..---","3": "...--","4": "....-","5": ".....","6": "-....","7": "--...","8": "---..","9": "----.","A": ".-","B": "-...","C": "-.-.",
  "D": "-..","E": ".","F": "..-.","G": "--.","H": "....","I": "..","J": ".---","K": "-.-","L": ".-..","M": "--","N": "-.","O": "---","P": ".--.","Q": "--.-","R": ".-.",
  "S": "...","T": "-","U": "..-","V": "...-","W": ".--","X": "-..-","Y": "-.--","Z": "--..",".": ".-.-.-",",": "--..--","?": "..--..","!": "-.-.--","-": "-....-","/": "-..-.",
  "@": ".--.-.","(": "-.--.",")": "-.--.-"}


def encrypt_to_morse_code(term):
    results = ''.join([MORSE_CODE_DICT.get(i,i) for i in list(term.upper())])
    return results


def main():
    st.title("Morse Code Analysis App")
    st.subheader("Hello Streamlit")
    menu = ["Home","About"]
    choice = st.sidebar.selectbox("Menu",menu)

    if choice == "Home":
        with st.form(key='encryption',clear_on_submit=True):
            raw_text = st.text_area("Enter a text Here")
            submit_button = st.form_submit_button(label="Encrypt")

            if submit_button:
                col1,col2 =st.columns([2,1])

                with col1:
                    st.info("Morse Code")
                    st.write("Original text:{}".format(raw_text))
                    results = encrypt_to_morse_code(raw_text)
                    st.write(results)
                    st.code(results)
                
                with col2:
                    st.info("Morse Code Audio")
                    with st.expander("Play Audio"):
                        for i in list(raw_text.upper()):
                            audio_file = open(os.path.join('morse_audio_files','{}_morse_code.ogg'.format(i)),'rb')
                            audio_bytes = audio_file.read()
                            st.write('{}'.format(i))
                            st.audio(audio_bytes)

    else:
        st.subheader("About")

if __name__ == '__main__':
    main()