Spaces:
Paused
Paused
| import requests | |
| # 🔥 Your SearXNG endpoint | |
| SEARXNG_URL = "https://funbro-my-search-api.hf.space/search" | |
| def search_web(query, max_results=5): | |
| try: | |
| response = requests.get( | |
| SEARXNG_URL, | |
| params={"q": query, "format": "json"}, | |
| timeout=15 | |
| ) | |
| data = response.json() | |
| results = data.get("results", []) | |
| if not results: | |
| return "No relevant web results found." | |
| compiled = "" | |
| for r in results[:max_results]: | |
| title = r.get("title", "") | |
| content = r.get("content", "") | |
| url = r.get("url", "") | |
| if not title or not content: | |
| continue | |
| compiled += f""" | |
| Title: {title} | |
| Source: {url} | |
| Snippet: {content} | |
| --- | |
| """ | |
| return compiled.strip() | |
| except Exception as e: | |
| return f"Search failed: {str(e)}" | |