Skip to content

Commit

Permalink
chore(example): add serve handler for speech command (#1718)
Browse files Browse the repository at this point in the history
  • Loading branch information
jialeicui authored Jan 16, 2023
1 parent 09828d9 commit d21c057
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions example/speech_command/sc/evaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@

import numpy as np
import torch
import gradio
import torchaudio

from starwhale import Audio, PipelineHandler, multi_classification
from starwhale.api.service import api

from .model import M5

Expand Down Expand Up @@ -108,3 +110,16 @@ def _load_model(self, device):
model.eval()
print("m5 model loaded, start to inference...")
return model

@api(
[
gradio.Audio(type="filepath"),
gradio.Audio(source="microphone", type="filepath"),
],
gradio.Label(),
)
def online_eval(self, file: str):
with open(file, "rb") as f:
data = f.read()
_, prob = self.ppl(Audio(fp=data))
return {ALL_LABELS[i]: p for i, p in enumerate(prob)}

0 comments on commit d21c057

Please sign in to comment.