Spaces:
Running
Running
idk something like this (#49)
Browse files- idk something like this (b20e2afb02e85352f6b0a03cc46a009870a51870)
Co-authored-by: Noa Roggendorff <[email protected]>
app.py
CHANGED
|
@@ -76,6 +76,20 @@ def unzip_file(file):
|
|
| 76 |
def progress_bar(total, current):
|
| 77 |
return "[" + "=" * int(current / total * 20) + ">" + " " * (20 - int(current / total * 20)) + "] " + str(int(current / total * 100)) + "%"
|
| 78 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 79 |
def download_from_url(url, name=None):
|
| 80 |
if name is None:
|
| 81 |
raise ValueError("The model name must be provided")
|
|
@@ -84,6 +98,8 @@ def download_from_url(url, name=None):
|
|
| 84 |
if "huggingface" not in url:
|
| 85 |
return ["The URL must be from huggingface", "Failed", "Failed"]
|
| 86 |
filename = os.path.join(TEMP_DIR, MODEL_PREFIX + str(random.randint(1, 1000)) + ".zip")
|
|
|
|
|
|
|
| 87 |
response = requests.get(url)
|
| 88 |
total = int(response.headers.get('content-length', 0))
|
| 89 |
if total > 500000000:
|
|
|
|
| 76 |
def progress_bar(total, current):
|
| 77 |
return "[" + "=" * int(current / total * 20) + ">" + " " * (20 - int(current / total * 20)) + "] " + str(int(current / total * 100)) + "%"
|
| 78 |
|
| 79 |
+
def contains_bad_word(text, bad_words):
|
| 80 |
+
text_lower = text.lower()
|
| 81 |
+
for word in bad_words:
|
| 82 |
+
if word.lower() in text_lower:
|
| 83 |
+
return True
|
| 84 |
+
return False
|
| 85 |
+
|
| 86 |
+
bad_words = ['puttana', 'whore', 'badword3', 'badword4']
|
| 87 |
+
|
| 88 |
+
class BadWordError(Exception):
|
| 89 |
+
def __init__(self, msg):
|
| 90 |
+
super().__init__(msg)
|
| 91 |
+
self.word = word
|
| 92 |
+
|
| 93 |
def download_from_url(url, name=None):
|
| 94 |
if name is None:
|
| 95 |
raise ValueError("The model name must be provided")
|
|
|
|
| 98 |
if "huggingface" not in url:
|
| 99 |
return ["The URL must be from huggingface", "Failed", "Failed"]
|
| 100 |
filename = os.path.join(TEMP_DIR, MODEL_PREFIX + str(random.randint(1, 1000)) + ".zip")
|
| 101 |
+
if contains_bad_word(url, bad_words):
|
| 102 |
+
return BadWordError("The filename has a bad word.")
|
| 103 |
response = requests.get(url)
|
| 104 |
total = int(response.headers.get('content-length', 0))
|
| 105 |
if total > 500000000:
|