AkshayUmesh commited on
Commit
bb31c45
Β·
verified Β·
1 Parent(s): 165f84e

Upload 3 files

Browse files
Files changed (3) hide show
  1. README.md +23 -19
  2. app.py +51 -0
  3. requirements.txt +7 -3
README.md CHANGED
@@ -1,19 +1,23 @@
1
- ---
2
- title: Docuquery
3
- emoji: πŸš€
4
- colorFrom: red
5
- colorTo: red
6
- sdk: docker
7
- app_port: 8501
8
- tags:
9
- - streamlit
10
- pinned: false
11
- short_description: Streamlit template space
12
- ---
13
-
14
- # Welcome to Streamlit!
15
-
16
- Edit `/src/streamlit_app.py` to customize this app to your heart's desire. :heart:
17
-
18
- If you have any questions, checkout our [documentation](https://docs.streamlit.io) and [community
19
- forums](https://discuss.streamlit.io).
 
 
 
 
 
1
+ # πŸ“„ DocuQuery - Free Document Q&A with LangChain + Hugging Face
2
+
3
+ DocuQuery lets you **upload a PDF and ask questions** about it.
4
+ This version uses **free Hugging Face models** (no OpenAI required).
5
+
6
+ ## πŸš€ Features
7
+ - Upload a PDF
8
+ - Ask questions in natural language
9
+ - Uses **sentence-transformers for embeddings** + **Flan-T5 for answering**
10
+ - Runs free via Hugging Face Hub
11
+
12
+ ## πŸ› οΈ Tech Stack
13
+ - Python, Streamlit
14
+ - LangChain, FAISS
15
+ - Hugging Face Hub (Flan-T5, MiniLM embeddings)
16
+
17
+ ## ▢️ Run Locally
18
+ ```bash
19
+ git clone https://github.com/<your-username>/docuquery.git
20
+ cd docuquery
21
+ pip install -r requirements.txt
22
+ export HUGGINGFACEHUB_API_TOKEN="your_hf_token_here"
23
+ streamlit run app.py
app.py ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from langchain_community.document_loaders import PyPDFLoader
3
+ from langchain.text_splitter import RecursiveCharacterTextSplitter
4
+ from langchain_community.vectorstores import FAISS
5
+ from langchain.chains import RetrievalQA
6
+ from langchain_community.embeddings import HuggingFaceEmbeddings
7
+ from langchain_community.llms import HuggingFaceHub
8
+ import tempfile
9
+ import os
10
+
11
+ # Hugging Face API token (free – just create an account on huggingface.co)
12
+ HF_TOKEN = os.getenv("HuggingfacehubAPIToken")
13
+
14
+ st.set_page_config(page_title="DocuQuery (Free)", page_icon="πŸ“„", layout="wide")
15
+ st.title("πŸ“„ DocuQuery - Free RAG App with Hugging Face Models")
16
+
17
+ # Upload PDF
18
+ uploaded_file = st.file_uploader("Upload your PDF file", type="pdf")
19
+
20
+ if uploaded_file:
21
+ with tempfile.NamedTemporaryFile(delete=False, suffix=".pdf") as tmp_file:
22
+ tmp_file.write(uploaded_file.read())
23
+ file_path = tmp_file.name
24
+
25
+ # Load PDF and split text
26
+ loader = PyPDFLoader(file_path)
27
+ documents = loader.load()
28
+
29
+ text_splitter = RecursiveCharacterTextSplitter(chunk_size=500, chunk_overlap=50)
30
+ docs = text_splitter.split_documents(documents)
31
+
32
+ # Create embeddings with free Hugging Face model
33
+ embeddings = HuggingFaceEmbeddings(model_name="sentence-transformers/all-MiniLM-L6-v2")
34
+ vectorstore = FAISS.from_documents(docs, embeddings)
35
+
36
+ retriever = vectorstore.as_retriever()
37
+
38
+ # Use a free Hugging Face LLM (lightweight for Q&A)
39
+ llm = HuggingFaceHub(
40
+ repo_id="google/flan-t5-base",
41
+ huggingfacehub_api_token=HF_TOKEN,
42
+ model_kwargs={"temperature":0, "max_length":512}
43
+ )
44
+
45
+ qa = RetrievalQA.from_chain_type(llm=llm, chain_type="stuff", retriever=retriever)
46
+
47
+ query = st.text_input("πŸ” Ask a question about your document:")
48
+
49
+ if query:
50
+ answer = qa.run(query)
51
+ st.markdown(f"**Answer:** {answer}")
requirements.txt CHANGED
@@ -1,3 +1,7 @@
1
- altair
2
- pandas
3
- streamlit
 
 
 
 
 
1
+ streamlit
2
+ langchain
3
+ langchain-community
4
+ faiss-cpu
5
+ sentence-transformers
6
+ pypdf
7
+ huggingface_hub