Spaces:
Running
Running
sahandkh1419
commited on
Commit
β’
b617e78
1
Parent(s):
0dd3575
Update app.py
Browse files
app.py
CHANGED
@@ -72,23 +72,37 @@ def cosine_sim(text1, text2):
|
|
72 |
|
73 |
|
74 |
model = whisper.load_model("base")
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
72 |
|
73 |
|
74 |
model = whisper.load_model("base")
|
75 |
+
|
76 |
+
|
77 |
+
tab1, tab2 = st.tabs(["Take Challenge", "Make Challenge"])
|
78 |
+
|
79 |
+
with tab1:
|
80 |
+
st.write("Listen to music since you have to record 15seconds after that")
|
81 |
+
st.audio("titanic.mp3")
|
82 |
+
|
83 |
+
|
84 |
+
audio_value = st.experimental_audio_input("Sing Rest of music:ποΈ")
|
85 |
+
lyrics = "Far across the distance And spaces between us You have come to show you go on"
|
86 |
+
|
87 |
+
if audio_value:
|
88 |
+
with open("user_sing.mp3", "wb") as f:
|
89 |
+
f.write(audio_value.getbuffer())
|
90 |
+
|
91 |
+
user_lyrics = model.transcribe("user_sing.mp3")["text"]
|
92 |
+
st.write(user_lyrics)
|
93 |
+
similarity_score = cosine_sim(lyrics, user_lyrics)
|
94 |
+
if similarity_score > 0.85:
|
95 |
+
st.success('Awsome! You are doing great', icon="β
")
|
96 |
+
st.markdown('<style>div.stAlert { background-color: rgba(3, 67, 24, 0.9); }</style>', unsafe_allow_html=True)
|
97 |
+
else:
|
98 |
+
st.error('Awful! Try harder next time', icon="π¨")
|
99 |
+
st.markdown('<style>div.stAlert { background-color: rgba(241, 36, 36, 0.9); }</style>', unsafe_allow_html=True)
|
100 |
+
|
101 |
+
|
102 |
+
with tab2:
|
103 |
+
st.write("Upload music to make challenge:")
|
104 |
+
uploaded_file = st.file_uploader("Choose a music file", type=["mp3", "wav"])
|
105 |
+
if uploaded_file is not None:
|
106 |
+
with open("raw_music.mp3", "wb") as f:
|
107 |
+
f.write(uploaded_file.getbuffer())
|
108 |
+
st.audio("raw_music.mp3")
|