Surn commited on
Commit
087a438
·
1 Parent(s): 638c558

Update storage

Browse files
Files changed (3) hide show
  1. utils/constants.py +14 -7
  2. utils/storage.md +3 -1
  3. utils/storage.py +8 -2
utils/constants.py CHANGED
@@ -67,11 +67,6 @@ SCALE_FACTOR = (12/5)
67
  TMPDIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'tmp')
68
  os.makedirs(TMPDIR, exist_ok=True)
69
 
70
- model_extensions = {".glb", ".gltf", ".obj", ".ply"}
71
- model_extensions_list = list(model_extensions)
72
- image_extensions = {".png", ".jpg", ".jpeg", ".webp"}
73
- image_extensions_list = list(image_extensions)
74
- upload_file_types = model_extensions_list + image_extensions_list
75
 
76
 
77
  PROMPTS = {
@@ -678,5 +673,17 @@ card_colors_alternating = [
678
  ]
679
 
680
  # Constants for URL shortener
681
- HF_REPO_ID = "Surn/Storage" # Or your desired repository
682
- SHORTENER_JSON_FILE = "shortener.json"
 
 
 
 
 
 
 
 
 
 
 
 
 
67
  TMPDIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'tmp')
68
  os.makedirs(TMPDIR, exist_ok=True)
69
 
 
 
 
 
 
70
 
71
 
72
  PROMPTS = {
 
673
  ]
674
 
675
  # Constants for URL shortener
676
+ HF_REPO_ID = os.getenv("HF_REPO_ID")
677
+ if not HF_REPO_ID:
678
+ HF_REPO_ID = "Surn/Storage" # Replace with your Hugging Face repository ID
679
+ SHORTENER_JSON_FILE = "shortener.json"
680
+
681
+ model_extensions = {".glb", ".gltf", ".obj", ".ply"}
682
+ model_extensions_list = list(model_extensions)
683
+ image_extensions = {".png", ".jpg", ".jpeg", ".webp"}
684
+ image_extensions_list = list(image_extensions)
685
+ audio_extensions = {".mp3", ".wav", ".ogg", ".flac", ".aac"}
686
+ audio_extensions_list = list(audio_extensions)
687
+ video_extensions = {".mp4"}
688
+ video_extensions_list = list(video_extensions)
689
+ upload_file_types = model_extensions_list + image_extensions_list + audio_extensions_list + video_extensions_list
utils/storage.md CHANGED
@@ -4,6 +4,8 @@ The `storage.py` module provides helper functions for:
4
  - Generating permalinks for 3D viewer projects.
5
  - Uploading files in batches to a Hugging Face repository.
6
  - Managing URL shortening by storing (short URL, full URL) pairs in a JSON file on the repository.
 
 
7
 
8
  ## Key Functions
9
 
@@ -53,7 +55,7 @@ files_for_permalink = [
53
  "local/path/to/heightmap.png",
54
  "local/path/to/image.png"
55
  ]
56
- repo_id = "Surn/Storage" # Make sure this is defined, e.g., from constants
57
  folder_name = "my_new_model_with_permalink"
58
 
59
  upload_result = upload_files_to_repo(
 
4
  - Generating permalinks for 3D viewer projects.
5
  - Uploading files in batches to a Hugging Face repository.
6
  - Managing URL shortening by storing (short URL, full URL) pairs in a JSON file on the repository.
7
+ - Retrieving full URLs from short URL IDs and vice versa.
8
+ - Handle specific file types for 3D models, images, video and audio.
9
 
10
  ## Key Functions
11
 
 
55
  "local/path/to/heightmap.png",
56
  "local/path/to/image.png"
57
  ]
58
+ repo_id = "Surn/Storage" # Make sure this is defined, e.g., from constants or environment variables
59
  folder_name = "my_new_model_with_permalink"
60
 
61
  upload_result = upload_files_to_repo(
utils/storage.py CHANGED
@@ -1,5 +1,5 @@
1
  # utils/storage.py
2
- __version__ = "0.1.0" # Added version
3
  import os
4
  import urllib.parse
5
  import tempfile
@@ -8,7 +8,7 @@ import json
8
  import base64
9
  from huggingface_hub import login, upload_folder, hf_hub_download, HfApi
10
  from huggingface_hub.utils import RepositoryNotFoundError, EntryNotFoundError
11
- from utils.constants import HF_API_TOKEN, upload_file_types, model_extensions, image_extensions, HF_REPO_ID, SHORTENER_JSON_FILE
12
  from typing import Any, Dict, List, Tuple, Union
13
 
14
  # see storage.md for detailed information about the storage module and its functions.
@@ -21,6 +21,8 @@ def generate_permalink(valid_files, base_url_external, permalink_viewer_url="sur
21
  """
22
  model_link = None
23
  images_links = []
 
 
24
  for f in valid_files:
25
  filename = os.path.basename(f)
26
  ext = os.path.splitext(filename)[1].lower()
@@ -29,6 +31,10 @@ def generate_permalink(valid_files, base_url_external, permalink_viewer_url="sur
29
  model_link = f"{base_url_external}/{filename}"
30
  elif ext in image_extensions:
31
  images_links.append(f"{base_url_external}/{filename}")
 
 
 
 
32
  if model_link and len(images_links) == 2:
33
  # Construct a permalink to the viewer project with query parameters.
34
  permalink_viewer_url = f"https://{permalink_viewer_url}/"
 
1
  # utils/storage.py
2
+ __version__ = "0.1.1" # Added version
3
  import os
4
  import urllib.parse
5
  import tempfile
 
8
  import base64
9
  from huggingface_hub import login, upload_folder, hf_hub_download, HfApi
10
  from huggingface_hub.utils import RepositoryNotFoundError, EntryNotFoundError
11
+ from utils.constants import HF_API_TOKEN, upload_file_types, model_extensions, image_extensions, audio_extensions, video_extensions, HF_REPO_ID, SHORTENER_JSON_FILE
12
  from typing import Any, Dict, List, Tuple, Union
13
 
14
  # see storage.md for detailed information about the storage module and its functions.
 
21
  """
22
  model_link = None
23
  images_links = []
24
+ audio_links = []
25
+ video_links = []
26
  for f in valid_files:
27
  filename = os.path.basename(f)
28
  ext = os.path.splitext(filename)[1].lower()
 
31
  model_link = f"{base_url_external}/{filename}"
32
  elif ext in image_extensions:
33
  images_links.append(f"{base_url_external}/{filename}")
34
+ elif ext in audio_extensions:
35
+ audio_links.append(f"{base_url_external}/{filename}")
36
+ elif ext in video_extensions:
37
+ video_links.append(f"{base_url_external}/{filename}")
38
  if model_link and len(images_links) == 2:
39
  # Construct a permalink to the viewer project with query parameters.
40
  permalink_viewer_url = f"https://{permalink_viewer_url}/"