Spaces:
Sleeping
Sleeping
Download modules/utils.py from Raahulthakur/NLP-Assistant: direct link, hf CLI and curl.
- Browser
- Download file 515 Bytes
-
https://huggingface.co/spaces/Raahulthakur/NLP-Assistant/resolve/main/modules/utils.py
- Command line
-
hf download hf://spaces/Raahulthakur/NLP-Assistant/modules/utils.py
-
curl -L -o utils.py https://huggingface.co/spaces/Raahulthakur/NLP-Assistant/resolve/main/modules/utils.py
515 Bytes
| import pdfplumber | |
| from newspaper import Article | |
| def read_pdf(file): | |
| text = "" | |
| with pdfplumber.open(file) as pdf: | |
| for page in pdf.pages: | |
| page_text = page.extract_text() | |
| if page_text: | |
| text += page_text + "\n" | |
| return text.strip() | |
| def fetch_article_from_url(url): | |
| try: | |
| article = Article(url) | |
| article.download() | |
| article.parse() | |
| return article.text | |
| except Exception as e: | |
| return f"Failed to fetch article: {e}" | |