Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,7 +6,6 @@ from langchain.text_splitter import CharacterTextSplitter
|
|
| 6 |
from langchain_community.vectorstores import FAISS
|
| 7 |
from langchain_community.embeddings import HuggingFaceEmbeddings
|
| 8 |
from langchain_core.prompts import PromptTemplate
|
| 9 |
-
from langchain_core.output_parsers import StrOutputParser
|
| 10 |
from langchain_community.llms import HuggingFacePipeline
|
| 11 |
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM, pipeline
|
| 12 |
|
|
@@ -35,12 +34,9 @@ def process_pdf(pdf_files):
|
|
| 35 |
splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=200)
|
| 36 |
texts = splitter.split_text(text)
|
| 37 |
|
| 38 |
-
# Convert to LangChain documents
|
| 39 |
-
docs = [doc for doc in texts]
|
| 40 |
-
|
| 41 |
# Embeddings & vector store
|
| 42 |
embeddings = HuggingFaceEmbeddings(model_name="sentence-transformers/all-MiniLM-L6-v2")
|
| 43 |
-
db = FAISS.from_texts(
|
| 44 |
|
| 45 |
return db
|
| 46 |
|
|
@@ -64,20 +60,24 @@ def ask_question(pdf_files, question):
|
|
| 64 |
response = llm.invoke(final_prompt)
|
| 65 |
return response
|
| 66 |
|
|
|
|
| 67 |
# ---------- Gradio UI ----------
|
| 68 |
with gr.Blocks() as demo:
|
| 69 |
gr.Markdown("## 📚 Multiple PDF Chatbot")
|
| 70 |
|
| 71 |
with gr.Row():
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
|
|
|
|
|
|
|
|
|
| 81 |
|
| 82 |
submit = gr.Button("Submit")
|
| 83 |
submit.click(fn=ask_question, inputs=[pdf_input, question_input], outputs=output)
|
|
|
|
| 6 |
from langchain_community.vectorstores import FAISS
|
| 7 |
from langchain_community.embeddings import HuggingFaceEmbeddings
|
| 8 |
from langchain_core.prompts import PromptTemplate
|
|
|
|
| 9 |
from langchain_community.llms import HuggingFacePipeline
|
| 10 |
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM, pipeline
|
| 11 |
|
|
|
|
| 34 |
splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=200)
|
| 35 |
texts = splitter.split_text(text)
|
| 36 |
|
|
|
|
|
|
|
|
|
|
| 37 |
# Embeddings & vector store
|
| 38 |
embeddings = HuggingFaceEmbeddings(model_name="sentence-transformers/all-MiniLM-L6-v2")
|
| 39 |
+
db = FAISS.from_texts(texts, embeddings)
|
| 40 |
|
| 41 |
return db
|
| 42 |
|
|
|
|
| 60 |
response = llm.invoke(final_prompt)
|
| 61 |
return response
|
| 62 |
|
| 63 |
+
|
| 64 |
# ---------- Gradio UI ----------
|
| 65 |
with gr.Blocks() as demo:
|
| 66 |
gr.Markdown("## 📚 Multiple PDF Chatbot")
|
| 67 |
|
| 68 |
with gr.Row():
|
| 69 |
+
pdf_input = gr.File(
|
| 70 |
+
file_types=[".pdf"],
|
| 71 |
+
type="file",
|
| 72 |
+
label="Upload PDFs",
|
| 73 |
+
file_types_multiple=True
|
| 74 |
+
)
|
| 75 |
+
|
| 76 |
+
with gr.Row():
|
| 77 |
+
question_input = gr.Textbox(label="Ask a Question")
|
| 78 |
+
|
| 79 |
+
with gr.Row():
|
| 80 |
+
output = gr.Textbox(label="Answer")
|
| 81 |
|
| 82 |
submit = gr.Button("Submit")
|
| 83 |
submit.click(fn=ask_question, inputs=[pdf_input, question_input], outputs=output)
|