Rahatara commited on
Commit
04cdfa0
·
verified ·
1 Parent(s): d3e47e7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -10
app.py CHANGED
@@ -1,6 +1,5 @@
1
  import gradio as gr
2
  import os
3
-
4
  from langchain_community.document_loaders import PyPDFLoader
5
  from langchain.text_splitter import RecursiveCharacterTextSplitter
6
  from langchain_community.vectorstores import Chroma
@@ -19,6 +18,27 @@ import torch
19
  import tqdm
20
  import accelerate
21
  import re
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
 
23
 
24
 
@@ -282,15 +302,6 @@ def demo():
282
  qa_chain = gr.State()
283
  collection_name = gr.State()
284
 
285
- gr.Markdown(
286
- """<center><h2>PDF-based chatbot</center></h2>
287
- <h3>Ask any questions about your PDF documents</h3>""")
288
- gr.Markdown(
289
- """<b>Note:</b> This AI assistant, using Langchain and open-source LLMs, performs retrieval-augmented generation (RAG) from your PDF documents. \
290
- The user interface explicitely shows multiple steps to help understand the RAG workflow.
291
- This chatbot takes past questions into account when generating answers (via conversational memory), and includes document references for clarity purposes.<br>
292
- <br><b>Warning:</b> This space uses the free CPU Basic hardware from Hugging Face. Some steps and LLM models used below (free inference endpoints) can take some time to generate a reply.
293
- """)
294
 
295
  with gr.Tab("Step 1 - Upload PDF"):
296
  with gr.Row():
 
1
  import gradio as gr
2
  import os
 
3
  from langchain_community.document_loaders import PyPDFLoader
4
  from langchain.text_splitter import RecursiveCharacterTextSplitter
5
  from langchain_community.vectorstores import Chroma
 
18
  import tqdm
19
  import accelerate
20
  import re
21
+ from huggingface_hub import login, HfApi
22
+
23
+
24
+
25
+ # Authenticate using the Hugging Face token stored as a secret
26
+ def authenticate_hf():
27
+ token = os.getenv("HUGGINGFACE_TOKEN")
28
+ if not token:
29
+ raise ValueError("Hugging Face token not found in environment variables.")
30
+
31
+ try:
32
+ login(token=token)
33
+ api = HfApi()
34
+ user_info = api.whoami(token=token)
35
+ print(f"Login successful. User info: {user_info}")
36
+ except Exception as e:
37
+ raise ValueError(f"Error during login: {e}")
38
+
39
+ # Authenticate at the start of the script
40
+ authenticate_hf()
41
+
42
 
43
 
44
 
 
302
  qa_chain = gr.State()
303
  collection_name = gr.State()
304
 
 
 
 
 
 
 
 
 
 
305
 
306
  with gr.Tab("Step 1 - Upload PDF"):
307
  with gr.Row():