abidlabs HF staff commited on
Commit
0ba7762
1 Parent(s): 9ebf7b6

Update maker.py

Browse files
Files changed (1) hide show
  1. maker.py +13 -1
maker.py CHANGED
@@ -3,7 +3,6 @@ import requests
3
  import json
4
  import huggingface_hub
5
  from huggingface_hub import HfApi
6
- from gradio_client.utils import strip_invalid_filename_characters
7
 
8
  HF_TOKEN = "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"
9
  HEADERS = {"Authorization": f"Bearer {HF_TOKEN}"}
@@ -140,6 +139,19 @@ def test_preview_chatbot(message, history, system_prompt):
140
  return response
141
 
142
 
 
 
 
 
 
 
 
 
 
 
 
 
 
143
 
144
  constants = """
145
  SYSTEM_PROMPT = "{}"
 
3
  import json
4
  import huggingface_hub
5
  from huggingface_hub import HfApi
 
6
 
7
  HF_TOKEN = "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"
8
  HEADERS = {"Authorization": f"Bearer {HF_TOKEN}"}
 
139
  return response
140
 
141
 
142
+ def strip_invalid_filename_characters(filename: str, max_bytes: int = 200) -> str:
143
+ """Strips invalid characters from a filename and ensures that the file_length is less than `max_bytes` bytes."""
144
+ filename = filename.replace(" ", "-")
145
+ filename = "".join([char for char in filename if char.isalnum() or char in "_-"])
146
+ filename_len = len(filename.encode())
147
+ if filename_len > max_bytes:
148
+ while filename_len > max_bytes:
149
+ if len(filename) == 0:
150
+ break
151
+ filename = filename[:-1]
152
+ filename_len = len(filename.encode())
153
+ return filename
154
+
155
 
156
  constants = """
157
  SYSTEM_PROMPT = "{}"