File size: 2,796 Bytes
5d20072
dea462a
1e85041
 
dea462a
26b478e
 
 
 
 
 
 
4fcc8cd
26b478e
 
 
 
c9cc87b
 
 
26b478e
 
 
 
 
725e115
14e9c4a
725e115
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26b478e
 
 
 
0d4a81a
26b478e
 
 
 
 
0d4a81a
26b478e
 
 
 
 
 
 
 
 
 
09fe96c
 
 
 
 
26b478e
dea462a
1e85041
d352d4e
 
5d20072
04c8b38
1a2e1f9
5d20072
 
d344ece
 
 
dea462a
 
1e85041
 
87479c7
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import streamlit as st
import whisper
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.metrics.pairwise import cosine_similarity

st.set_page_config(
    page_title="Sing It Forward App",
    page_icon="🎵")

st.markdown(
    """
    <style>
    body {
        background: linear-gradient(to bottom, #0E5AAB, #00ffff);
        padding: 20px;
        border-radius: 10px;
    }
    a {
        color: black !important
    }    
    </style>
    """,
    unsafe_allow_html=True
)


background_image_url = "https://static.vecteezy.com/system/resources/previews/020/333/164/non_2x/stephen-foster-memorial-day-illustration-with-copy-space-area-and-blue-background-suitable-to-use-on-memorial-day-event-vector.jpg"
st.markdown(
    f"""
    <style>
    .stApp {{
        background-image: url("{background_image_url}");
        background-size: cover;
        background-position: center;
        background-repeat: no-repeat;
    }}
    </style>
    """,
    unsafe_allow_html=True
)



st.markdown("<h1 style='text-align: center; margin-bottom: 5px;'>Sing It Forward App🎵</h1>", unsafe_allow_html=True)

description = """
<h5>Welcome to Sing It Forward App!</h5>

<p style="text-align: justify;">
Get ready to test your singing skills and memory! First, listen carefully to the first part of the song, then it’s your turn to shine.
Record yourself singing the next 15 seconds on your own, matching the lyrics and rhythm perfectly. Think you’ve got what it takes to keep the music going?
Let’s see if you can hit the right notes and showcase your talent! Unleash your inner star and take the challenge!
</p>

📌For any questions or contact:  
**Name:** <span style="color: black;">Sahand Khorsandi</span>  
**Email:** <a href="mailto:[email protected]" style="color: black;">[email protected]</a>"""
st.markdown(description, unsafe_allow_html=True)
st.write('------')





def cosine_sim(text1, text2):
    vectorizer = TfidfVectorizer().fit_transform([text1, text2])
    vectors = vectorizer.toarray()
    return cosine_similarity(vectors)[0, 1]
    

model = whisper.load_model("base")
st.write("Listen to music since you have to record 15seconds after that")
st.audio("titanic.mp3")


audio_value = st.experimental_audio_input("Sing Rest of music:🎙️")
lyrics = "Far across the distance And spaces between us You have come to show you go on"

if audio_value:
    with open("user_sing.mp3", "wb") as f:
        f.write(audio_value.getbuffer())

    user_lyrics = model.transcribe("user_sing.mp3")["text"]
    st.write(user_lyrics)
    similarity_score = cosine_sim(lyrics, user_lyrics)
    if similarity_score > 0.85:
        st.success('Awsome! You are doing great', icon="✅")
    else:
        st.error('Awful! Try harder next time', icon="🚨")