File size: 1,101 Bytes
e019169
 
09ec697
043f2c8
35d23eb
4db7dc5
09ec697
9b36fa7
0fc26e1
e019169
732d8fb
 
 
9b36fa7
 
 
 
 
c8a97fa
c24de0c
9b36fa7
e019169
 
 
0fc26e1
e019169
 
f54a47c
e019169
 
4db7dc5
e019169
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
from transformers import pipeline
import gradio as gr
from numpy import random 
from PIL import Image
pipe = pipeline(model="fimster/whisper-small-sv-SE")  # change to "your-username/the-name-you-picked"
images = ["katt", "melon", "hund", "banan"]
image = random.choice(images)

def transcribe(audio, img):
    text = pipe(audio)["text"]
    text = text.replace("!", "")
    text = text.replace(".", "")
    text = text.replace(",", "")
    returntext = ""
    if text.lower() != image.lower():
        returntext = "Du svarade fel, ditt svar var: " + text + ", rätt svar var: " + image
    else:
        returntext = "Du hade rätt, svaret var: " + image
    global image
    image = random.choice(images)
    return returntext

iface = gr.Interface(
    fn=transcribe, 
    inputs=[gr.Audio(source="microphone", type="filepath"), gr.Image("./images/" + image + ".jpeg")], 
    outputs="text",
    title="Whisper Small Swedish",
    description="Demo of whisper small ASR fine tuned to swedish. Vad är det på bilden? Spela in ditt svar genom att trycka på inspelningsknappen!",
)


iface.launch()