Spaces:
Sleeping
Sleeping
Commit
·
3291d28
1
Parent(s):
917de57
audio record
Browse files- pages/4_Trying Out(Guess the Phrase).py +33 -18
- utils/login.py +0 -5
pages/4_Trying Out(Guess the Phrase).py
CHANGED
|
@@ -3,6 +3,7 @@ from utils.levels import complete_level, render_page, initialize_level
|
|
| 3 |
from utils.login import initialize_login, get_login
|
| 4 |
import requests
|
| 5 |
import os
|
|
|
|
| 6 |
|
| 7 |
|
| 8 |
def check_sentence_similarity(source_sentence, sentence):
|
|
@@ -36,28 +37,42 @@ initialize_level()
|
|
| 36 |
def step_page():
|
| 37 |
st.header("Tryit Out")
|
| 38 |
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
else:
|
| 45 |
audio_file = "assets/sample1.flac"
|
| 46 |
|
| 47 |
-
|
|
|
|
| 48 |
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
|
| 62 |
|
| 63 |
render_page(step_page, LEVEL)
|
|
|
|
| 3 |
from utils.login import initialize_login, get_login
|
| 4 |
import requests
|
| 5 |
import os
|
| 6 |
+
from audio_recorder_streamlit import audio_recorder
|
| 7 |
|
| 8 |
|
| 9 |
def check_sentence_similarity(source_sentence, sentence):
|
|
|
|
| 37 |
def step_page():
|
| 38 |
st.header("Tryit Out")
|
| 39 |
|
| 40 |
+
input_type = st.selectbox("Input Type", ["Upload", "Record", "Sample"], index=2)
|
| 41 |
+
audio_file = None
|
| 42 |
+
if input_type == "Upload":
|
| 43 |
+
uploaded_file = st.file_uploader("Upload a file", type=["wav", "mp3", "flac"])
|
| 44 |
+
if uploaded_file:
|
| 45 |
+
audio_file = os.path.join(
|
| 46 |
+
".sessions", get_login()["username"], "audio.flac"
|
| 47 |
+
)
|
| 48 |
+
with open(audio_file, "wb") as f:
|
| 49 |
+
f.write(uploaded_file.getbuffer())
|
| 50 |
+
elif input_type == "Record":
|
| 51 |
+
audio_bytes = audio_recorder()
|
| 52 |
+
if audio_bytes:
|
| 53 |
+
audio_file = os.path.join(
|
| 54 |
+
".sessions", get_login()["username"], "audio.flac"
|
| 55 |
+
)
|
| 56 |
+
with open(audio_file, "wb") as f:
|
| 57 |
+
f.write(audio_bytes)
|
| 58 |
else:
|
| 59 |
audio_file = "assets/sample1.flac"
|
| 60 |
|
| 61 |
+
if audio_file:
|
| 62 |
+
st.audio(audio_file, format="audio/flac")
|
| 63 |
|
| 64 |
+
transcript = st.text_input("What did you hear?")
|
| 65 |
+
if st.button("Check") and transcript:
|
| 66 |
+
with st.spinner("Checking..."):
|
| 67 |
+
output = get_audio_transcription(audio_file)
|
| 68 |
+
similarity = check_sentence_similarity(output["text"], transcript)
|
| 69 |
+
if similarity > 0.75:
|
| 70 |
+
st.success(
|
| 71 |
+
f"Correct! You are {similarity * 100}% similar to the original sentence."
|
| 72 |
+
)
|
| 73 |
+
else:
|
| 74 |
+
st.error("You are not similar enough to the original sentence.")
|
| 75 |
+
st.info(f"Original sentence: {output['text']}")
|
| 76 |
|
| 77 |
|
| 78 |
render_page(step_page, LEVEL)
|
utils/login.py
CHANGED
|
@@ -15,11 +15,6 @@ def initialize_login():
|
|
| 15 |
|
| 16 |
if st.button("Login"):
|
| 17 |
authorized = authenticate(username, password)
|
| 18 |
-
authorized = {
|
| 19 |
-
"status": True,
|
| 20 |
-
"username": "admin",
|
| 21 |
-
"Name": "Admin",
|
| 22 |
-
}
|
| 23 |
if authorized["status"]:
|
| 24 |
st.session_state["login"] = authorized
|
| 25 |
os.makedirs(
|
|
|
|
| 15 |
|
| 16 |
if st.button("Login"):
|
| 17 |
authorized = authenticate(username, password)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
if authorized["status"]:
|
| 19 |
st.session_state["login"] = authorized
|
| 20 |
os.makedirs(
|