marcenacp commited on
Commit
36f4fe3
1 Parent(s): bc133ae

Deploy (see actual commits on https://github.com/mlcommons/croissant).

Browse files
Files changed (4) hide show
  1. core/state.py +2 -0
  2. events/metadata.py +22 -0
  3. views/metadata.py +44 -0
  4. views/splash.py +1 -0
core/state.py CHANGED
@@ -183,8 +183,10 @@ 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
+ creator: mlc.PersonOrOrganization | None = None
187
  data_biases: str | None = None
188
  data_collection: str | None = None
189
+ date_published: datetime.datetime | None = None
190
  license: str | None = ""
191
  personal_sensitive_information: str | None = None
192
  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"
@@ -91,6 +93,7 @@ class MetadataEvent(enum.Enum):
91
 
92
  NAME = "NAME"
93
  DESCRIPTION = "DESCRIPTION"
 
94
  URL = "URL"
95
  LICENSE = "LICENSE"
96
  CITATION = "CITATION"
@@ -98,6 +101,10 @@ 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):
@@ -119,3 +126,18 @@ 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"
 
93
 
94
  NAME = "NAME"
95
  DESCRIPTION = "DESCRIPTION"
96
+ DATE_PUBLISHED = "DATE_PUBLISHED"
97
  URL = "URL"
98
  LICENSE = "LICENSE"
99
  CITATION = "CITATION"
 
101
  DATA_BIASES = "DATA_BIASES"
102
  DATA_COLLECTION = "DATA_COLLECTION"
103
  PERSONAL_SENSITIVE_INFORMATION = "PERSONAL_SENSITIVE_INFORMATION"
104
+ CREATOR_ADD = "CREATOR_ADD"
105
+ CREATOR_NAME = "CREATOR_NAME"
106
+ CREATOR_URL = "CREATOR_URL"
107
+ CREATOR_REMOVE = "CREATOR_REMOVE"
108
 
109
 
110
  def handle_metadata_change(event: MetadataEvent, metadata: Metadata, key: str):
 
126
  metadata.data_collection = st.session_state[key]
127
  elif event == MetadataEvent.PERSONAL_SENSITIVE_INFORMATION:
128
  metadata.personal_sensitive_information = st.session_state[key]
129
+ elif event == MetadataEvent.DATE_PUBLISHED:
130
+ date = st.session_state[key]
131
+ metadata.date_published = datetime.datetime(date.year, date.month, date.day)
132
+ elif event == MetadataEvent.CREATOR_ADD:
133
+ metadata.creator = mlc.PersonOrOrganization()
134
+ elif event == MetadataEvent.CREATOR_REMOVE:
135
+ metadata.creator = None
136
+ elif event == MetadataEvent.CREATOR_NAME:
137
+ if not metadata.creator:
138
+ metadata.creator = mlc.PersonOrOrganization()
139
+ metadata.creator.name = st.session_state[key]
140
+ elif event == MetadataEvent.CREATOR_URL:
141
+ if not metadata.creator:
142
+ metadata.creator = mlc.PersonOrOrganization()
143
+ metadata.creator.url = st.session_state[key]
views/metadata.py CHANGED
@@ -106,3 +106,47 @@ 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.creator:
118
+ col1, col2, col3 = st.columns([1, 1, 1])
119
+ key = "metadata-creator-name"
120
+ col1.text_input(
121
+ label="Creator name",
122
+ key=key,
123
+ value=metadata.creator.name,
124
+ on_change=handle_metadata_change,
125
+ placeholder="A person or an organization",
126
+ args=(MetadataEvent.CREATOR_NAME, metadata, key),
127
+ )
128
+ key = "metadata-creator-url"
129
+ col2.text_input(
130
+ label="Creator URL",
131
+ key=key,
132
+ value=metadata.creator.url,
133
+ placeholder="https://mlcommons.org",
134
+ on_change=handle_metadata_change,
135
+ args=(MetadataEvent.CREATOR_URL, metadata, key),
136
+ )
137
+ key = "metadata-creator-remove"
138
+ col3.button(
139
+ "✖️",
140
+ key=key,
141
+ help="Remove the creator",
142
+ on_click=handle_metadata_change,
143
+ args=(MetadataEvent.CREATOR_REMOVE, metadata, key),
144
+ )
145
+ else:
146
+ key = "metadata-add-creator"
147
+ st.button(
148
+ label="✚ Add a creator",
149
+ key=key,
150
+ on_click=handle_metadata_change,
151
+ args=(MetadataEvent.CREATOR_ADD, metadata, key),
152
+ )
views/splash.py CHANGED
@@ -110,6 +110,7 @@ def render_splash():
110
  metadata = mlc.Metadata.from_json(mlc.Issues(), json, None)
111
  st.session_state[Metadata] = Metadata.from_canonical(metadata)
112
  save_current_project()
 
113
  except Exception:
114
  st.error(f"Malformed JSON: {json}")
115
  elif url:
 
110
  metadata = mlc.Metadata.from_json(mlc.Issues(), json, None)
111
  st.session_state[Metadata] = Metadata.from_canonical(metadata)
112
  save_current_project()
113
+ st.rerun()
114
  except Exception:
115
  st.error(f"Malformed JSON: {json}")
116
  elif url: