Spaces:
Sleeping
Sleeping
Pranjal Gupta
commited on
Commit
·
52e00f2
1
Parent(s):
70d6f98
login implemented using token
Browse files
app.py
CHANGED
|
@@ -13,6 +13,8 @@ from langchain_core.documents import Document
|
|
| 13 |
from langchain_community.llms import HuggingFacePipeline
|
| 14 |
from langchain_community.document_loaders import PyPDFLoader
|
| 15 |
from langchain.text_splitter import RecursiveCharacterTextSplitter
|
|
|
|
|
|
|
| 16 |
|
| 17 |
# Initialize in-memory ChromaDB client
|
| 18 |
client = chromadb.Client()
|
|
@@ -87,7 +89,7 @@ def using_ollama_model(retriever, query, results, conversation_history):
|
|
| 87 |
)
|
| 88 |
|
| 89 |
doc_texts = "\\n".join([doc.page_content for doc in results])
|
| 90 |
-
model_id = "
|
| 91 |
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
| 92 |
model = AutoModelForCausalLM.from_pretrained(model_id)
|
| 93 |
pipe = pipeline(
|
|
@@ -165,13 +167,22 @@ def gradio_rag_wrapper(message, history):
|
|
| 165 |
return response
|
| 166 |
|
| 167 |
# Create the Gradio interface with multimodal input
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 175 |
|
| 176 |
if __name__ == "__main__":
|
| 177 |
# Create a dummy doc for initial testing if no PDF is uploaded
|
|
|
|
| 13 |
from langchain_community.llms import HuggingFacePipeline
|
| 14 |
from langchain_community.document_loaders import PyPDFLoader
|
| 15 |
from langchain.text_splitter import RecursiveCharacterTextSplitter
|
| 16 |
+
from huggingface_hub import login
|
| 17 |
+
|
| 18 |
|
| 19 |
# Initialize in-memory ChromaDB client
|
| 20 |
client = chromadb.Client()
|
|
|
|
| 89 |
)
|
| 90 |
|
| 91 |
doc_texts = "\\n".join([doc.page_content for doc in results])
|
| 92 |
+
model_id = "meta-llama/Llama-3.2-3B-Instruct"
|
| 93 |
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
| 94 |
model = AutoModelForCausalLM.from_pretrained(model_id)
|
| 95 |
pipe = pipeline(
|
|
|
|
| 167 |
return response
|
| 168 |
|
| 169 |
# Create the Gradio interface with multimodal input
|
| 170 |
+
with gr.Blocks(title="Contextual RAG Chatbot on Hugging Face Spaces") as demo:
|
| 171 |
+
gr.Markdown("## Contextual RAG Chatbot")
|
| 172 |
+
gr.Markdown("Please enter your Hugging Face Access Token to access gated models like Llama 3.2. You can generate a token from your [Hugging Face settings](https://huggingface.co/settings/tokens).")
|
| 173 |
+
|
| 174 |
+
hf_token_textbox = gr.Textbox(
|
| 175 |
+
label="Hugging Face Access Token",
|
| 176 |
+
type="password",
|
| 177 |
+
interactive=True
|
| 178 |
+
)
|
| 179 |
+
|
| 180 |
+
chatbot = gr.ChatInterface(
|
| 181 |
+
fn=lambda message, history: gradio_rag_wrapper(message, history, hf_token_textbox.value),
|
| 182 |
+
multimodal=True,
|
| 183 |
+
description="Upload a PDF file to start chatting!",
|
| 184 |
+
textbox=gr.MultimodalTextbox(file_types=[".pdf"]),
|
| 185 |
+
)
|
| 186 |
|
| 187 |
if __name__ == "__main__":
|
| 188 |
# Create a dummy doc for initial testing if no PDF is uploaded
|