whisper-swedish / app.py
sharner
Some small changes to interface
4021dbc
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()