aimodelshare 0.1.54__py3-none-any.whl → 0.1.59__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of aimodelshare might be problematic. Click here for more details.

Files changed (35) hide show
  1. aimodelshare/__init__.py +94 -14
  2. aimodelshare/aimsonnx.py +263 -82
  3. aimodelshare/api.py +13 -12
  4. aimodelshare/auth.py +163 -0
  5. aimodelshare/base_image.py +1 -1
  6. aimodelshare/containerisation.py +1 -1
  7. aimodelshare/data_sharing/download_data.py +133 -83
  8. aimodelshare/generatemodelapi.py +7 -6
  9. aimodelshare/main/authorization.txt +275 -275
  10. aimodelshare/main/eval_lambda.txt +81 -13
  11. aimodelshare/model.py +492 -196
  12. aimodelshare/modeluser.py +22 -0
  13. aimodelshare/moral_compass/README.md +367 -0
  14. aimodelshare/moral_compass/__init__.py +58 -0
  15. aimodelshare/moral_compass/_version.py +3 -0
  16. aimodelshare/moral_compass/api_client.py +553 -0
  17. aimodelshare/moral_compass/challenge.py +365 -0
  18. aimodelshare/moral_compass/config.py +187 -0
  19. aimodelshare/playground.py +26 -14
  20. aimodelshare/preprocessormodules.py +60 -6
  21. aimodelshare/pyspark/authorization.txt +258 -258
  22. aimodelshare/pyspark/eval_lambda.txt +1 -1
  23. aimodelshare/reproducibility.py +20 -5
  24. aimodelshare/utils/__init__.py +78 -0
  25. aimodelshare/utils/optional_deps.py +38 -0
  26. aimodelshare-0.1.59.dist-info/METADATA +258 -0
  27. {aimodelshare-0.1.54.dist-info → aimodelshare-0.1.59.dist-info}/RECORD +30 -24
  28. aimodelshare-0.1.59.dist-info/licenses/LICENSE +5 -0
  29. {aimodelshare-0.1.54.dist-info → aimodelshare-0.1.59.dist-info}/top_level.txt +0 -1
  30. aimodelshare-0.1.54.dist-info/METADATA +0 -63
  31. aimodelshare-0.1.54.dist-info/licenses/LICENSE +0 -2
  32. tests/__init__.py +0 -0
  33. tests/test_aimsonnx.py +0 -135
  34. tests/test_playground.py +0 -721
  35. {aimodelshare-0.1.54.dist-info → aimodelshare-0.1.59.dist-info}/WHEEL +0 -0
@@ -20,6 +20,45 @@ logger = logging.getLogger(__name__)
20
20
  # from s3connect import get_ytestdata, get_onnx_mem, get_onnx_temp
21
21
 
22
22
 
23
+ ####################################################################
24
+ ##################### Helper Functions #############################
25
+
26
+ def _ensure_df(obj):
27
+ """
28
+ Safely convert various input types to pandas DataFrame.
29
+ Handles dict, list, and DataFrame inputs with robust error handling.
30
+
31
+ For dict inputs, always treats them as a single row to maintain consistent
32
+ behavior and avoid unexpected flattening of nested structures.
33
+
34
+ Args:
35
+ obj: Input object (DataFrame, dict, list, or other)
36
+
37
+ Returns:
38
+ pandas.DataFrame
39
+ """
40
+ import pandas as pd
41
+
42
+ if isinstance(obj, pd.DataFrame):
43
+ return obj
44
+
45
+ if isinstance(obj, dict):
46
+ # Always treat dict as single row to maintain consistent structure
47
+ return pd.DataFrame([obj])
48
+
49
+ if isinstance(obj, list):
50
+ if len(obj) == 0:
51
+ return pd.DataFrame()
52
+ # If all elements are dicts, create DataFrame from list of dicts
53
+ if all(isinstance(x, dict) for x in obj):
54
+ return pd.DataFrame(obj)
55
+ # Otherwise, create single-column DataFrame
56
+ return pd.DataFrame({'value': obj})
57
+
58
+ # For any other type, return empty DataFrame
59
+ return pd.DataFrame()
60
+
61
+
23
62
  ####################################################################
24
63
  ########################### main handler ###########################
25
64
 
@@ -63,7 +102,7 @@ def handler(event, context):
63
102
  return exdata_dict
64
103
 
65
104
  idtoken=event['requestContext']['authorizer']['principalId']
66
- decoded = jwt.decode(idtoken, options={"verify_signature": False}) # works in PyJWT < v2.0
105
+ decoded = jwt.decode(idtoken,options={"verify_signature": False,"verify_aud": False}) # works in PyJWT < v2.0
67
106
  email=decoded['email']
68
107
  print(email)
69
108
  submission_type = body.get("submission_type", None)
@@ -859,6 +898,7 @@ def model_from_string(model_type):
859
898
  'BayesianRidge': 'sklearn.linear_model',
860
899
  'BernoulliNB': 'sklearn.naive_bayes',
861
900
  'BernoulliRBM': 'sklearn.neural_network',
901
+ 'CalibratedClassifierCV': 'sklearn.calibration',
862
902
  'CategoricalNB': 'sklearn.naive_bayes',
863
903
  'ClassifierMixin': 'sklearn.naive_bayes',
864
904
  'ComplementNB': 'sklearn.naive_bayes',
@@ -896,6 +936,7 @@ def model_from_string(model_type):
896
936
  'LassoLars': 'sklearn.linear_model',
897
937
  'LassoLarsCV': 'sklearn.linear_model',
898
938
  'LassoLarsIC': 'sklearn.linear_model',
939
+ 'LinearDiscriminantAnalysis': 'sklearn.discriminant_analysis',
899
940
  'LinearRegression': 'sklearn.linear_model',
900
941
  'LinearSVC': 'sklearn.svm',
901
942
  'LinearSVR': 'sklearn.svm',
@@ -930,6 +971,7 @@ def model_from_string(model_type):
930
971
  'PassiveAggressiveRegressor': 'sklearn.linear_model',
931
972
  'Perceptron': 'sklearn.linear_model',
932
973
  'PoissonRegressor': 'sklearn.linear_model',
974
+ 'QuadraticDiscriminantAnalysis': 'sklearn.discriminant_analysis',
933
975
  'RANSACRegressor': 'sklearn.linear_model',
934
976
  'RadiusNeighborsClassifier': 'sklearn.neighbors',
935
977
  'RadiusNeighborsRegressor': 'sklearn.neighbors',
@@ -984,13 +1026,25 @@ def get_leaderboard(task_type="classification", verbose=3, columns=None, private
984
1026
 
985
1027
  s3 = boto3.resource("s3")
986
1028
  bucketres = s3.Bucket("$bucket_name")
987
- with open("/tmp/"+mastertable_path.split("/")[-1]+".csv", "wb") as lbfo:
988
- bucketres.download_fileobj("$unique_model_id/"+mastertable_path+".csv", lbfo)
989
-
990
-
991
-
992
- leaderboard = pd.read_csv("/tmp/"+mastertable_path.split("/")[-1]+".csv", sep="\t")
993
- currentversions=leaderboard['version']
1029
+
1030
+ # Defensive read of master leaderboard file
1031
+ try:
1032
+ with open("/tmp/"+mastertable_path.split("/")[-1]+".csv", "wb") as lbfo:
1033
+ bucketres.download_fileobj("$unique_model_id/"+mastertable_path+".csv", lbfo)
1034
+ leaderboard = pd.read_csv("/tmp/"+mastertable_path.split("/")[-1]+".csv", sep="\t")
1035
+ except Exception as e:
1036
+ print(f"Warning: Could not read master leaderboard file: {e}")
1037
+ leaderboard = pd.DataFrame()
1038
+
1039
+ # Ensure leaderboard is a DataFrame
1040
+ leaderboard = _ensure_df(leaderboard)
1041
+
1042
+ # Get current versions if available
1043
+ try:
1044
+ currentversions=leaderboard['version']
1045
+ except KeyError:
1046
+ currentversions=[]
1047
+
994
1048
  print("current versions:")
995
1049
  print(list(currentversions))
996
1050
  allversions = [sub.split('_v')[1].split('.')[0] for sub in newleaderboarddata]
@@ -1002,12 +1056,26 @@ def get_leaderboard(task_type="classification", verbose=3, columns=None, private
1002
1056
  #TODO: check if items in leaderboard, if so, then do following
1003
1057
  if len(missingincurrent_leaderboard)>0:
1004
1058
  for i in missingincurrent_leaderboard:
1005
- with open("/tmp/"+mastertable_path.split("/")[-1]+"_v"+str(i)+".csv", "wb") as lbfo:
1006
- bucketres.download_fileobj("$unique_model_id/"+mastertable_path+"_v"+str(i)+".csv", lbfo)
1007
- newleaderboard = pd.read_csv("/tmp/"+mastertable_path.split("/")[-1]+"_v"+str(i)+".csv", sep="\t")
1008
- newleaderboard.drop(newleaderboard.filter(regex="Unname"),axis=1, inplace=True)
1059
+ try:
1060
+ with open("/tmp/"+mastertable_path.split("/")[-1]+"_v"+str(i)+".csv", "wb") as lbfo:
1061
+ bucketres.download_fileobj("$unique_model_id/"+mastertable_path+"_v"+str(i)+".csv", lbfo)
1062
+ newleaderboard = pd.read_csv("/tmp/"+mastertable_path.split("/")[-1]+"_v"+str(i)+".csv", sep="\t")
1063
+ newleaderboard.drop(newleaderboard.filter(regex="Unname"),axis=1, inplace=True)
1064
+ except Exception as e:
1065
+ print(f"Warning: Could not read leaderboard for version {i}: {e}")
1066
+ continue
1009
1067
 
1010
- leaderboard=pd.concat([leaderboard, newleaderboard]).drop_duplicates()
1068
+ # Ensure newleaderboard is a DataFrame before concat
1069
+ newleaderboard = _ensure_df(newleaderboard)
1070
+
1071
+ # Use pd.concat instead of deprecated append
1072
+ leaderboard = pd.concat([leaderboard, newleaderboard], ignore_index=True)
1073
+
1074
+ # Deduplicate once after all concatenations, keeping last occurrence
1075
+ if 'version' in leaderboard.columns:
1076
+ leaderboard = leaderboard.drop_duplicates(subset=['version'], keep='last')
1077
+ else:
1078
+ leaderboard = leaderboard.drop_duplicates(keep='last')
1011
1079
 
1012
1080
  leaderboard.drop(leaderboard.filter(regex="Unname"),axis=1, inplace=True)
1013
1081
  #save new leaderboard here