File size: 1,052 Bytes
e019169
 
09ec697
35d23eb
4db7dc5
09ec697
9b36fa7
 
 
 
 
 
e019169
 
9b36fa7
 
 
 
 
 
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
from transformers import pipeline
import gradio as gr
from numpy import random 
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)
query_image = Image.open("./images/" + image + ".jpeg")

with gr.Blocks as demo:
    with gr.row():
        gr.Label("Vad är detta? Spela in ditt svar med inspelningsknappen!")
        input_img = gr.Image(query_image)
def transcribe(audio):
    text = pipe(audio)["text"]
    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
    return returntext

iface = gr.Interface(
    fn=transcribe, 
    inputs=gr.Audio(source="microphone", type="filepath"), 
    outputs="text",
    title="Whisper Small Swedish",
    description="Realtime demo for Swedish speech recognition using a fine-tuned Whisper small model.",
)


iface.launch()