Spaces:
Runtime error
Runtime error
Upload folder using huggingface_hub
Browse files- README.md +3 -9
- __pycache__/main.cpython-311.pyc +0 -0
- main.py +139 -0
- requirements.txt +2 -0
README.md
CHANGED
|
@@ -1,12 +1,6 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
|
| 4 |
-
colorFrom: red
|
| 5 |
-
colorTo: indigo
|
| 6 |
sdk: gradio
|
| 7 |
-
sdk_version:
|
| 8 |
-
app_file: app.py
|
| 9 |
-
pinned: false
|
| 10 |
---
|
| 11 |
-
|
| 12 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
| 1 |
---
|
| 2 |
+
title: best-model-search
|
| 3 |
+
app_file: main.py
|
|
|
|
|
|
|
| 4 |
sdk: gradio
|
| 5 |
+
sdk_version: 4.44.1
|
|
|
|
|
|
|
| 6 |
---
|
|
|
|
|
|
__pycache__/main.cpython-311.pyc
ADDED
|
Binary file (5.05 kB). View file
|
|
|
main.py
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from smolagents import CodeAgent, InferenceClientModel, GradioUI, tool
|
| 2 |
+
from huggingface_hub import HfApi
|
| 3 |
+
import requests
|
| 4 |
+
from typing import List, Dict
|
| 5 |
+
|
| 6 |
+
@tool
|
| 7 |
+
def leaderboard_search(query: str) -> str:
|
| 8 |
+
"""
|
| 9 |
+
Search Hugging Face Spaces specifically in the model benchmarking category.
|
| 10 |
+
|
| 11 |
+
Args:
|
| 12 |
+
query: The search query to find relevant model benchmarking spaces
|
| 13 |
+
|
| 14 |
+
Returns:
|
| 15 |
+
A formatted string containing search results with space names, descriptions, and additional information
|
| 16 |
+
"""
|
| 17 |
+
api_url = "https://huggingface.co/api/spaces"
|
| 18 |
+
|
| 19 |
+
search_words = ["arena", "leaderboard", "benchmark"]
|
| 20 |
+
results = []
|
| 21 |
+
|
| 22 |
+
try:
|
| 23 |
+
for word in search_words:
|
| 24 |
+
params = {
|
| 25 |
+
"search": query + " " + word,
|
| 26 |
+
"full": True # Get full information
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
response = requests.get(api_url, params=params)
|
| 30 |
+
print(response)
|
| 31 |
+
|
| 32 |
+
spaces = response.json()
|
| 33 |
+
print(spaces)
|
| 34 |
+
|
| 35 |
+
if not spaces:
|
| 36 |
+
continue # Skip if no spaces found for this search word
|
| 37 |
+
|
| 38 |
+
for space in spaces:
|
| 39 |
+
# Extract relevant information
|
| 40 |
+
space_id = space.get("id", "Unknown")
|
| 41 |
+
author = space_id.split("/")[0] if "/" in space_id else "Unknown"
|
| 42 |
+
space_name = space_id.split("/")[1] if "/" in space_id else space_id
|
| 43 |
+
likes = space.get("likes", 0)
|
| 44 |
+
|
| 45 |
+
# Try to get detailed information if available
|
| 46 |
+
title = space.get("cardData", {}).get("title") if space.get("cardData") else space_name
|
| 47 |
+
description = space.get("cardData", {}).get("short_description", "No description available") if space.get("cardData") else "No description available"
|
| 48 |
+
|
| 49 |
+
# Create formatted result string
|
| 50 |
+
result = f"🚀 **{title}** ({space_id})\n"
|
| 51 |
+
result += f" 👤 Author: {author}\n"
|
| 52 |
+
result += f" 📝 {description}\n"
|
| 53 |
+
result += f" ❤️ Likes: {likes}\n"
|
| 54 |
+
result += f" 🔗 URL: https://huggingface.co/spaces/{space_id}\n"
|
| 55 |
+
|
| 56 |
+
results.append(result)
|
| 57 |
+
|
| 58 |
+
if not results:
|
| 59 |
+
return f"No model benchmarking spaces found for query: '{query}'"
|
| 60 |
+
|
| 61 |
+
return "\n".join(results)
|
| 62 |
+
except requests.exceptions.RequestException as e:
|
| 63 |
+
return f"Error searching Hugging Face Spaces: {str(e)}"
|
| 64 |
+
except Exception as e:
|
| 65 |
+
return f"Unexpected error: {str(e)}"
|
| 66 |
+
|
| 67 |
+
except requests.exceptions.RequestException as e:
|
| 68 |
+
return f"Error searching Hugging Face Spaces: {str(e)}"
|
| 69 |
+
except Exception as e:
|
| 70 |
+
return f"Unexpected error: {str(e)}"
|
| 71 |
+
|
| 72 |
+
@tool
|
| 73 |
+
def get_space_content(space_id: str) -> str:
|
| 74 |
+
"""
|
| 75 |
+
Get the content of a Hugging Face Space.
|
| 76 |
+
|
| 77 |
+
Args:
|
| 78 |
+
space_id: The Hugging Face Space ID (e.g., "open-llm-leaderboard/open_llm_leaderboard")
|
| 79 |
+
|
| 80 |
+
Returns:
|
| 81 |
+
The space content or error message
|
| 82 |
+
"""
|
| 83 |
+
try:
|
| 84 |
+
# Get the space's README or main content
|
| 85 |
+
readme_url = f"https://huggingface.co/spaces/{space_id}/raw/main/README.md"
|
| 86 |
+
response = requests.get(readme_url)
|
| 87 |
+
|
| 88 |
+
if response.status_code == 200:
|
| 89 |
+
return f"Content from {space_id}:\n\n{response.text}"
|
| 90 |
+
else:
|
| 91 |
+
# Try to get any available file
|
| 92 |
+
files_url = f"https://huggingface.co/api/spaces/{space_id}/tree/main"
|
| 93 |
+
files_response = requests.get(files_url)
|
| 94 |
+
|
| 95 |
+
if files_response.status_code == 200:
|
| 96 |
+
files = files_response.json()
|
| 97 |
+
return f"Available files in {space_id}:\n" + "\n".join([f"- {file['path']}" for file in files])
|
| 98 |
+
else:
|
| 99 |
+
return f"Space {space_id} exists but couldn't retrieve content"
|
| 100 |
+
|
| 101 |
+
except Exception as e:
|
| 102 |
+
return f"Error accessing space {space_id}: {str(e)}"
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
@tool
|
| 106 |
+
def get_file_from_space(space_id: str, file_path: str) -> str:
|
| 107 |
+
"""
|
| 108 |
+
Get a specific file from a Hugging Face Space.
|
| 109 |
+
|
| 110 |
+
Args:
|
| 111 |
+
space_id: The Hugging Face Space ID
|
| 112 |
+
file_path: Path to the file in the space
|
| 113 |
+
|
| 114 |
+
Returns:
|
| 115 |
+
The file content or error message
|
| 116 |
+
"""
|
| 117 |
+
try:
|
| 118 |
+
url = f"https://huggingface.co/spaces/{space_id}/raw/main/{file_path}"
|
| 119 |
+
response = requests.get(url)
|
| 120 |
+
|
| 121 |
+
if response.status_code == 200:
|
| 122 |
+
return f"Content of {file_path} from {space_id}:\n\n{response.text}"
|
| 123 |
+
else:
|
| 124 |
+
return f"Couldn't retrieve {file_path} from {space_id}"
|
| 125 |
+
|
| 126 |
+
except Exception as e:
|
| 127 |
+
return f"Error: {str(e)}"
|
| 128 |
+
|
| 129 |
+
# Initialize the agent with the leaderboard search and space content tools
|
| 130 |
+
model = InferenceClientModel()
|
| 131 |
+
agent = CodeAgent(
|
| 132 |
+
tools=[leaderboard_search, get_space_content, get_file_from_space],
|
| 133 |
+
additional_authorized_imports=["json", "requests"],
|
| 134 |
+
model=model,
|
| 135 |
+
add_base_tools=False,
|
| 136 |
+
description="Your job is to find the best possible model for a given task based on relevant leaderboards or arenas. You will be provided with a task description, and you should use the leaderboard tool to find relevant leaderboards or arenas. If you want to inspect the contents of a particular Space (e.g., README or code), use the space_content_tool. Respond with a list of the top models, including their names, scores, and links to their leaderboard pages.",
|
| 137 |
+
)
|
| 138 |
+
|
| 139 |
+
GradioUI(agent).launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
smolagents
|
| 2 |
+
huggingface_hub
|