Spaces:
Running
Running
Deploy (see actual commits on https://github.com/mlcommons/croissant).
Browse files- core/state.py +3 -0
- events/metadata.py +27 -0
- views/metadata.py +45 -0
core/state.py
CHANGED
@@ -183,8 +183,11 @@ class Metadata:
|
|
183 |
name: str = ""
|
184 |
description: str | None = None
|
185 |
citation: str | None = None
|
|
|
|
|
186 |
data_biases: str | None = None
|
187 |
data_collection: str | None = None
|
|
|
188 |
license: str | None = ""
|
189 |
personal_sensitive_information: str | None = None
|
190 |
url: str = ""
|
|
|
183 |
name: str = ""
|
184 |
description: str | None = None
|
185 |
citation: str | None = None
|
186 |
+
conforms_to: str | None = None
|
187 |
+
creators: list[mlc.PersonOrOrganization] = dataclasses.field(default_factory=list)
|
188 |
data_biases: str | None = None
|
189 |
data_collection: str | None = None
|
190 |
+
date_published: datetime.datetime | None = None
|
191 |
license: str | None = ""
|
192 |
personal_sensitive_information: str | None = None
|
193 |
url: str = ""
|
events/metadata.py
CHANGED
@@ -1,9 +1,11 @@
|
|
|
|
1 |
import enum
|
2 |
|
3 |
import streamlit as st
|
4 |
|
5 |
from core.names import find_unique_name
|
6 |
from core.state import Metadata
|
|
|
7 |
|
8 |
# List from:
|
9 |
LICENSES_URL = "https://huggingface.co/docs/hub/repositories-licenses"
|
@@ -90,7 +92,9 @@ class MetadataEvent(enum.Enum):
|
|
90 |
"""Event that triggers a metadata change."""
|
91 |
|
92 |
NAME = "NAME"
|
|
|
93 |
DESCRIPTION = "DESCRIPTION"
|
|
|
94 |
URL = "URL"
|
95 |
LICENSE = "LICENSE"
|
96 |
CITATION = "CITATION"
|
@@ -98,11 +102,17 @@ class MetadataEvent(enum.Enum):
|
|
98 |
DATA_BIASES = "DATA_BIASES"
|
99 |
DATA_COLLECTION = "DATA_COLLECTION"
|
100 |
PERSONAL_SENSITIVE_INFORMATION = "PERSONAL_SENSITIVE_INFORMATION"
|
|
|
|
|
|
|
|
|
101 |
|
102 |
|
103 |
def handle_metadata_change(event: MetadataEvent, metadata: Metadata, key: str):
|
104 |
if event == MetadataEvent.NAME:
|
105 |
metadata.name = find_unique_name(set(), st.session_state[key])
|
|
|
|
|
106 |
elif event == MetadataEvent.DESCRIPTION:
|
107 |
metadata.description = st.session_state[key]
|
108 |
elif event == MetadataEvent.LICENSE:
|
@@ -119,3 +129,20 @@ def handle_metadata_change(event: MetadataEvent, metadata: Metadata, key: str):
|
|
119 |
metadata.data_collection = st.session_state[key]
|
120 |
elif event == MetadataEvent.PERSONAL_SENSITIVE_INFORMATION:
|
121 |
metadata.personal_sensitive_information = st.session_state[key]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import datetime
|
2 |
import enum
|
3 |
|
4 |
import streamlit as st
|
5 |
|
6 |
from core.names import find_unique_name
|
7 |
from core.state import Metadata
|
8 |
+
import mlcroissant as mlc
|
9 |
|
10 |
# List from:
|
11 |
LICENSES_URL = "https://huggingface.co/docs/hub/repositories-licenses"
|
|
|
92 |
"""Event that triggers a metadata change."""
|
93 |
|
94 |
NAME = "NAME"
|
95 |
+
CONFORMS_TO = "CONFORMS_TO"
|
96 |
DESCRIPTION = "DESCRIPTION"
|
97 |
+
DATE_PUBLISHED = "DATE_PUBLISHED"
|
98 |
URL = "URL"
|
99 |
LICENSE = "LICENSE"
|
100 |
CITATION = "CITATION"
|
|
|
102 |
DATA_BIASES = "DATA_BIASES"
|
103 |
DATA_COLLECTION = "DATA_COLLECTION"
|
104 |
PERSONAL_SENSITIVE_INFORMATION = "PERSONAL_SENSITIVE_INFORMATION"
|
105 |
+
CREATOR_ADD = "CREATOR_ADD"
|
106 |
+
CREATOR_NAME = "CREATOR_NAME"
|
107 |
+
CREATOR_URL = "CREATOR_URL"
|
108 |
+
CREATOR_REMOVE = "CREATOR_REMOVE"
|
109 |
|
110 |
|
111 |
def handle_metadata_change(event: MetadataEvent, metadata: Metadata, key: str):
|
112 |
if event == MetadataEvent.NAME:
|
113 |
metadata.name = find_unique_name(set(), st.session_state[key])
|
114 |
+
if event == MetadataEvent.CONFORMS_TO:
|
115 |
+
metadata.conforms_to = st.session_state[key]
|
116 |
elif event == MetadataEvent.DESCRIPTION:
|
117 |
metadata.description = st.session_state[key]
|
118 |
elif event == MetadataEvent.LICENSE:
|
|
|
129 |
metadata.data_collection = st.session_state[key]
|
130 |
elif event == MetadataEvent.PERSONAL_SENSITIVE_INFORMATION:
|
131 |
metadata.personal_sensitive_information = st.session_state[key]
|
132 |
+
elif event == MetadataEvent.DATE_PUBLISHED:
|
133 |
+
date = st.session_state[key]
|
134 |
+
metadata.date_published = datetime.datetime(date.year, date.month, date.day)
|
135 |
+
elif event == MetadataEvent.CREATOR_ADD:
|
136 |
+
metadata.creators = [mlc.PersonOrOrganization()]
|
137 |
+
elif event == MetadataEvent.CREATOR_REMOVE:
|
138 |
+
metadata.creators = []
|
139 |
+
elif event == MetadataEvent.CREATOR_NAME:
|
140 |
+
if metadata.creators:
|
141 |
+
metadata.creators[0].name = st.session_state[key]
|
142 |
+
else:
|
143 |
+
metadata.creators = [mlc.PersonOrOrganization(name=st.session_state[key])]
|
144 |
+
elif event == MetadataEvent.CREATOR_URL:
|
145 |
+
if metadata.creators:
|
146 |
+
metadata.creators[0].url = st.session_state[key]
|
147 |
+
else:
|
148 |
+
metadata.creators = [mlc.PersonOrOrganization(url=st.session_state[key])]
|
views/metadata.py
CHANGED
@@ -106,3 +106,48 @@ def _render_generic_metadata(metadata: Metadata):
|
|
106 |
on_change=handle_metadata_change,
|
107 |
args=(MetadataEvent.CITATION, metadata, key),
|
108 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
106 |
on_change=handle_metadata_change,
|
107 |
args=(MetadataEvent.CITATION, metadata, key),
|
108 |
)
|
109 |
+
key = "metadata-date-published"
|
110 |
+
st.date_input(
|
111 |
+
label="Date of first broadcast/publication.",
|
112 |
+
key=key,
|
113 |
+
value=metadata.date_published,
|
114 |
+
on_change=handle_metadata_change,
|
115 |
+
args=(MetadataEvent.DATE_PUBLISHED, metadata, key),
|
116 |
+
)
|
117 |
+
if metadata.creators:
|
118 |
+
creator = metadata.creators[0]
|
119 |
+
col1, col2, col3 = st.columns([1, 1, 1])
|
120 |
+
key = "metadata-creator-name"
|
121 |
+
col1.text_input(
|
122 |
+
label="Creator name",
|
123 |
+
key=key,
|
124 |
+
value=creator.name,
|
125 |
+
on_change=handle_metadata_change,
|
126 |
+
placeholder="A person or an organization",
|
127 |
+
args=(MetadataEvent.CREATOR_NAME, metadata, key),
|
128 |
+
)
|
129 |
+
key = "metadata-creator-url"
|
130 |
+
col2.text_input(
|
131 |
+
label="Creator URL",
|
132 |
+
key=key,
|
133 |
+
value=creator.url,
|
134 |
+
placeholder="https://mlcommons.org",
|
135 |
+
on_change=handle_metadata_change,
|
136 |
+
args=(MetadataEvent.CREATOR_URL, metadata, key),
|
137 |
+
)
|
138 |
+
key = "metadata-creator-remove"
|
139 |
+
col3.button(
|
140 |
+
"✖️",
|
141 |
+
key=key,
|
142 |
+
help="Remove the creator",
|
143 |
+
on_click=handle_metadata_change,
|
144 |
+
args=(MetadataEvent.CREATOR_REMOVE, metadata, key),
|
145 |
+
)
|
146 |
+
else:
|
147 |
+
key = "metadata-add-creator"
|
148 |
+
st.button(
|
149 |
+
label="✚ Add a creator",
|
150 |
+
key=key,
|
151 |
+
on_click=handle_metadata_change,
|
152 |
+
args=(MetadataEvent.CREATOR_ADD, metadata, key),
|
153 |
+
)
|