Spaces:
Build error
Build error
Download web_search.py from 0Learn/Ai-Email-Assistant: direct link, hf CLI and curl.
- Browser
- Download file 429 Bytes
-
https://huggingface.co/spaces/0Learn/Ai-Email-Assistant/resolve/main/web_search.py
- Command line
-
hf download hf://spaces/0Learn/Ai-Email-Assistant/web_search.py
-
curl -L -o web_search.py https://huggingface.co/spaces/0Learn/Ai-Email-Assistant/resolve/main/web_search.py
429 Bytes
| # web_search.py | |
| # Filepath: ai-email-assistant/web_search.py | |
| # Implements web search functionality | |
| from duckduckgo_search import DDGS | |
| def search_web(query, num_results=5): | |
| try: | |
| with DDGS() as ddgs: | |
| results = list(ddgs.text(query, max_results=num_results)) | |
| return [f"{r['title']}: {r['body']}" for r in results] | |
| except Exception as e: | |
| return [f"Error performing web search: {str(e)}"] |