Repository
Question-Answering-Project
This project is a Django web application that allows you to **upload a file** (TXT, PDF, DOCX), extract its text, and then **chat with a chatbot** powered by **Google Gemini** — with the conversation based entirely on the uploaded file’s content.
📄 File-Based Chatbot with Google Gemini
This project is a Django web application that allows you to upload a file (TXT, PDF, DOCX), extract its text, and then chat with a chatbot powered by Google Gemini — with the conversation based entirely on the uploaded file’s content.
🚀 Features
- 📂 Upload Files: Supports
.txt,.pdf,.docxformats. - 🧠 Text Extraction: Automatically reads and processes file content.
- 💬 Interactive Chat: Ask questions and receive answers only from your uploaded file.
- 🔄 Persistent Context: The chatbot remembers your uploaded file during the session.
- 🖥 User-Friendly Interface: File upload + chat input on the same page.
🛠️ Tech Stack
- Backend: Django
- AI Model: Google Gemini API
- Frontend: HTML + Django Templates
- File Parsing:
- PyPDF2 for PDFs
- python-docx for DOCX
- Built-in Python for TXT
📦 Installation
-
Clone the repository ```bash git clone https://github.com/yourusername/gemini-file-chatbot.git cd gemini-file-chatbot
-
Create and activate a virtual environment
bash
python -m venv venv
source venv/bin/activate # On Mac/Linux
venv\Scripts\activate # On Windows
- Install dependencies
bash
pip install -r requirements.txt
- Set up environment variables
Create a
.envfile in the project root and add:
env
GOOGLE_API_KEY=your_google_gemini_api_key
- Run database migrations
bash
python manage.py migrate
- Start the development server
bash
python manage.py runserver
📄 Usage
- Go to
http://127.0.0.1:8000/chatbot/ - Upload your file (
.txt,.pdf,.docx). - Once uploaded, an input box will appear.
- Type your questions — responses are based only on your uploaded file.
📂 Project Structure
project_root/
│
├── app/
│ ├── models.py # File model with text storage
│ ├── forms.py # Upload form
│ ├── views.py # Upload + chat logic
│ ├── gemini.py # Google Gemini API wrapper
│ ├── templates/
│ │ └── chatbot.html # Main chatbot page
│
├── manage.py
├── requirements.txt
├── README.md
📜 Example
Upload File:
my_notes.pdfcontaining details about cars.
User:
"What does it say about electric cars?"
Bot:
"The file mentions that electric cars are environmentally friendly and have lower running costs compared to traditional gasoline vehicles."
⚠️ Notes
- Large files may take longer to process.
- Session data is cleared when the server restarts.
- Gemini API usage depends on your API quota and billing settings.
📄 License
This project is licensed under the MIT License.
💡 Future Improvements
- Store and search across multiple uploaded files.
- Add streaming responses for real-time replies.
- Enable multi-user sessions with authentication.