A Flask-based web chatbot that provides detailed information about medicines using a local dataset and the OpenFDA API. The chatbot uses TF-IDF similarity matching to interpret user queries and responds with structured information about medicine uses, side effects, storage, and more.
- Overview
- Features
- Technologies
- Installation
- Usage
- File Structure
- How It Works
- Dataset
- Troubleshooting
- Contributing
- License
The Medicine Chatbot is a web application designed to assist users in retrieving information about medicines. Users can ask questions like "What is Augmentin used for?" or "Side effects of Azithral?" via a simple chat interface. The bot processes these queries using TF-IDF vectorization to match them against a local CSV dataset (Medicine_Details_Final.csv) and fetches additional data from the OpenFDA API when available. Responses are structured with bold headings and bullet points for clarity, mimicking the style of advanced AI assistants like ChatGPT.
This project is ideal for learning about web development with Flask, natural language processing with TF-IDF, and API integration.
- Interactive Chat Interface: Simple, classic UI with a chat box, input field, and "Send" button.
- Medicine Information: Provides details from a local dataset, including:
- Medicine name
- Composition
- Uses
- Side effects
- Manufacturer
- Storage conditions
- OpenFDA Integration: Fetches real-time FDA data (indications and adverse reactions) for matched medicines.
- TF-IDF Matching: Uses term frequency-inverse document frequency to find the best medicine match based on user input.
- Structured Responses: Formats answers with bold headings and bullet points for readability.
- Error Handling: Gracefully handles missing data, API failures, and invalid queries.
- Python 3.13: Core programming language.
- Flask: Lightweight web framework for serving the app.
- Pandas: Data manipulation for the CSV dataset.
- Scikit-learn: TF-IDF vectorization and cosine similarity.
- Requests: HTTP requests to the OpenFDA API.
- HTML/CSS/JavaScript: Frontend for the chat interface.
-
Clone the Repository:
git clone https://github.com/yourusername/medicine-chatbot.git cd medicine-chatbot -
Set Up a Virtual Environment (optional but recommended):
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install Dependencies:
pip install pandas scikit-learn flask requests
-
Prepare the Dataset:
- Ensure
Medicine_Details_Final.csvis in the project root. - The CSV must have these columns:
Medicine NameCompositionUsesSide_effectsManufacturerStorage ConditionStorage Temperature (°C)Storage Humidity (%)
- Example CSV is available in the repo as
Medicine_Details_Final.csv.
- Ensure
-
Run the Application:
python chatbot.py
-
Access the Chatbot:
- Open a browser and go to
http://127.0.0.1:5000/.
- Open a browser and go to
-
Start the Server:
- Run
python chatbot.pyin your terminal. - You’ll see output like:
* Serving Flask app 'chatbot' * Debug mode: on * Running on http://127.0.0.1:5000
- Run
-
Interact with the Chatbot:
- Open
http://127.0.0.1:5000/in your browser. - Type a question (e.g., "What is Augmentin used for?") in the input box.
- Click "Send" or press Enter.
- The bot responds with structured info (e.g., uses, FDA data).
- Open
medicine-chatbot/
├── chatbot.py # Main application script
├── Medicine_Details_Final.csv # Medicine dataset
├── README.md # This file
└── requirements.txt # List of Python dependencies
- CSV Loading:
pandas.read_csv()loadsMedicine_Details_Final.csvinto a DataFrame. - TF-IDF Matching:
TfidfVectorizercreates a matrix of term frequencies from the dataset. - API Integration: Queries OpenFDA API with medicine names.
- Response Generation: Combines local data and API results into structured responses.
- HTML/CSS: Chat UI with a chat box, input field, and button.
- JavaScript: Handles sending user input and displaying bot responses.
-
Server Not Starting:
- Run
pip install -r requirements.txt. - Change
app.run(port=5001)if port 5000 is in use.
- Run
-
No Response:
- Check API connectivity.
- Ensure dataset is correctly formatted.
- Fork the repository.
- Create a branch (
git checkout -b feature/your-feature). - Commit changes (
git commit -m "Add your feature"). - Push to the branch (
git push origin feature/your-feature). - Open a Pull Request.
This project is licensed under the MIT License. See LICENSE for details.