sahandkh1419 commited on
Commit
90db3b8
1 Parent(s): 31057e3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -6
app.py CHANGED
@@ -72,7 +72,7 @@ def cosine_sim(text1, text2):
72
  return cosine_similarity(vectors)[0, 1]
73
 
74
 
75
- model = whisper.load_model("base")
76
 
77
 
78
  tab1, tab2 = st.tabs(["Take Challenge", "Make Challenge"])
@@ -89,7 +89,7 @@ with tab1:
89
  with open("user_sing.mp3", "wb") as f:
90
  f.write(audio_value.getbuffer())
91
 
92
- user_lyrics = model.transcribe("user_sing.mp3")["text"]
93
  st.write(user_lyrics)
94
  similarity_score = cosine_sim(lyrics, user_lyrics)
95
  if similarity_score > 0.85:
@@ -100,7 +100,7 @@ with tab1:
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, key):
104
  st.write('------')
105
  st.write("Listen to music since you have to record 15seconds after that")
106
  st.audio(music_file)
@@ -108,7 +108,7 @@ def take_challenge(music_file, typed_lyrics, key):
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:
@@ -123,6 +123,9 @@ def take_challenge(music_file, typed_lyrics, key):
123
  with tab2:
124
  st.write("Upload music to make challenge:")
125
  uploaded_file = st.file_uploader("Choose a music file", type=["mp3", "wav"])
 
 
 
126
  if uploaded_file is not None:
127
  with open("raw_music.mp3", "wb") as f:
128
  f.write(uploaded_file.getbuffer())
@@ -139,11 +142,11 @@ with tab2:
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, "unique_key_1")
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, "unique_key_2")
 
72
  return cosine_similarity(vectors)[0, 1]
73
 
74
 
75
+ model = whisper.load_model("small")
76
 
77
 
78
  tab1, tab2 = st.tabs(["Take Challenge", "Make Challenge"])
 
89
  with open("user_sing.mp3", "wb") as f:
90
  f.write(audio_value.getbuffer())
91
 
92
+ user_lyrics = model.transcribe("user_sing.mp3", language="en")["text"]
93
  st.write(user_lyrics)
94
  similarity_score = cosine_sim(lyrics, user_lyrics)
95
  if similarity_score > 0.85:
 
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, key, language):
104
  st.write('------')
105
  st.write("Listen to music since you have to record 15seconds after that")
106
  st.audio(music_file)
 
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", language=language)["text"]
112
  st.write(user_lyrics)
113
  similarity_score = cosine_sim(typed_lyrics, user_lyrics)
114
  if similarity_score > 0.85:
 
123
  with tab2:
124
  st.write("Upload music to make challenge:")
125
  uploaded_file = st.file_uploader("Choose a music file", type=["mp3", "wav"])
126
+ language_mapping = {"English": "en", "Persian": "fa"}
127
+ selected_language = st.radio("Select Language", language_mapping.keys(), horizontal=True)
128
+ language = language_mapping[selected_language]
129
  if uploaded_file is not None:
130
  with open("raw_music.mp3", "wb") as f:
131
  f.write(uploaded_file.getbuffer())
 
142
  trimmed_audio.export("trimmed_music.mp3", format="mp3")
143
  st.write("Now type what user should sing:")
144
  typed_lyrics = st.text_area("Lyrics to be singed:")
145
+ take_challenge("trimmed_music.mp3", typed_lyrics, "unique_key_1", language)
146
  else:
147
  st.error('Start Time should be smaller than End Time!', icon="❌")
148
  st.markdown('<style>div.stAlert { background-color: rgba(241, 36, 36, 0.9); }</style>', unsafe_allow_html=True)
149
  else:
150
  st.write("Now type what user should sing:")
151
  typed_lyrics = st.text_area("Lyrics to be singed:")
152
+ take_challenge("raw_music.mp3", typed_lyrics, "unique_key_2", language)