File size: 1,532 Bytes
69a9bd1
 
5845aec
f8dd39f
69a9bd1
ca7a91e
fab0e17
69a9bd1
 
 
 
 
fab0e17
5845aec
 
4021dbc
 
 
fab0e17
 
 
4021dbc
 
fab0e17
b1c4543
5845aec
fab0e17
4021dbc
 
fab0e17
2cc03f8
fab0e17
 
af5b628
69a9bd1
fab0e17
66fd747
69a9bd1
fab0e17
2cc03f8
fab0e17
69a9bd1
 
fab0e17
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
from transformers import pipeline
import gradio as gr
from song_guesser import SongGuesser
from list_songs import ListSongs

pipe = pipeline(model="MarieGotthardt/whisper_swedish_tuned")


def transcribe(audio):
    text = pipe(audio)["text"]
    return text


def get_song_guess(audio):
    user_query = transcribe(audio)
    song_guess = SongGuesser.guess_song(user_query)
    if len(song_guess) == 0:
        song_guess = "too badly for him to guess a song" # default output if no song guess
    output = (
        "What Santa heard: "
        + user_query
        + "\n\nSanta thinks you sang: "
        + song_guess
    )
    return output


intro_info = "Santa wants you to sing a Swedish Christmas song so he can try to guess it, but keep in mind that Santa is getting old and doesn't hear so well.\nTo help Santa guess correctly, try to sing clearly or more of the lyrics, and make sure to sing one of the songs Santa is familiar with from the list below!"
santa_image_md = '<img width="400" height="400" style="float: right;" src="https://raw.githubusercontent.com/SamuelHarner/app-images/main/images/DALLE-Santa-480.png?raw=true">'
song_info = (
    "Santa is familiar with the following Swedish Christmas songs: \n"
    + ListSongs.get_song_list()
)

iface = gr.Interface(
    fn=get_song_guess,
    inputs=gr.Audio(sources=["microphone"], type="filepath"),
    outputs="text",
    title="Sing a song and let Santa guess 🎅🏼",
    description=santa_image_md+"\n"+intro_info,
    article=song_info,
)

iface.launch()