Spaces:
Running
Running
features_dict => features
Browse files- tagging_app.py +22 -22
tagging_app.py
CHANGED
@@ -57,45 +57,45 @@ creator_set = {
|
|
57 |
########################
|
58 |
|
59 |
@st.cache
|
60 |
-
def filter_features(
|
61 |
-
if isinstance(
|
62 |
-
return dict([(k, filter_features(v)) for k, v in
|
63 |
-
elif
|
64 |
return {
|
65 |
-
"feature_type":
|
66 |
-
"dtype":
|
67 |
}
|
68 |
-
elif
|
69 |
-
if "dtype" in
|
70 |
return {
|
71 |
-
"feature_type":
|
72 |
-
"feature": filter_features(
|
73 |
}
|
74 |
-
elif "_type" in
|
75 |
return {
|
76 |
-
"feature_type":
|
77 |
"dtype": "int32",
|
78 |
-
"feature": filter_features(
|
79 |
}
|
80 |
else:
|
81 |
return dict(
|
82 |
-
[("feature_type",
|
83 |
-
[(k, filter_features(v)) for k, v in
|
84 |
)
|
85 |
-
elif
|
86 |
return {
|
87 |
-
"feature_type":
|
88 |
"dtype": "int32",
|
89 |
-
"class_names":
|
90 |
}
|
91 |
-
elif
|
92 |
return {
|
93 |
-
"feature_type":
|
94 |
"dtype": "string",
|
95 |
-
"languages":
|
96 |
}
|
97 |
else:
|
98 |
-
return dict([(k, filter_features(v)) for k, v in
|
99 |
|
100 |
|
101 |
@st.cache
|
|
|
57 |
########################
|
58 |
|
59 |
@st.cache
|
60 |
+
def filter_features(features):
|
61 |
+
if isinstance(features, list):
|
62 |
+
return dict([(k, filter_features(v)) for k, v in features[0].items()])
|
63 |
+
elif features.get("_type", None) == 'Value':
|
64 |
return {
|
65 |
+
"feature_type": features["_type"],
|
66 |
+
"dtype": features["dtype"],
|
67 |
}
|
68 |
+
elif features.get("_type", None) == 'Sequence':
|
69 |
+
if "dtype" in features["feature"]:
|
70 |
return {
|
71 |
+
"feature_type": features["_type"],
|
72 |
+
"feature": filter_features(features["feature"]),
|
73 |
}
|
74 |
+
elif "_type" in features["feature"] and features["feature"]["_type"] == "ClassLabel":
|
75 |
return {
|
76 |
+
"feature_type": features["_type"],
|
77 |
"dtype": "int32",
|
78 |
+
"feature": filter_features(features["feature"]),
|
79 |
}
|
80 |
else:
|
81 |
return dict(
|
82 |
+
[("feature_type", features["_type"])] + \
|
83 |
+
[(k, filter_features(v)) for k, v in features["feature"].items()]
|
84 |
)
|
85 |
+
elif features.get("_type", None) == 'ClassLabel':
|
86 |
return {
|
87 |
+
"feature_type": features["_type"],
|
88 |
"dtype": "int32",
|
89 |
+
"class_names": features["names"],
|
90 |
}
|
91 |
+
elif features.get("_type", None) in ['Translation', 'TranslationVariableLanguages']:
|
92 |
return {
|
93 |
+
"feature_type": features["_type"],
|
94 |
"dtype": "string",
|
95 |
+
"languages": features["languages"],
|
96 |
}
|
97 |
else:
|
98 |
+
return dict([(k, filter_features(v)) for k, v in features.items()])
|
99 |
|
100 |
|
101 |
@st.cache
|