Spaces:
Runtime error
Runtime error
Initial commit: Gradio app and requirements
Browse files- app.py +52 -0
- requirements.txt +4 -0
app.py
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from autogluon.tabular import TabularPredictor
|
| 3 |
+
import pandas as pd
|
| 4 |
+
|
| 5 |
+
# Load the model from the `model/` folder in this repo
|
| 6 |
+
predictor = TabularPredictor.load("model/")
|
| 7 |
+
|
| 8 |
+
key_center_mapping = {
|
| 9 |
+
0: "A", 1: "Bb", 2: "B", 3: "C", 4: "Db", 5: "D",
|
| 10 |
+
6: "Eb", 7: "E", 8: "F", 9: "Gb", 10: "G", 11: "Ab"
|
| 11 |
+
}
|
| 12 |
+
marking_mapping = {
|
| 13 |
+
0: "Minuet", 1: "Allegro", 2: "Andante",
|
| 14 |
+
3: "Moderato", 4: "Allegretto", 5: "Dance"
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
def predict_composer(rh, lh, measures, key_center, marking):
|
| 18 |
+
df = pd.DataFrame({
|
| 19 |
+
'right hand notes': [rh],
|
| 20 |
+
'left hand notes': [lh],
|
| 21 |
+
'measures': [measures],
|
| 22 |
+
'Key Center': [key_center],
|
| 23 |
+
'marking': [marking]
|
| 24 |
+
})
|
| 25 |
+
pred = predictor.predict(df)[0]
|
| 26 |
+
probs = predictor.predict_proba(df).iloc[0].to_dict()
|
| 27 |
+
return pred, probs
|
| 28 |
+
|
| 29 |
+
examples = [
|
| 30 |
+
[108, 82, 16, 3, 1],
|
| 31 |
+
[196, 136, 29, 2, 2],
|
| 32 |
+
[96, 49, 13, 2, 4],
|
| 33 |
+
[481, 561, 31, 5, 5],
|
| 34 |
+
[174, 129, 31, 2, 1],
|
| 35 |
+
]
|
| 36 |
+
|
| 37 |
+
with gr.Blocks() as demo:
|
| 38 |
+
gr.Markdown("# Classical Music Composer Classifier")
|
| 39 |
+
gr.Markdown("Predict whether a piece was composed by **Mozart** or **Beethoven**.")
|
| 40 |
+
with gr.Row():
|
| 41 |
+
rh = gr.Number(150, label="Right Hand Notes")
|
| 42 |
+
lh = gr.Number(100, label="Left Hand Notes")
|
| 43 |
+
measures = gr.Number(20, label="Measures")
|
| 44 |
+
with gr.Row():
|
| 45 |
+
key_center = gr.Dropdown(list(key_center_mapping.keys()), value=3, label="Key Center")
|
| 46 |
+
marking = gr.Dropdown(list(marking_mapping.keys()), value=1, label="Marking")
|
| 47 |
+
out_label = gr.Textbox(label="Predicted Composer")
|
| 48 |
+
out_probs = gr.Label(num_top_classes=2, label="Probabilities")
|
| 49 |
+
for inp in [rh, lh, measures, key_center, marking]:
|
| 50 |
+
inp.change(fn=predict_composer, inputs=[rh, lh, measures, key_center, marking], outputs=[out_label, out_probs])
|
| 51 |
+
gr.Examples(examples, inputs=[rh, lh, measures, key_center, marking], outputs=[out_label, out_probs])
|
| 52 |
+
demo.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio>=3.0
|
| 2 |
+
autogluon.tabular
|
| 3 |
+
pandas
|
| 4 |
+
huggingface_hub
|