Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -289,6 +289,31 @@ def get_huggingface_safetensors(link):
|
|
289 |
|
290 |
def check_custom_model(link):
|
291 |
print(f"Checking a custom model on: {link}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
292 |
if link.startswith("https://"):
|
293 |
if link.startswith("https://huggingface.co") or link.startswith("https://www.huggingface.co"):
|
294 |
link_split = link.split("huggingface.co/")
|
|
|
289 |
|
290 |
def check_custom_model(link):
|
291 |
print(f"Checking a custom model on: {link}")
|
292 |
+
|
293 |
+
if link.endswith('.safetensors'):
|
294 |
+
if 'huggingface.co' in link:
|
295 |
+
parts = link.split('/')
|
296 |
+
try:
|
297 |
+
hf_index = parts.index('huggingface.co')
|
298 |
+
username = parts[hf_index + 1]
|
299 |
+
repo_name = parts[hf_index + 2]
|
300 |
+
repo = f"{username}/{repo_name}"
|
301 |
+
|
302 |
+
safetensors_name = parts[-1]
|
303 |
+
|
304 |
+
try:
|
305 |
+
model_card = ModelCard.load(repo)
|
306 |
+
trigger_word = model_card.data.get("instance_prompt", "")
|
307 |
+
image_path = model_card.data.get("widget", [{}])[0].get("output", {}).get("url", None)
|
308 |
+
image_url = f"https://huggingface.co/{repo}/resolve/main/{image_path}" if image_path else None
|
309 |
+
except:
|
310 |
+
trigger_word = ""
|
311 |
+
image_url = None
|
312 |
+
|
313 |
+
return repo_name, repo, safetensors_name, trigger_word, image_url
|
314 |
+
except:
|
315 |
+
raise Exception("Invalid safetensors URL format")
|
316 |
+
|
317 |
if link.startswith("https://"):
|
318 |
if link.startswith("https://huggingface.co") or link.startswith("https://www.huggingface.co"):
|
319 |
link_split = link.split("huggingface.co/")
|