sahandkh1419 commited on
Commit
7f9e9d7
β€’
1 Parent(s): 6c1e437

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -30
app.py CHANGED
@@ -72,37 +72,7 @@ def cosine_sim(text1, text2):
72
  vectors = vectorizer.toarray()
73
  return cosine_similarity(vectors)[0, 1]
74
 
75
-
76
-
77
-
78
- tab1, tab2 = st.tabs(["Take Challenge", "Make Challenge"])
79
-
80
- with tab1:
81
- st.write("Listen to music since you have to record 15seconds after that")
82
- st.audio("titanic.mp3")
83
-
84
-
85
- audio_value = st.experimental_audio_input("Sing Rest of music:πŸŽ™οΈ")
86
- lyrics = "Far across the distance And spaces between us You have come to show you go on"
87
-
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)
96
- if similarity_score > 0.85:
97
- st.success('Awsome! You are doing great', icon="βœ…")
98
- st.markdown('<style>div.stAlert { background-color: rgba(3, 67, 24, 0.9); }</style>', unsafe_allow_html=True)
99
- else:
100
- st.error('Awful! Try harder next time', icon="🚨")
101
- st.markdown('<style>div.stAlert { background-color: rgba(241, 36, 36, 0.9); }</style>', unsafe_allow_html=True)
102
-
103
-
104
  def take_challenge(music_file, typed_lyrics, key, language):
105
- st.write('------')
106
  st.write("Listen to music since you have to record 15seconds after that")
107
  st.audio(music_file)
108
  audio_value = st.experimental_audio_input("Sing Rest of music:πŸŽ™οΈ", key=key)
@@ -127,6 +97,14 @@ def take_challenge(music_file, typed_lyrics, key, language):
127
  st.markdown('<style>div.stAlert { background-color: rgba(241, 36, 36, 0.9); }</style>', unsafe_allow_html=True)
128
 
129
 
 
 
 
 
 
 
 
 
130
 
131
  with tab2:
132
  st.write("Upload music to make challenge:")
@@ -150,6 +128,7 @@ with tab2:
150
  trimmed_audio.export("trimmed_music.mp3", format="mp3")
151
  st.write("Now type what user should sing:")
152
  typed_lyrics = st.text_area("Lyrics to be singed:")
 
153
  take_challenge("trimmed_music.mp3", typed_lyrics, "unique_key_1", language)
154
  else:
155
  st.error('Start Time should be smaller than End Time!', icon="❌")
@@ -157,4 +136,5 @@ with tab2:
157
  else:
158
  st.write("Now type what user should sing:")
159
  typed_lyrics = st.text_area("Lyrics to be singed:")
 
160
  take_challenge("raw_music.mp3", typed_lyrics, "unique_key_2", language)
 
72
  vectors = vectorizer.toarray()
73
  return cosine_similarity(vectors)[0, 1]
74
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
75
  def take_challenge(music_file, typed_lyrics, key, language):
 
76
  st.write("Listen to music since you have to record 15seconds after that")
77
  st.audio(music_file)
78
  audio_value = st.experimental_audio_input("Sing Rest of music:πŸŽ™οΈ", key=key)
 
97
  st.markdown('<style>div.stAlert { background-color: rgba(241, 36, 36, 0.9); }</style>', unsafe_allow_html=True)
98
 
99
 
100
+
101
+
102
+ tab1, tab2 = st.tabs(["Take Challenge", "Make Challenge"])
103
+
104
+ with tab1:
105
+ lyrics = "Far across the distance And spaces between us You have come to show you go on"
106
+ take_challenge("titanic.mp3", lyrics, key="en_challenge", language="en")
107
+
108
 
109
  with tab2:
110
  st.write("Upload music to make challenge:")
 
128
  trimmed_audio.export("trimmed_music.mp3", format="mp3")
129
  st.write("Now type what user should sing:")
130
  typed_lyrics = st.text_area("Lyrics to be singed:")
131
+ st.write('------')
132
  take_challenge("trimmed_music.mp3", typed_lyrics, "unique_key_1", language)
133
  else:
134
  st.error('Start Time should be smaller than End Time!', icon="❌")
 
136
  else:
137
  st.write("Now type what user should sing:")
138
  typed_lyrics = st.text_area("Lyrics to be singed:")
139
+ st.write('------')
140
  take_challenge("raw_music.mp3", typed_lyrics, "unique_key_2", language)