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.
Language: JavaScript
Stars: 1
Forks: 2
Watchers: 1
README
π 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
,.docx
formats. - π§ 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
.env
file 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.pdf
containing 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.