someone-in-the-world Claude Sonnet 4.6 commited on
Commit
18a8688
·
1 Parent(s): dccc3f5

Add README.md upload to dataset repo for HF viewer image column rendering

Browse files

The HF viewer needs YAML frontmatter in README.md to identify image columns.
Generated from hf_meta so the schema stays in one place. Uploaded once on
first inference (skipped if README.md already exists).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

Files changed (1) hide show
  1. app.py +26 -0
app.py CHANGED
@@ -187,6 +187,22 @@ def update_dimensions_on_upload(image):
187
  return (nw // 8) * 8, (nh // 8) * 8
188
 
189
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
190
  def log_inference(pil_inputs, output_pil, prompt, seed, steps, guidance_scale,
191
  input_width, input_height, duration_seconds, success, error_message=""):
192
  if not HF_TOKEN or not DATASET_REPO:
@@ -267,6 +283,16 @@ def log_inference(pil_inputs, output_pil, prompt, seed, steps, guidance_scale,
267
  api = HfApi(token=HF_TOKEN)
268
  api.create_repo(repo_id=DATASET_REPO, repo_type="dataset", private=True, exist_ok=True)
269
 
 
 
 
 
 
 
 
 
 
 
270
  try:
271
  local_path = hf_hub_download(
272
  repo_id=DATASET_REPO, filename=path_in_repo,
 
187
  return (nw // 8) * 8, (nh // 8) * 8
188
 
189
 
190
+ def _readme_from_features(feats):
191
+ lines = ["---", "configs:", "- config_name: default",
192
+ " data_files:", " - split: train",
193
+ " path: data/*.parquet", " features:"]
194
+ for name, f in feats.items():
195
+ lines.append(f" - name: {name}")
196
+ if f.get("_type") == "Image":
197
+ lines.append(" dtype: image")
198
+ elif f.get("_type") == "Sequence" and f.get("feature", {}).get("_type") == "Image":
199
+ lines.append(" sequence: image")
200
+ else:
201
+ lines.append(f" dtype: {f.get('dtype', 'string')}")
202
+ lines.append("---")
203
+ return "\n".join(lines) + "\n"
204
+
205
+
206
  def log_inference(pil_inputs, output_pil, prompt, seed, steps, guidance_scale,
207
  input_width, input_height, duration_seconds, success, error_message=""):
208
  if not HF_TOKEN or not DATASET_REPO:
 
283
  api = HfApi(token=HF_TOKEN)
284
  api.create_repo(repo_id=DATASET_REPO, repo_type="dataset", private=True, exist_ok=True)
285
 
286
+ # Upload README.md once so the HF viewer knows the column types.
287
+ try:
288
+ hf_hub_download(repo_id=DATASET_REPO, filename="README.md",
289
+ repo_type="dataset", token=HF_TOKEN)
290
+ except Exception:
291
+ readme = _readme_from_features(_json.loads(hf_meta)["info"]["features"])
292
+ api.upload_file(path_or_fileobj=readme.encode(), path_in_repo="README.md",
293
+ repo_id=DATASET_REPO, repo_type="dataset")
294
+ print("[log] uploaded README.md with feature schema")
295
+
296
  try:
297
  local_path = hf_hub_download(
298
  repo_id=DATASET_REPO, filename=path_in_repo,