File size: 1,742 Bytes
87c1b11
af4167f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5ac4244
 
 
 
 
 
 
 
 
 
af4167f
 
5ac4244
 
 
 
 
 
 
 
 
 
 
 
38e0bd1
 
 
 
5ac4244
 
 
 
 
 
 
 
 
 
87c1b11
 
 
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import gradio as gr
from sagan_inference import run_sagan, z_score_standardize

AGE_CHOICES = ["kindergarten", "grade_6", "adult"]

def score_audio(audio, age_group):
    # Gradio passes `audio` as (tempfilepath, sr)
    wav_path = audio[0]
    raw = run_sagan(wav_path)
    calibrated = z_score_standardize(raw, age_group)
    # Display-friendly labels
    return {
        "Pitch Accuracy (0–1)": calibrated["pitch"],
        "Rhythm Consistency (0–1)": calibrated["rhythm"],
        "Timbre Score (0–1)": calibrated["timbre"],
    }

# with gr.Blocks() as demo:
#     gr.Markdown("## SAGAN Singing Scorer with Age-Calibrated Z-Scores")
#     audio_input = gr.Audio(source="upload", label="Upload Singing Clip")
#     age_input   = gr.Dropdown(AGE_CHOICES, label="Age Group")
#     output      = gr.Label(label="Calibrated Scores")
#     btn         = gr.Button("Score My Singing")
#     btn.click(fn=score_audio,
#               inputs=[audio_input, age_input],
#               outputs=output)

with gr.Blocks() as demo:
    gr.Markdown("## SAGAN Singing Scorer with Age-Calibrated Z-Scores")
    
    audio_input = gr.Audio(
        sources=["upload"],      # use the plural `sources`
        type="filepath",         # returns a local file path to your fn
        label="Upload Singing Clip"
    )
    
    age_input = gr.Dropdown(
        choices=AGE_CHOICES, 
        label="Age Group"
    )
    
    # output = gr.Label(
    #     label="Calibrated Scores"
    # )
    output = gr.JSON(
        label="Calibrated Scores"
    )
    
    btn = gr.Button("Score My Singing")
    btn.click(
        fn=score_audio,
        inputs=[audio_input, age_input],
        outputs=output
    )


if __name__ == "__main__":
    demo.launch()