sahandkh1419 commited on
Commit
684e692
1 Parent(s): 90db3b8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -3
app.py CHANGED
@@ -4,6 +4,7 @@ from sklearn.feature_extraction.text import TfidfVectorizer
4
  from sklearn.metrics.pairwise import cosine_similarity
5
  import base64
6
  from pydub import AudioSegment
 
7
 
8
  st.set_page_config(
9
  page_title="Sing It Forward App",
@@ -72,7 +73,6 @@ def cosine_sim(text1, text2):
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"])
@@ -88,7 +88,8 @@ with tab1:
88
  if audio_value:
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)
@@ -108,7 +109,14 @@ def take_challenge(music_file, typed_lyrics, key, language):
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:
 
4
  from sklearn.metrics.pairwise import cosine_similarity
5
  import base64
6
  from pydub import AudioSegment
7
+ from hezar.models import Model
8
 
9
  st.set_page_config(
10
  page_title="Sing It Forward App",
 
73
  return cosine_similarity(vectors)[0, 1]
74
 
75
 
 
76
 
77
 
78
  tab1, tab2 = st.tabs(["Take Challenge", "Make Challenge"])
 
88
  if audio_value:
89
  with open("user_sing.mp3", "wb") as f:
90
  f.write(audio_value.getbuffer())
91
+
92
+ model = whisper.load_model("base.en")
93
  user_lyrics = model.transcribe("user_sing.mp3", language="en")["text"]
94
  st.write(user_lyrics)
95
  similarity_score = cosine_sim(lyrics, user_lyrics)
 
109
  if audio_value:
110
  with open("user_sing.mp3", "wb") as f:
111
  f.write(audio_value.getbuffer())
112
+
113
+ if language == "en":
114
+ model = whisper.load_model("base.en")
115
+ user_lyrics = model.transcribe("user_sing.mp3", language=language)["text"]
116
+ else:
117
+ model = Model.load("hezarai/whisper-small-fa")
118
+ user_lyrics = model.predict("user_sing.mp3")[0]["text"]
119
+
120
  st.write(user_lyrics)
121
  similarity_score = cosine_sim(typed_lyrics, user_lyrics)
122
  if similarity_score > 0.85: