Spaces:
Running
Running
File size: 1,650 Bytes
4386283 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | from gradio_client import Client
import logging
logger = logging.getLogger("tools-api")
def search_web_tool(query: str, limit: int = 4):
"""Search the web for information using victor/websearch space."""
logger.info(f"Searching web for: {query}")
try:
client = Client("https://victor-websearch.hf.space/")
result = client.predict(query, "search", limit, api_name="/search_web")
return result
except Exception as e:
logger.error(f"Error searching web: {e}")
return f"Error searching web: {str(e)}"
def search_hf_spaces_tool(query: str, limit: int = 3):
"""Search Hugging Face Spaces using john6666/testwarm space."""
logger.info(f"Searching HF Spaces for: {query}")
try:
client = Client("https://john6666-testwarm.hf.space/")
# data format for /search endpoint
result = client.predict(
["model"], # Repo type
"last_modified", # Sort
"ascending order", # Sort method
query, # Filter
query, # Search
"", # Author
"", # Tags
"warm", # Inference status
"gated", # Gated status
["auto"], # Approval method
["n<1K"], # Size categories
limit, # Limit
["cpu-basic"], # Specify hardware
["RUNNING"], # Specify stage
["Space Runtime"], # Fetch detail
["Type"], # Show items
api_name="/search"
)
return result
except Exception as e:
logger.error(f"Error searching HF Spaces: {e}")
return f"Error searching HF Spaces: {str(e)}"
|