Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -3,39 +3,46 @@ import gradio as gr
|
|
3 |
|
4 |
HF_API_BASE = "https://huggingface.co/api/models"
|
5 |
SEARCH_TERMS = [
|
6 |
-
"
|
7 |
-
"
|
8 |
-
"KingOfPop", "King_Of_Pop", "King-Of-Pop", "kingofpop"
|
9 |
]
|
10 |
|
11 |
def get_models(user: str):
|
12 |
url = f"{HF_API_BASE}?search={user}"
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
|
|
|
|
|
|
17 |
return []
|
18 |
|
19 |
def check_zip_files(model_id: str):
|
20 |
-
url = f"https://huggingface.co/{model_id}/tree/main"
|
21 |
-
|
22 |
zip_links = []
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
|
|
|
|
30 |
zip_links.append(f"https://huggingface.co/{model_id}/resolve/main/{file['path']}?download=true")
|
|
|
|
|
31 |
return zip_links
|
32 |
|
33 |
def search_huggingface_zips(user: str):
|
34 |
models = get_models(user)
|
35 |
all_links = []
|
36 |
for model in models:
|
37 |
-
model_id = model
|
38 |
-
|
|
|
39 |
return "\n".join(all_links) if all_links else "No ZIP files found."
|
40 |
|
41 |
demo = gr.Interface(
|
@@ -46,4 +53,4 @@ demo = gr.Interface(
|
|
46 |
description="Enter a Hugging Face username to search for ZIP files related to Michael Jackson.",
|
47 |
)
|
48 |
|
49 |
-
demo.launch()
|
|
|
3 |
|
4 |
HF_API_BASE = "https://huggingface.co/api/models"
|
5 |
SEARCH_TERMS = [
|
6 |
+
"mj", "michaeljackson", "michael_jackson", "michael-jackson", "mjackson",
|
7 |
+
"m_jackson", "m-jackson", "kingofpop", "king_of_pop", "king-of-pop"
|
|
|
8 |
]
|
9 |
|
10 |
def get_models(user: str):
|
11 |
url = f"{HF_API_BASE}?search={user}"
|
12 |
+
headers = {"User-Agent": "Mozilla/5.0"}
|
13 |
+
try:
|
14 |
+
response = requests.get(url, headers=headers)
|
15 |
+
response.raise_for_status()
|
16 |
+
return response.json() if response.text else []
|
17 |
+
except requests.exceptions.RequestException as e:
|
18 |
+
print(f"Error fetching models: {e}")
|
19 |
return []
|
20 |
|
21 |
def check_zip_files(model_id: str):
|
22 |
+
url = f"https://huggingface.co/api/models/{model_id}/tree/main"
|
23 |
+
headers = {"User-Agent": "Mozilla/5.0"}
|
24 |
zip_links = []
|
25 |
+
try:
|
26 |
+
response = requests.get(url, headers=headers)
|
27 |
+
response.raise_for_status()
|
28 |
+
if response.text:
|
29 |
+
files = response.json()
|
30 |
+
for file in files:
|
31 |
+
file_path = file.get('path', '').lower()
|
32 |
+
if file.get('type') == 'file' and file_path.endswith('.zip'):
|
33 |
+
if any(term in file_path or term in model_id.lower() for term in SEARCH_TERMS):
|
34 |
zip_links.append(f"https://huggingface.co/{model_id}/resolve/main/{file['path']}?download=true")
|
35 |
+
except requests.exceptions.RequestException as e:
|
36 |
+
print(f"Error accessing model {model_id}: {e}")
|
37 |
return zip_links
|
38 |
|
39 |
def search_huggingface_zips(user: str):
|
40 |
models = get_models(user)
|
41 |
all_links = []
|
42 |
for model in models:
|
43 |
+
model_id = model.get('modelId', '')
|
44 |
+
if model_id and any(term in model_id.lower() for term in SEARCH_TERMS):
|
45 |
+
all_links.extend(check_zip_files(model_id))
|
46 |
return "\n".join(all_links) if all_links else "No ZIP files found."
|
47 |
|
48 |
demo = gr.Interface(
|
|
|
53 |
description="Enter a Hugging Face username to search for ZIP files related to Michael Jackson.",
|
54 |
)
|
55 |
|
56 |
+
demo.launch()
|