GlitchGhost commited on
Commit
2e67891
Β·
verified Β·
1 Parent(s): f68e648

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -1
app.py CHANGED
@@ -8,7 +8,7 @@ from bs4 import BeautifulSoup
8
  from sentence_transformers import SentenceTransformer
9
  from langchain_community.vectorstores import FAISS
10
  from langchain.embeddings.base import Embeddings
11
- from transformers import pipeline
12
 
13
  # === Embeddings Wrapper ===
14
  class SentenceTransformerEmbeddings(Embeddings):
@@ -35,6 +35,13 @@ def split_text(text, chunk_size=500, overlap=50):
35
  start += chunk_size - overlap
36
  return chunks
37
 
 
 
 
 
 
 
 
38
  def ask_mistral(question, context, hf_api_key):
39
  # Load the Hugging Face Mistral model pipeline
40
  nlp = pipeline("question-answering", model="mistralai/Mistral-7B-v0.3", tokenizer="mistralai/Mistral-7B-v0.3", use_auth_token=hf_api_key)
@@ -77,6 +84,8 @@ st.title("πŸ” RAG Assistant: Chat with PDF, CSV, or Website")
77
  with st.sidebar:
78
  data_source = st.selectbox("πŸ“‚ Select Input Type", ["PDF", "CSV", "Website URL"])
79
  hf_api_key = st.text_input("πŸ”‘ Enter Hugging Face API Key", type="password")
 
 
80
 
81
  # === Logic by Data Source ===
82
  vectorstore = None
 
8
  from sentence_transformers import SentenceTransformer
9
  from langchain_community.vectorstores import FAISS
10
  from langchain.embeddings.base import Embeddings
11
+ from transformers import pipeline, HfApi, HfFolder
12
 
13
  # === Embeddings Wrapper ===
14
  class SentenceTransformerEmbeddings(Embeddings):
 
35
  start += chunk_size - overlap
36
  return chunks
37
 
38
+ def login_to_huggingface(api_key):
39
+ try:
40
+ HfFolder.save_token(api_key)
41
+ st.success("βœ… Logged into Hugging Face successfully!")
42
+ except Exception as e:
43
+ st.error(f"❌ Failed to log in: {e}")
44
+
45
  def ask_mistral(question, context, hf_api_key):
46
  # Load the Hugging Face Mistral model pipeline
47
  nlp = pipeline("question-answering", model="mistralai/Mistral-7B-v0.3", tokenizer="mistralai/Mistral-7B-v0.3", use_auth_token=hf_api_key)
 
84
  with st.sidebar:
85
  data_source = st.selectbox("πŸ“‚ Select Input Type", ["PDF", "CSV", "Website URL"])
86
  hf_api_key = st.text_input("πŸ”‘ Enter Hugging Face API Key", type="password")
87
+ if hf_api_key:
88
+ login_to_huggingface(hf_api_key)
89
 
90
  # === Logic by Data Source ===
91
  vectorstore = None