mohitk24 commited on
Commit
b3017c6
·
verified ·
1 Parent(s): 683c17d

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +7 -31
app.py CHANGED
@@ -1,28 +1,22 @@
1
  import os
 
2
  import shutil
3
  import zipfile
4
  import pathlib
5
  import pandas as pd
6
  import gradio as gr
7
  import huggingface_hub as h
8
- from huggingface_hub import HfApi, Repository, create_repo
9
  import autogluon.tabular
 
 
 
10
 
11
  model_repo_id = "madhavkarthi/24679-HW2-tabular-autolguon-predictor"
12
  zip_filename = "autogluon_predictor_dir.zip"
13
  cache_dir = pathlib.Path("hf_assests")
14
  extract_dir = cache_dir / "predictor_native"
15
 
16
- feature_col = ["right hand notes", "left hand notes",
17
- "measures", "Key Center", "marking",
18
- ]
19
- target_col = "Target (Composer)"
20
-
21
- outcome_lab = {
22
- 0: "Beethoven",
23
- 1: "Mozart"
24
- }
25
-
26
  def prepare_predictor_dir() -> str:
27
  cache_dir.mkdir(parents=True, exist_ok=True)
28
  local_zip = h.hf_hub_download(
@@ -44,25 +38,14 @@ def prepare_predictor_dir() -> str:
44
  predictor_dir = prepare_predictor_dir()
45
  predictor = autogluon.tabular.TabularPredictor.load(predictor_dir, require_py_version_match=False)
46
 
47
- def human_label(c):
48
- try:
49
- ci = int(c)
50
- if ci in outcome_lab:
51
- return outcome_lab[ci]
52
- except Exception:
53
- pass
54
- if c in outcome_lab:
55
- return outcome_lab[c]
56
- return str(c)
57
-
58
  def do_predict(right_hand_notes, left_hand_notes, measures, Key_Center, marking):
59
 
60
  row = {
61
  feature_col[0]: int(right_hand_notes),
62
  feature_col[1]: int(left_hand_notes),
63
  feature_col[2]: int(measures),
64
- feature_col[3]: float(Key_Center),
65
- feature_col[4]: float(marking),
66
  }
67
  X = pd.DataFrame([row], columns=feature_col)
68
 
@@ -89,13 +72,6 @@ def do_predict(right_hand_notes, left_hand_notes, measures, Key_Center, marking)
89
 
90
  return pred_label, proba_dict
91
 
92
- examples = [
93
- [108, 82, 16, 3, 1], #Mozart
94
- [196, 136, 29, 2, 2], #Mozart
95
- [96, 49, 13, 2, 4], #Beethoven
96
- [104, 86, 19, 6, 5] #Beethoven
97
- ]
98
-
99
  key_center_mapping = {
100
  0: "A", 1: "Bb", 2: "B", 3: "C", 4: "Db", 5: "D",
101
  6: "Eb", 7: "E", 8: "F", 9: "Gb", 10: "G", 11: "Ab"
 
1
  import os
2
+ import os
3
  import shutil
4
  import zipfile
5
  import pathlib
6
  import pandas as pd
7
  import gradio as gr
8
  import huggingface_hub as h
9
+ from huggingface_hub import HfApi, Repository, create_repo, login
10
  import autogluon.tabular
11
+ import getpass
12
+ import shutil
13
+ from git import Repo as GitRepo
14
 
15
  model_repo_id = "madhavkarthi/24679-HW2-tabular-autolguon-predictor"
16
  zip_filename = "autogluon_predictor_dir.zip"
17
  cache_dir = pathlib.Path("hf_assests")
18
  extract_dir = cache_dir / "predictor_native"
19
 
 
 
 
 
 
 
 
 
 
 
20
  def prepare_predictor_dir() -> str:
21
  cache_dir.mkdir(parents=True, exist_ok=True)
22
  local_zip = h.hf_hub_download(
 
38
  predictor_dir = prepare_predictor_dir()
39
  predictor = autogluon.tabular.TabularPredictor.load(predictor_dir, require_py_version_match=False)
40
 
 
 
 
 
 
 
 
 
 
 
 
41
  def do_predict(right_hand_notes, left_hand_notes, measures, Key_Center, marking):
42
 
43
  row = {
44
  feature_col[0]: int(right_hand_notes),
45
  feature_col[1]: int(left_hand_notes),
46
  feature_col[2]: int(measures),
47
+ feature_col[3]: int(Key_Center),
48
+ feature_col[4]: int(marking),
49
  }
50
  X = pd.DataFrame([row], columns=feature_col)
51
 
 
72
 
73
  return pred_label, proba_dict
74
 
 
 
 
 
 
 
 
75
  key_center_mapping = {
76
  0: "A", 1: "Bb", 2: "B", 3: "C", 4: "Db", 5: "D",
77
  6: "Eb", 7: "E", 8: "F", 9: "Gb", 10: "G", 11: "Ab"