CoolFace
Apppublic

ComposableConsult/ragmodelwithllm

sourceHugging Facemitupdated 1y agoView on Hugging Face
0likes
App README

๐Ÿง  RAG Chatbot with Document Upload and PDF Support

This is a lightweight Retrieval-Augmented Generation (RAG) chatbot built using Gradio, FAISS, Hugging Face Transformers, and Sentence Transformers. It enables users to upload .pdf or .txt documents and ask natural language questions about their contents. The chatbot uses a combination of embedding-based semantic search and a generative language model to provide accurate and context-aware answers.


๐Ÿš€ Features

  • โ€”โœ… Upload .txt and .pdf files
  • โ€”โœ… Automatically extracts and chunks document content
  • โ€”โœ… FAISS-powered semantic search over document chunks
  • โ€”โœ… all-MiniLM-L6-v2 SentenceTransformer for embedding generation
  • โ€”โœ… TinyLlama-1.1B-Chat-v1.0 for answer generation
  • โ€”โœ… Interactive chatbot with session-based message history
  • โ€”โœ… GPU acceleration (if available), falls back to CPU
  • โ€”โœ… Clean, responsive UI with example prompts

๐Ÿ› ๏ธ How It Works

๐Ÿ“‚ Upload Documents

Upload one or more .pdf or .txt files using the drag-and-drop UI.

๐Ÿงฑ Index Building

The app:

  • โ€”Extracts text from each document
  • โ€”Splits it into 500-character chunks
  • โ€”Generates embeddings using all-MiniLM-L6-v2
  • โ€”Stores the chunks in a FAISS index for fast retrieval

โ“ Querying

When a user asks a question:

  • โ€”The query is embedded and compared against all document chunks
  • โ€”The top-3 most relevant chunks are retrieved
  • โ€”A custom prompt is created combining those chunks and the question

๐Ÿ’ฌ Chatbot Response

The prompt is passed to the TinyLlama language model, which generates a relevant answer. The result is displayed in a persistent chat history window.


๐Ÿ’ป Requirements

Install the required Python packages:

bash
pip install gradio faiss-cpu torch transformers sentence-transformers PyPDF2