Spaces:
Runtime error
Runtime error
Download src/ingest.py from Ayush027/async-rust-rag: direct link, hf CLI and curl.
- Browser
- Download file 605 Bytes
-
https://huggingface.co/spaces/Ayush027/async-rust-rag/resolve/main/src/ingest.py
- Command line
-
hf download hf://spaces/Ayush027/async-rust-rag/src/ingest.py
-
curl -L -o ingest.py https://huggingface.co/spaces/Ayush027/async-rust-rag/resolve/main/src/ingest.py
605 Bytes
| import httpx | |
| from bs4 import BeautifulSoup | |
| from markdownify import markdownify | |
| def fetch_page(url:str)-> str: | |
| response = httpx.get(url) | |
| soup = BeautifulSoup(response.text,"html.parser") | |
| main_content = soup.find("main") | |
| print(main_content) | |
| return markdownify(str(main_content)) | |
| def save(content:str, filename:str): | |
| with open(f"knowledge_base/{filename}", "w") as f: | |
| f.write(content) | |
| if __name__ == "__main__": | |
| url = "https://tokio.rs/tokio/tutorial" | |
| content = fetch_page(url) | |
| save(content, "tokio_tutorial.md") | |
| print(f"Saved {len(content)} characters") |