Commit
•
9a0fc73
1
Parent(s):
13c4458
add urls for prs to summary
Browse files
app.py
CHANGED
@@ -21,6 +21,7 @@ from huggingface_hub.utils import HfHubHTTPError, RepositoryNotFoundError
|
|
21 |
from tqdm.asyncio import tqdm as atqdm
|
22 |
from tqdm.auto import tqdm
|
23 |
import random
|
|
|
24 |
|
25 |
cache.setup("mem://")
|
26 |
|
@@ -48,8 +49,8 @@ def get_models(user_or_org):
|
|
48 |
iter(
|
49 |
list_models(
|
50 |
filter=model_filter,
|
51 |
-
sort="downloads",
|
52 |
-
direction=-1,
|
53 |
cardData=True,
|
54 |
full=True,
|
55 |
)
|
@@ -185,6 +186,16 @@ For a hands-on example of how such metadata can play a pivotal role in mapping m
|
|
185 |
This PR was requested via the [Librarian Bot](https://huggingface.co/librarian-bot) [metadata request service](https://huggingface.co/spaces/librarian-bots/metadata_request_service) by request of [{opened_by}](https://huggingface.co/{opened_by})
|
186 |
"""
|
187 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
188 |
def update_metadata(metadata_payload: Dict[str, str], user_making_request=None):
|
189 |
metadata_payload["opened_pr"] = False
|
190 |
regex_match = metadata_payload["match"]
|
@@ -214,7 +225,7 @@ def update_metadata(metadata_payload: Dict[str, str], user_making_request=None):
|
|
214 |
logger.info("previously opened PR to add base_model tag")
|
215 |
metadata_payload["opened_pr"] = True
|
216 |
return metadata_payload
|
217 |
-
model_card.push_to_hub(
|
218 |
repo_id,
|
219 |
token=token,
|
220 |
repo_type="model",
|
@@ -223,6 +234,9 @@ def update_metadata(metadata_payload: Dict[str, str], user_making_request=None):
|
|
223 |
commit_description=template,
|
224 |
)
|
225 |
metadata_payload["opened_pr"] = True
|
|
|
|
|
|
|
226 |
return metadata_payload
|
227 |
except HfHubHTTPError:
|
228 |
return metadata_payload
|
@@ -246,7 +260,24 @@ def open_prs(profile: gr.OAuthProfile | None, user_or_org: str = None):
|
|
246 |
)
|
247 |
except Exception as e:
|
248 |
logger.error(e)
|
249 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
250 |
|
251 |
|
252 |
# description_text = """
|
@@ -310,7 +341,8 @@ For a hands-on example of how such metadata can play a pivotal role in mapping m
|
|
310 |
|
311 |
with gr.Blocks() as demo:
|
312 |
gr.HTML(
|
313 |
-
"<h1 style='text-align:center;'><span>🤖</span> Librarian Bot Metadata
|
|
|
314 |
)
|
315 |
gr.Markdown(
|
316 |
"""<div style='text-align:center;'><img src='https://huggingface.co/spaces/davanstrien/librarian_bot_request_metadata/resolve/main/image.png' style='display:block;margin-left:auto;margin-right:auto;width:150px;'></div><p>"""
|
|
|
21 |
from tqdm.asyncio import tqdm as atqdm
|
22 |
from tqdm.auto import tqdm
|
23 |
import random
|
24 |
+
from huggingface_hub import get_discussion_details
|
25 |
|
26 |
cache.setup("mem://")
|
27 |
|
|
|
49 |
iter(
|
50 |
list_models(
|
51 |
filter=model_filter,
|
52 |
+
# sort="downloads",
|
53 |
+
# direction=-1,
|
54 |
cardData=True,
|
55 |
full=True,
|
56 |
)
|
|
|
186 |
This PR was requested via the [Librarian Bot](https://huggingface.co/librarian-bot) [metadata request service](https://huggingface.co/spaces/librarian-bots/metadata_request_service) by request of [{opened_by}](https://huggingface.co/{opened_by})
|
187 |
"""
|
188 |
|
189 |
+
|
190 |
+
PR_FROM_COMMIT_PATTERN = re.compile(r"pr%2F(\d{1,3})/README.md")
|
191 |
+
|
192 |
+
|
193 |
+
def get_pr_url_from_commit_url(commit_url, repo_id):
|
194 |
+
re_match = re.search(PR_FROM_COMMIT_PATTERN, commit_url)
|
195 |
+
pr_number = int(re_match.groups()[0])
|
196 |
+
return get_discussion_details(repo_id=repo_id, discussion_num=pr_number).url
|
197 |
+
|
198 |
+
|
199 |
def update_metadata(metadata_payload: Dict[str, str], user_making_request=None):
|
200 |
metadata_payload["opened_pr"] = False
|
201 |
regex_match = metadata_payload["match"]
|
|
|
225 |
logger.info("previously opened PR to add base_model tag")
|
226 |
metadata_payload["opened_pr"] = True
|
227 |
return metadata_payload
|
228 |
+
commit_url = model_card.push_to_hub(
|
229 |
repo_id,
|
230 |
token=token,
|
231 |
repo_type="model",
|
|
|
234 |
commit_description=template,
|
235 |
)
|
236 |
metadata_payload["opened_pr"] = True
|
237 |
+
metadata_payload["pr_url"] = get_pr_url_from_commit_url(
|
238 |
+
commit_url=commit_url, repo_id=repo_id
|
239 |
+
)
|
240 |
return metadata_payload
|
241 |
except HfHubHTTPError:
|
242 |
return metadata_payload
|
|
|
260 |
)
|
261 |
except Exception as e:
|
262 |
logger.error(e)
|
263 |
+
if not results:
|
264 |
+
return "No PRs to open"
|
265 |
+
if not any(r["opened_pr"] for r in results):
|
266 |
+
return "No PRs to open"
|
267 |
+
message = "# ✨ Librarian Bot Metadata Request Summary ✨ \n\n"
|
268 |
+
message += (
|
269 |
+
f"Librarian bot has {len([r for r in results if r['opened_pr']])} PRs open"
|
270 |
+
" against your repos \n\n"
|
271 |
+
)
|
272 |
+
message += "# URLs for newly opened PRs\n"
|
273 |
+
for result in results:
|
274 |
+
if result["opened_pr"]:
|
275 |
+
print(result)
|
276 |
+
try:
|
277 |
+
message += f"- {result['pr_url']}\n"
|
278 |
+
except KeyError:
|
279 |
+
continue
|
280 |
+
return message
|
281 |
|
282 |
|
283 |
# description_text = """
|
|
|
341 |
|
342 |
with gr.Blocks() as demo:
|
343 |
gr.HTML(
|
344 |
+
"<h1 style='text-align:center;'><span>🤖</span> Librarian Bot Metadata"
|
345 |
+
" Request Service <span>🤖</span></h1>"
|
346 |
)
|
347 |
gr.Markdown(
|
348 |
"""<div style='text-align:center;'><img src='https://huggingface.co/spaces/davanstrien/librarian_bot_request_metadata/resolve/main/image.png' style='display:block;margin-left:auto;margin-right:auto;width:150px;'></div><p>"""
|