MohamedRashad commited on
Commit
ae2bd07
1 Parent(s): 3eaf01d

chore: Add fuzzywuzzy dependency and implement model search functionality

Browse files
Files changed (2) hide show
  1. app.py +29 -1
  2. requirements.txt +2 -1
app.py CHANGED
@@ -1,5 +1,6 @@
1
  import gradio as gr
2
  import pandas as pd
 
3
 
4
  def load_leaderboard():
5
  imagenet_df = pd.read_csv('https://raw.githubusercontent.com/huggingface/pytorch-image-models/main/results/results-imagenet.csv')
@@ -51,13 +52,40 @@ def load_leaderboard():
51
 
52
  return result
53
 
 
54
  df = load_leaderboard()
55
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
56
  with gr.Blocks("Timm Leaderboard") as app:
57
  gr.HTML("<center><h1>PyTorch Image Models Leaderboard</h1></center>")
58
  gr.Markdown("This leaderboard is based on the results of the models from the [PyTorch Image Models]('https://github.com/huggingface/pytorch-image-models') repository.")
59
- leaderboard = gr.DataFrame(df)
 
 
 
60
  refresh_button = gr.Button(value="Refresh Leaderboard", variant="primary")
61
  refresh_button.click(load_leaderboard, outputs=[leaderboard])
 
 
62
 
63
  app.launch()
 
1
  import gradio as gr
2
  import pandas as pd
3
+ from fuzzywuzzy import fuzz
4
 
5
  def load_leaderboard():
6
  imagenet_df = pd.read_csv('https://raw.githubusercontent.com/huggingface/pytorch-image-models/main/results/results-imagenet.csv')
 
52
 
53
  return result
54
 
55
+ global df
56
  df = load_leaderboard()
57
 
58
+ def search_leaderboard(model_name):
59
+ if not model_name:
60
+ return df
61
+
62
+ threshold = 95 # You can adjust this value to make the search more or less strict
63
+
64
+ def calculate_similarity(row):
65
+ similarity = fuzz.partial_ratio(model_name.lower(), row['model'].lower())
66
+ return similarity if similarity >= threshold else 0
67
+
68
+ # Add a new column for similarity scores
69
+ df['similarity'] = df.apply(calculate_similarity, axis=1)
70
+
71
+ # Filter and sort the dataframe
72
+ filtered_df = df[df['similarity'] > 0].sort_values('similarity', ascending=False)
73
+
74
+ # Remove the similarity column before returning
75
+ filtered_df = filtered_df.drop('similarity', axis=1)
76
+
77
+ return filtered_df
78
+
79
  with gr.Blocks("Timm Leaderboard") as app:
80
  gr.HTML("<center><h1>PyTorch Image Models Leaderboard</h1></center>")
81
  gr.Markdown("This leaderboard is based on the results of the models from the [PyTorch Image Models]('https://github.com/huggingface/pytorch-image-models') repository.")
82
+ with gr.Row():
83
+ search_bar = gr.Textbox(lines=1, label="Search Model (You can press Enter to Search)", placeholder="Search for a model", scale=4)
84
+ search_btn = gr.Button(value="Search", variant="primary", scale=1)
85
+ leaderboard = gr.Dataframe(df)
86
  refresh_button = gr.Button(value="Refresh Leaderboard", variant="primary")
87
  refresh_button.click(load_leaderboard, outputs=[leaderboard])
88
+ search_btn.click(search_leaderboard, inputs=[search_bar], outputs=[leaderboard])
89
+ search_bar.submit(search_leaderboard, inputs=[search_bar], outputs=[leaderboard])
90
 
91
  app.launch()
requirements.txt CHANGED
@@ -1,2 +1,3 @@
1
  gradio
2
- pandas
 
 
1
  gradio
2
+ pandas
3
+ fuzzywuzzy