sahandkh1419 commited on
Commit
b617e78
β€’
1 Parent(s): 0dd3575

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -20
app.py CHANGED
@@ -72,23 +72,37 @@ def cosine_sim(text1, text2):
72
 
73
 
74
  model = whisper.load_model("base")
75
- st.write("Listen to music since you have to record 15seconds after that")
76
- st.audio("titanic.mp3")
77
-
78
-
79
- audio_value = st.experimental_audio_input("Sing Rest of music:πŸŽ™οΈ")
80
- lyrics = "Far across the distance And spaces between us You have come to show you go on"
81
-
82
- if audio_value:
83
- with open("user_sing.mp3", "wb") as f:
84
- f.write(audio_value.getbuffer())
85
-
86
- user_lyrics = model.transcribe("user_sing.mp3")["text"]
87
- st.write(user_lyrics)
88
- similarity_score = cosine_sim(lyrics, user_lyrics)
89
- if similarity_score > 0.85:
90
- st.success('Awsome! You are doing great', icon="βœ…")
91
- st.markdown('<style>div.stAlert { background-color: rgba(3, 67, 24, 0.9); }</style>', unsafe_allow_html=True)
92
- else:
93
- st.error('Awful! Try harder next time', icon="🚨")
94
- st.markdown('<style>div.stAlert { background-color: rgba(241, 36, 36, 0.9); }</style>', unsafe_allow_html=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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")