awacke1 commited on
Commit
4bfe927
·
verified ·
1 Parent(s): e5c4bb6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +44 -23
app.py CHANGED
@@ -193,23 +193,49 @@ def SwarmyTime(data: List[Dict]) -> Dict:
193
  aggregated["unique_authors"] = len(aggregated["unique_authors"])
194
  return aggregated
195
 
196
- with gr.Blocks() as demo:
197
- gr.Markdown("## Search the Hugging Face Hub")
 
 
 
 
198
  with gr.Row():
199
- search_query = gr.Textbox(label="Search Query", value="awacke1")
200
- search_type = gr.Radio(["Models", "Datasets", "Spaces"], label="Search Type", value="Models")
201
- search_button = gr.Button("Search")
 
 
 
 
 
 
 
 
 
 
 
 
202
 
203
- results_html = gr.HTML(label="Search Results")
 
 
 
 
 
 
 
 
 
 
 
 
 
204
 
205
  with gr.Row():
206
- download_readme_button = gr.Button("📚 Download READMEs", visible=False)
207
- download_repo_button = gr.Button("📦 Download Repositories", visible=False)
208
-
209
- download_status = gr.Markdown("", label="Download Status")
210
- download_area = gr.HTML("", label="Download Link")
211
- metadata_output = gr.Textbox(label="Metadata", lines=10)
212
- aggregated_output = gr.JSON(label="Aggregated Content")
213
 
214
  search_type_state = gr.State("")
215
  current_results = gr.State([])
@@ -219,12 +245,9 @@ with gr.Blocks() as demo:
219
  data = df.to_dict('records')
220
  aggregated = SwarmyTime(data)
221
  html_results = display_results(df)
222
- show_download = len(data) > 0
223
  return [
224
  html_results, # results_html
225
- show_download, # download_readme_button visible
226
- show_download, # download_repo_button visible
227
- "", # download_status
228
  "", # download_area
229
  aggregated, # aggregated_output
230
  search_type, # search_type_state
@@ -233,23 +256,21 @@ with gr.Blocks() as demo:
233
 
234
  async def handle_readme_download(data):
235
  if not data:
236
- return ["No results to download", ""]
237
  download_link, status = await download_all_readmes(data)
238
- return [status, download_link]
239
 
240
  def handle_repo_download(data, search_type):
241
  if not data:
242
- return ["No results to download", ""]
243
  download_link, status = create_repo_zip(data, search_type)
244
- return [status, download_link]
245
 
246
  search_button.click(
247
  search_and_aggregate,
248
  inputs=[search_query, search_type],
249
  outputs=[
250
  results_html,
251
- download_readme_button,
252
- download_repo_button,
253
  download_status,
254
  download_area,
255
  aggregated_output,
 
193
  aggregated["unique_authors"] = len(aggregated["unique_authors"])
194
  return aggregated
195
 
196
+ with gr.Blocks(theme=gr.themes.Soft()) as demo:
197
+ gr.Markdown("""
198
+ # Search the Hugging Face Hub
199
+ Search and download models, datasets, and spaces from Hugging Face.
200
+ """)
201
+
202
  with gr.Row():
203
+ with gr.Column(scale=3):
204
+ search_query = gr.Textbox(
205
+ label="Search Query",
206
+ value="awacke1",
207
+ placeholder="Enter search term..."
208
+ )
209
+ with gr.Column(scale=2):
210
+ search_type = gr.Radio(
211
+ ["Models", "Datasets", "Spaces"],
212
+ label="Search Type",
213
+ value="Models",
214
+ container=True
215
+ )
216
+ with gr.Column(scale=1):
217
+ search_button = gr.Button("🔍 Search", variant="primary", scale=1)
218
 
219
+ with gr.Row(variant="panel"):
220
+ with gr.Column(scale=1):
221
+ gr.Markdown("### Download Options")
222
+ with gr.Row():
223
+ download_readme_button = gr.Button(
224
+ "📚 Download READMEs",
225
+ variant="secondary",
226
+ )
227
+ download_repo_button = gr.Button(
228
+ "📦 Download Repositories",
229
+ variant="secondary",
230
+ )
231
+ download_status = gr.Markdown("Status: Ready to download", label="Status")
232
+ download_area = gr.HTML("", label="Download Link")
233
 
234
  with gr.Row():
235
+ with gr.Column(scale=2):
236
+ results_html = gr.HTML(label="Search Results")
237
+ with gr.Column(scale=1):
238
+ aggregated_output = gr.JSON(label="Search Statistics")
 
 
 
239
 
240
  search_type_state = gr.State("")
241
  current_results = gr.State([])
 
245
  data = df.to_dict('records')
246
  aggregated = SwarmyTime(data)
247
  html_results = display_results(df)
 
248
  return [
249
  html_results, # results_html
250
+ "Status: Ready to download", # download_status
 
 
251
  "", # download_area
252
  aggregated, # aggregated_output
253
  search_type, # search_type_state
 
256
 
257
  async def handle_readme_download(data):
258
  if not data:
259
+ return ["Status: No results to download", ""]
260
  download_link, status = await download_all_readmes(data)
261
+ return [f"Status: {status}", download_link]
262
 
263
  def handle_repo_download(data, search_type):
264
  if not data:
265
+ return ["Status: No results to download", ""]
266
  download_link, status = create_repo_zip(data, search_type)
267
+ return [f"Status: {status}", download_link]
268
 
269
  search_button.click(
270
  search_and_aggregate,
271
  inputs=[search_query, search_type],
272
  outputs=[
273
  results_html,
 
 
274
  download_status,
275
  download_area,
276
  aggregated_output,