Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
from langchain_community.document_loaders import PyPDFLoader
|
| 3 |
from langchain_community.vectorstores import FAISS
|
| 4 |
from langchain.text_splitter import RecursiveCharacterTextSplitter
|
|
@@ -15,7 +16,7 @@ warnings.filterwarnings('ignore')
|
|
| 15 |
|
| 16 |
# Set your Hugging Face API token here.
|
| 17 |
# For deployment on Hugging Face, you can set this as an environment variable.
|
| 18 |
-
|
| 19 |
os.environ["HUGGINGFACEHUB_API_TOKEN"] = "hf_YOUR_HUGGINGFACE_TOKEN"
|
| 20 |
|
| 21 |
## LLM - Using an open-source model from Hugging Face
|
|
@@ -86,8 +87,15 @@ def retriever_qa(file, query):
|
|
| 86 |
"""
|
| 87 |
Sets up a RetrievalQA chain to answer questions based on the document.
|
| 88 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
llm = get_llm()
|
| 90 |
-
retriever_obj = retriever(
|
| 91 |
|
| 92 |
# Custom prompt to act as a conversational legal advisor
|
| 93 |
prompt_template = f"""
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import os
|
| 3 |
from langchain_community.document_loaders import PyPDFLoader
|
| 4 |
from langchain_community.vectorstores import FAISS
|
| 5 |
from langchain.text_splitter import RecursiveCharacterTextSplitter
|
|
|
|
| 16 |
|
| 17 |
# Set your Hugging Face API token here.
|
| 18 |
# For deployment on Hugging Face, you can set this as an environment variable.
|
| 19 |
+
|
| 20 |
os.environ["HUGGINGFACEHUB_API_TOKEN"] = "hf_YOUR_HUGGINGFACE_TOKEN"
|
| 21 |
|
| 22 |
## LLM - Using an open-source model from Hugging Face
|
|
|
|
| 87 |
"""
|
| 88 |
Sets up a RetrievalQA chain to answer questions based on the document.
|
| 89 |
"""
|
| 90 |
+
# Use the file path from the Gradio file object
|
| 91 |
+
file_path = file.name if file else None
|
| 92 |
+
|
| 93 |
+
# Check if a file was uploaded
|
| 94 |
+
if not file_path:
|
| 95 |
+
return "Please upload a valid PDF file before asking a question."
|
| 96 |
+
|
| 97 |
llm = get_llm()
|
| 98 |
+
retriever_obj = retriever(file_path)
|
| 99 |
|
| 100 |
# Custom prompt to act as a conversational legal advisor
|
| 101 |
prompt_template = f"""
|