← Back to Projects

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.

JavaScript⭐ 0 StarsπŸ”„ 2 Forks

πŸ“„ 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


πŸ“¦ Installation

  1. Clone the repository ```bash git clone https://github.com/yourusername/gemini-file-chatbot.git cd gemini-file-chatbot

  2. Create and activate a virtual environment

bash python -m venv venv source venv/bin/activate # On Mac/Linux venv\Scripts\activate # On Windows

  1. Install dependencies

bash pip install -r requirements.txt

  1. Set up environment variables Create a .env file in the project root and add:

env GOOGLE_API_KEY=your_google_gemini_api_key

  1. Run database migrations

bash python manage.py migrate

  1. Start the development server

bash python manage.py runserver


πŸ“„ Usage

  1. Go to http://127.0.0.1:8000/chatbot/
  2. Upload your file (.txt, .pdf, .docx).
  3. Once uploaded, an input box will appear.
  4. 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.