Spaces:
Sleeping
Sleeping
Commit
·
0c00649
1
Parent(s):
8802a4f
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import os
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
MORSE_CODE_DICT = {"0": "-----","1": ".----","2": "..---","3": "...--","4": "....-","5": ".....","6": "-....","7": "--...","8": "---..","9": "----.","A": ".-","B": "-...","C": "-.-.",
|
| 7 |
+
"D": "-..","E": ".","F": "..-.","G": "--.","H": "....","I": "..","J": ".---","K": "-.-","L": ".-..","M": "--","N": "-.","O": "---","P": ".--.","Q": "--.-","R": ".-.",
|
| 8 |
+
"S": "...","T": "-","U": "..-","V": "...-","W": ".--","X": "-..-","Y": "-.--","Z": "--..",".": ".-.-.-",",": "--..--","?": "..--..","!": "-.-.--","-": "-....-","/": "-..-.",
|
| 9 |
+
"@": ".--.-.","(": "-.--.",")": "-.--.-"}
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
def encrypt_to_morse_code(term):
|
| 13 |
+
results = ''.join([MORSE_CODE_DICT.get(i,i) for i in list(term.upper())])
|
| 14 |
+
return results
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
def main():
|
| 18 |
+
st.title("Morse Code Analysis App")
|
| 19 |
+
st.subheader("Hello Streamlit")
|
| 20 |
+
menu = ["Home","About"]
|
| 21 |
+
choice = st.sidebar.selectbox("Menu",menu)
|
| 22 |
+
|
| 23 |
+
if choice == "Home":
|
| 24 |
+
with st.form(key='encryption',clear_on_submit=True):
|
| 25 |
+
raw_text = st.text_area("Enter a text Here")
|
| 26 |
+
submit_button = st.form_submit_button(label="Encrypt")
|
| 27 |
+
|
| 28 |
+
if submit_button:
|
| 29 |
+
col1,col2 =st.columns([2,1])
|
| 30 |
+
|
| 31 |
+
with col1:
|
| 32 |
+
st.info("Morse Code")
|
| 33 |
+
st.write("Original text:{}".format(raw_text))
|
| 34 |
+
results = encrypt_to_morse_code(raw_text)
|
| 35 |
+
st.write(results)
|
| 36 |
+
st.code(results)
|
| 37 |
+
|
| 38 |
+
with col2:
|
| 39 |
+
st.info("Morse Code Audio")
|
| 40 |
+
with st.expander("Play Audio"):
|
| 41 |
+
for i in list(raw_text.upper()):
|
| 42 |
+
audio_file = open(os.path.join('morse_audio_files','{}_morse_code.ogg'.format(i)),'rb')
|
| 43 |
+
audio_bytes = audio_file.read()
|
| 44 |
+
st.write('{}'.format(i))
|
| 45 |
+
st.audio(audio_bytes)
|
| 46 |
+
|
| 47 |
+
else:
|
| 48 |
+
st.subheader("About")
|
| 49 |
+
|
| 50 |
+
if __name__ == '__main__':
|
| 51 |
+
main()
|