Leeps commited on
Commit
24b90be
·
verified ·
1 Parent(s): 4dec569

Upload folder using huggingface_hub

Browse files
Files changed (2) hide show
  1. README.md +77 -0
  2. main.py +12 -4
README.md CHANGED
@@ -4,3 +4,80 @@ app_file: main.py
4
  sdk: gradio
5
  sdk_version: 5.23.1
6
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
  sdk: gradio
5
  sdk_version: 5.23.1
6
  ---
7
+
8
+ # Model Recommender
9
+
10
+ An intelligent agent that searches for and recommends the best AI models for specific tasks by analyzing leaderboards, benchmarks, and arenas across the Hugging Face ecosystem. This tool represents the first step towards self-assembling and self-improving AI systems.
11
+
12
+ ## Overview
13
+
14
+ The Model Recommender automates the process of finding optimal AI models for specific tasks by searching through Hugging Face's extensive collection of leaderboards, benchmarks, and model arenas. Instead of manually comparing models across different evaluation metrics, this agent can quickly identify the top-performing models for your specific use case, saving valuable research time and ensuring you're using state-of-the-art solutions.
15
+
16
+ ## How It Works
17
+
18
+ This tool leverages the Hugging Face API to search for and analyze model benchmarking spaces. When given a task description, the agent:
19
+
20
+ 1. Searches for relevant leaderboards, benchmarks, and arenas using targeted queries
21
+ 2. Analyzes the search results to identify the most relevant evaluation spaces
22
+ 3. Examines the content of these spaces to extract model performance data
23
+ 4. Compiles a ranked list of the best models for the specified task
24
+ 5. Provides detailed information about each model, including performance metrics and links
25
+
26
+ The agent can also download and examine specific files from Hugging Face Spaces to extract more detailed information about model performance and implementation details.
27
+
28
+ ## Features
29
+
30
+ - **Intelligent Leaderboard Search**: Finds relevant model evaluation spaces based on task descriptions
31
+ - **Comprehensive Model Analysis**: Examines multiple evaluation metrics to identify truly optimal models
32
+ - **Detailed Reporting**: Provides performance metrics, model links, and implementation details
33
+ - **Space Content Examination**: Can inspect the contents of Hugging Face Spaces to extract additional information
34
+ - **File Download Capability**: Can download specific files or entire repositories for deeper analysis
35
+
36
+
37
+
38
+ ## Installation
39
+
40
+ Install the required dependencies:
41
+
42
+ ```bash
43
+ pip install -r requirements.txt
44
+ ```
45
+
46
+ ## Usage
47
+
48
+ Run the application:
49
+
50
+ ```bash
51
+ python main.py
52
+ ```
53
+
54
+ This will launch a Gradio interface where you can:
55
+
56
+ 1. Enter a task description (e.g., "text classification", "image generation", "question answering")
57
+ 2. The agent will search for relevant leaderboards and benchmarks
58
+ 3. Review the recommended models, their performance metrics, and links to learn more
59
+
60
+ ## Example Queries
61
+
62
+ - "Find the best models for text classification"
63
+ - "What are the top performing models for image generation?"
64
+ - "I need a model for question answering in a production environment"
65
+ - "Which models perform best on the GLUE benchmark?"
66
+
67
+ ## Towards Self-Assembling AI Systems
68
+
69
+ This Model Recommender represents the first step towards truly self-assembling and self-improving AI systems. By automating the discovery and evaluation of model components, we're building the foundation for systems that can:
70
+
71
+ 1. **Self-Optimize**: Automatically identify and integrate better-performing components
72
+ 2. **Self-Assemble**: Combine specialized models to solve complex tasks
73
+ 3. **Self-Evaluate**: Understand their own performance characteristics and limitations
74
+
75
+ Future iterations will expand beyond model discovery to include automated fine-tuning, integration, and deployment - moving us closer to AI systems that can improve themselves with minimal human intervention.
76
+
77
+ ## Customization
78
+
79
+ To modify the search behavior or add additional tools, edit the `main.py` file:
80
+
81
+ - Adjust the `search_words` list in the `leaderboard_search` function to target different types of evaluation spaces
82
+ - Add new tools to extract more specific information from Hugging Face repositories
83
+ - Modify the agent description to focus on specific types of models or evaluation metrics
main.py CHANGED
@@ -1,11 +1,19 @@
1
  from smolagents import CodeAgent, InferenceClientModel, GradioUI, tool
2
- from huggingface_hub import HfApi
3
- from huggingface_hub import snapshot_download
4
  import requests
5
  from typing import List, Dict
6
  from typing import Optional, Union
7
  from pathlib import Path
8
 
 
 
 
 
 
 
 
 
9
  @tool
10
  def leaderboard_search(query: str) -> str:
11
  """
@@ -29,7 +37,7 @@ def leaderboard_search(query: str) -> str:
29
  "full": True # Get full information
30
  }
31
 
32
- response = requests.get(api_url, params=params)
33
  print(response)
34
 
35
  spaces = response.json()
@@ -137,7 +145,7 @@ def get_file_from_space(space_id: str, file_path: str) -> str:
137
  """
138
  try:
139
  url = f"https://huggingface.co/spaces/{space_id}/raw/main/{file_path}"
140
- response = requests.get(url)
141
 
142
  if response.status_code == 200:
143
  return f"Content of {file_path} from {space_id}:\n\n{response.text}"
 
1
  from smolagents import CodeAgent, InferenceClientModel, GradioUI, tool
2
+ import os
3
+ from huggingface_hub import HfApi, login, snapshot_download
4
  import requests
5
  from typing import List, Dict
6
  from typing import Optional, Union
7
  from pathlib import Path
8
 
9
+ # read token from environment
10
+ HF_TOKEN = os.getenv("HUGGINGFACE_API_KEY")
11
+ if not HF_TOKEN:
12
+ raise RuntimeError("HUGGINGFACE_API_KEY environment variable is not set")
13
+
14
+ # tell huggingface_hub to use it
15
+ login(token=HF_TOKEN)
16
+
17
  @tool
18
  def leaderboard_search(query: str) -> str:
19
  """
 
37
  "full": True # Get full information
38
  }
39
 
40
+ response = requests.get(api_url, params=params, headers={"Authorization": f"Bearer {HF_TOKEN}"})
41
  print(response)
42
 
43
  spaces = response.json()
 
145
  """
146
  try:
147
  url = f"https://huggingface.co/spaces/{space_id}/raw/main/{file_path}"
148
+ response = requests.get(url, headers={"Authorization": f"Bearer {HF_TOKEN}"})
149
 
150
  if response.status_code == 200:
151
  return f"Content of {file_path} from {space_id}:\n\n{response.text}"