This project is a Flask-based web application that enables users to ask questions regarding content fetched from a specified URL. The application leverages the Ollama model to generate responses based on the content it scrapes.
- Fetches and scrapes text content from a specific website.
- Utilizes the Ollama model to provide context-aware answers to user questions.
- Simple RESTful API interface for seamless interaction.
- Flask: A lightweight WSGI web application framework.
- BeautifulSoup: A library for parsing HTML and XML documents.
- Requests: A simple HTTP library for Python.
- Ollama: A command-line interface for running large language models.
To get started with this application, follow these steps:
-
Clone the Repository:
git clone https://github.com/yourusername/flask-web-scraper-with-ollama.git cd flask-web-scraper-with-ollama
Make sure you have Python 3.7+ installed. Then install the required packages:
pip install Flask requests beautifulsoup4
Follow the instructions on the Ollama website to install the Ollama CLI and ensure it is in your system's PATH.
Start the Flask application using the following command: python app.py The application will be accessible at http://127.0.0.1:5000.This endpoint allows users to submit a question, and the application will provide a response based on the scraped content.
Content-Type: application/json
Body:
json: { "question": "What is the main topic of the article?" }
You can use curl or any API client like Postman to send a request:
curl -X POST http://127.0.0.1:5000/ask \ -H "Content-Type: application/json" \ -d '{"question": "What is the main topic of the article?"}'
json { "response": "The answer generated by the Ollama model based on the content." }
json { "error": "URL and question are required" }
Note: The application currently scrapes content from a hardcoded URL. You may want to modify the code to accept a URL from the request body for greater flexibility.
This project is licensed under the MIT License. See the LICENSE file for more details.