Spaces:
Running
Running
sahandkh1419
commited on
Commit
β’
2306856
1
Parent(s):
c5afedf
Update app.py
Browse files
app.py
CHANGED
@@ -100,6 +100,26 @@ with tab1:
|
|
100 |
st.markdown('<style>div.stAlert { background-color: rgba(241, 36, 36, 0.9); }</style>', unsafe_allow_html=True)
|
101 |
|
102 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
103 |
with tab2:
|
104 |
st.write("Upload music to make challenge:")
|
105 |
uploaded_file = st.file_uploader("Choose a music file", type=["mp3", "wav"])
|
@@ -118,11 +138,12 @@ with tab2:
|
|
118 |
trimmed_audio = audio[start_time * 1000:end_time * 1000]
|
119 |
trimmed_audio.export("trimmed_music.mp3", format="mp3")
|
120 |
st.write("Now type what user should sing:")
|
121 |
-
|
122 |
-
|
123 |
else:
|
124 |
-
st.
|
|
|
125 |
else:
|
126 |
st.write("Now type what user should sing:")
|
127 |
-
|
128 |
-
|
|
|
100 |
st.markdown('<style>div.stAlert { background-color: rgba(241, 36, 36, 0.9); }</style>', unsafe_allow_html=True)
|
101 |
|
102 |
|
103 |
+
def take_challenge(music_file, typed_lyrics):
|
104 |
+
st.write('------')
|
105 |
+
st.write("Listen to music since you have to record 15seconds after that")
|
106 |
+
st.audio(music_file)
|
107 |
+
audio_value = st.experimental_audio_input("Sing Rest of music:ποΈ")
|
108 |
+
if audio_value:
|
109 |
+
with open("user_sing.mp3", "wb") as f:
|
110 |
+
f.write(audio_value.getbuffer())
|
111 |
+
user_lyrics = model.transcribe("user_sing.mp3")["text"]
|
112 |
+
st.write(user_lyrics)
|
113 |
+
similarity_score = cosine_sim(typed_lyrics, user_lyrics)
|
114 |
+
if similarity_score > 0.85:
|
115 |
+
st.success('Awsome! You are doing great', icon="β
")
|
116 |
+
st.markdown('<style>div.stAlert { background-color: rgba(3, 67, 24, 0.9); }</style>', unsafe_allow_html=True)
|
117 |
+
else:
|
118 |
+
st.error('Awful! Try harder next time', icon="π¨")
|
119 |
+
st.markdown('<style>div.stAlert { background-color: rgba(241, 36, 36, 0.9); }</style>', unsafe_allow_html=True)
|
120 |
+
|
121 |
+
|
122 |
+
|
123 |
with tab2:
|
124 |
st.write("Upload music to make challenge:")
|
125 |
uploaded_file = st.file_uploader("Choose a music file", type=["mp3", "wav"])
|
|
|
138 |
trimmed_audio = audio[start_time * 1000:end_time * 1000]
|
139 |
trimmed_audio.export("trimmed_music.mp3", format="mp3")
|
140 |
st.write("Now type what user should sing:")
|
141 |
+
typed_lyrics = st.text_area("Lyrics to be singed:")
|
142 |
+
take_challenge("trimmed_music.mp3", typed_lyrics)
|
143 |
else:
|
144 |
+
st.error('Start Time should be smaller than End Time!', icon="β")
|
145 |
+
st.markdown('<style>div.stAlert { background-color: rgba(241, 36, 36, 0.9); }</style>', unsafe_allow_html=True)
|
146 |
else:
|
147 |
st.write("Now type what user should sing:")
|
148 |
+
typed_lyrics = st.text_area("Lyrics to be singed:")
|
149 |
+
take_challenge("raw_music.mp3", typed_lyrics)
|