davanstrien HF staff commited on
Commit
a4421c2
1 Parent(s): c328472
Files changed (1) hide show
  1. app.py +24 -6
app.py CHANGED
@@ -10,7 +10,7 @@ def extract_collection_id(input_text):
10
  return url_match[1]
11
 
12
  # Check if input is already in the correct format
13
- return input_text if re.match(r"^[\w-]+/[\w-]+$", input_text) else None
14
 
15
 
16
  def load_collection():
@@ -35,14 +35,12 @@ def load_collection():
35
 
36
  def display_dataset(dataset_ids, index):
37
  dataset_id = dataset_ids[index]
38
- return gr.HTML(
39
- f"""<iframe
40
  src="https://huggingface.co/datasets/{dataset_id}/embed/viewer"
41
  frameborder="0"
42
  width="100%"
43
  height="560px"
44
- ></iframe>"""
45
- )
46
 
47
 
48
  def navigate_dataset(dataset_ids, index, direction):
@@ -53,11 +51,31 @@ def navigate_dataset(dataset_ids, index, direction):
53
  )
54
 
55
 
 
 
 
 
 
56
  try:
57
  dataset_ids, collection_id = load_collection()
 
58
 
59
  with gr.Blocks() as demo:
60
- gr.Markdown(f"<h1>Dataset Viewer for Collection: {collection_id}</h1>")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
61
 
62
  index_state = gr.State(value=0)
63
 
 
10
  return url_match[1]
11
 
12
  # Check if input is already in the correct format
13
+ return input_text if re.match(r"^[\w-]+/[\w-]+", input_text) else None
14
 
15
 
16
  def load_collection():
 
35
 
36
  def display_dataset(dataset_ids, index):
37
  dataset_id = dataset_ids[index]
38
+ return gr.HTML(f"""<iframe
 
39
  src="https://huggingface.co/datasets/{dataset_id}/embed/viewer"
40
  frameborder="0"
41
  width="100%"
42
  height="560px"
43
+ ></iframe>""")
 
44
 
45
 
46
  def navigate_dataset(dataset_ids, index, direction):
 
51
  )
52
 
53
 
54
+ def get_display_name(collection_id):
55
+ # Strip out the extra ID part of the name
56
+ return re.sub(r"-[a-f0-9]{32}$", "", collection_id)
57
+
58
+
59
  try:
60
  dataset_ids, collection_id = load_collection()
61
+ display_name = get_display_name(collection_id)
62
 
63
  with gr.Blocks() as demo:
64
+ gr.Markdown(f"<h1>Dataset Viewer for Collection: {display_name}</h1>")
65
+ gr.Markdown(
66
+ f"[View full collection on Hugging Face](https://huggingface.co/collections/{collection_id})"
67
+ )
68
+
69
+ gr.Markdown("""
70
+ This app allows you to browse and view datasets from a specific Hugging Face collection.
71
+ Use the 'Previous' and 'Next' buttons to navigate through the datasets in the collection.
72
+
73
+ **Note**: This space is currently set up to display datasets from a specific collection.
74
+ If you'd like to use it for a different collection:
75
+ 1. Duplicate this space
76
+ 2. In your duplicated space, set the `COLLECTION_SLUG_OR_URL` environment variable to your desired collection ID or URL
77
+ 3. Your new space will then display datasets from your chosen collection!
78
+ """)
79
 
80
  index_state = gr.State(value=0)
81