awacke1 commited on
Commit
682cab2
·
verified ·
1 Parent(s): b184b04

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -74
app.py CHANGED
@@ -14,16 +14,6 @@ import tempfile
14
  import shutil
15
  import os
16
 
17
- # Search Terms
18
- example_search_terms = [
19
- {"id": "gpt-3", "emoji": "🤖"},
20
- {"id": "stable-diffusion", "emoji": "🎨"},
21
- {"id": "whisper", "emoji": "🗣️"},
22
- {"id": "bert", "emoji": "📖"},
23
- {"id": "resnet", "emoji": "🖼️"}
24
- ]
25
-
26
-
27
  # Initialize HuggingFace with access token
28
  def init_huggingface(token: str):
29
  """Initialize HuggingFace with access token."""
@@ -88,24 +78,6 @@ def SwarmyTime(data: List[Dict]) -> Dict:
88
  aggregated["unique_authors"] = len(aggregated["unique_authors"])
89
  return aggregated
90
 
91
- def search_and_aggregate(query, search_type, token, example_term):
92
- if example_term:
93
- query = example_term.split(" ")[1] # Extract the user ID from the button label
94
- df = search_hub(query, search_type, token)
95
- data = df.to_dict('records')
96
- aggregated = SwarmyTime(data)
97
- html_results = display_results(df)
98
- return [
99
- html_results,
100
- "Status: Ready to download",
101
- "",
102
- aggregated,
103
- search_type,
104
- data
105
- ]
106
-
107
-
108
-
109
  def search_hub(query: str, search_type: str, token: str = None) -> pd.DataFrame:
110
  """Search the Hugging Face Hub for models, datasets, or spaces."""
111
  api = HfApi(token=token)
@@ -279,13 +251,6 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
279
  Search and download models, datasets, and spaces from Hugging Face.
280
  """)
281
 
282
- with gr.Row():
283
- example_search_buttons = gr.Dataset(
284
- components=[gr.Button(value=f"{term['emoji']} {term['id']}", variant="secondary") for term in example_search_terms],
285
- label="Example Search Terms",
286
- samples=[]
287
- )
288
-
289
  with gr.Row():
290
  with gr.Column(scale=3):
291
  hf_token = gr.Textbox(
@@ -348,49 +313,22 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
348
  search_type,
349
  data
350
  ]
 
351
  async def handle_readme_download(data, token):
352
- if data:
353
- download_link, status = await download_all_readmes(data, token)
354
- return [f"Status: {status}", download_link]
355
- else:
356
  return ["Status: No results to download", ""]
357
-
 
 
358
  def handle_repo_download(data, search_type, token):
359
- if data:
360
- download_link, status = create_repo_zip(data, search_type, token)
361
- return [f"Status: {status}", download_link]
362
- else:
363
  return ["Status: No results to download", ""]
364
-
365
- #async def handle_readme_download(data, token):
366
- # if not data:
367
- # return ["Status: No results to download", ""]
368
- # download_link, status = await download_all_readmes(data, token)
369
- # return [f"Status: {status}", download_link]
370
-
371
- #def handle_repo_download(data, search_type, token):
372
- # if not data:
373
- # return ["Status: No results to download", ""]
374
- # download_link, status = create_repo_zip(data, search_type, token)
375
- # return [f"Status: {status}", download_link]
376
-
377
- #search_button.click(
378
- # search_and_aggregate,
379
- # inputs=[search_query, search_type, hf_token],
380
- # outputs=[
381
- # results_html,
382
- # download_status,
383
- # download_area,
384
- # aggregated_output,
385
- # search_type_state,
386
- # current_results
387
- # ]
388
- #)
389
-
390
 
391
  search_button.click(
392
  search_and_aggregate,
393
- inputs=[search_query, search_type, hf_token, example_search_buttons],
394
  outputs=[
395
  results_html,
396
  download_status,
@@ -398,10 +336,9 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
398
  aggregated_output,
399
  search_type_state,
400
  current_results
401
- ],
402
- call_after=lambda data: [handle_readme_download(data[-1], hf_token.value), handle_repo_download(data[-1], search_type.value, hf_token.value)]
403
  )
404
-
405
  download_readme_button.click(
406
  handle_readme_download,
407
  inputs=[current_results, hf_token],
 
14
  import shutil
15
  import os
16
 
 
 
 
 
 
 
 
 
 
 
17
  # Initialize HuggingFace with access token
18
  def init_huggingface(token: str):
19
  """Initialize HuggingFace with access token."""
 
78
  aggregated["unique_authors"] = len(aggregated["unique_authors"])
79
  return aggregated
80
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
81
  def search_hub(query: str, search_type: str, token: str = None) -> pd.DataFrame:
82
  """Search the Hugging Face Hub for models, datasets, or spaces."""
83
  api = HfApi(token=token)
 
251
  Search and download models, datasets, and spaces from Hugging Face.
252
  """)
253
 
 
 
 
 
 
 
 
254
  with gr.Row():
255
  with gr.Column(scale=3):
256
  hf_token = gr.Textbox(
 
313
  search_type,
314
  data
315
  ]
316
+
317
  async def handle_readme_download(data, token):
318
+ if not data:
 
 
 
319
  return ["Status: No results to download", ""]
320
+ download_link, status = await download_all_readmes(data, token)
321
+ return [f"Status: {status}", download_link]
322
+
323
  def handle_repo_download(data, search_type, token):
324
+ if not data:
 
 
 
325
  return ["Status: No results to download", ""]
326
+ download_link, status = create_repo_zip(data, search_type, token)
327
+ return [f"Status: {status}", download_link]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
328
 
329
  search_button.click(
330
  search_and_aggregate,
331
+ inputs=[search_query, search_type, hf_token],
332
  outputs=[
333
  results_html,
334
  download_status,
 
336
  aggregated_output,
337
  search_type_state,
338
  current_results
339
+ ]
 
340
  )
341
+
342
  download_readme_button.click(
343
  handle_readme_download,
344
  inputs=[current_results, hf_token],