Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -8,9 +8,9 @@ import tempfile
|
|
| 8 |
from huggingface_hub import HfApi, HfFolder
|
| 9 |
|
| 10 |
DB_FAISS_PATH = 'vectorstore/db_faiss'
|
| 11 |
-
|
| 12 |
|
| 13 |
-
# Function to create or update FAISS vector DB and upload to Hugging Face
|
| 14 |
def create_vector_db(uploaded_files):
|
| 15 |
# Create a temporary directory
|
| 16 |
with tempfile.TemporaryDirectory() as temp_dir:
|
|
@@ -61,14 +61,14 @@ def create_vector_db(uploaded_files):
|
|
| 61 |
if not hf_token:
|
| 62 |
raise ValueError("Hugging Face token not found. Please set the token in Hugging Face secrets.")
|
| 63 |
|
| 64 |
-
# Push the updated vector database to Hugging Face
|
| 65 |
HfFolder.save_token(hf_token)
|
| 66 |
api = HfApi()
|
| 67 |
api.upload_folder(
|
| 68 |
folder_path=DB_FAISS_PATH, # Local path to the FAISS folder
|
| 69 |
-
path_in_repo="faiss_data", #
|
| 70 |
-
repo_id=
|
| 71 |
-
repo_type="
|
| 72 |
token=hf_token # Use the token from secrets
|
| 73 |
)
|
| 74 |
|
|
@@ -89,9 +89,9 @@ def main():
|
|
| 89 |
try:
|
| 90 |
success = create_vector_db(uploaded_files)
|
| 91 |
if success:
|
| 92 |
-
st.success("Vector database created and uploaded successfully!")
|
| 93 |
except Exception as e:
|
| 94 |
st.error(f"An error occurred: {str(e)}")
|
| 95 |
|
| 96 |
if __name__ == "__main__":
|
| 97 |
-
main()
|
|
|
|
| 8 |
from huggingface_hub import HfApi, HfFolder
|
| 9 |
|
| 10 |
DB_FAISS_PATH = 'vectorstore/db_faiss'
|
| 11 |
+
SPACE_REPO = "GovindRaj/ebiz-chatbot" # Your Hugging Face Space ID
|
| 12 |
|
| 13 |
+
# Function to create or update FAISS vector DB and upload to Hugging Face Space
|
| 14 |
def create_vector_db(uploaded_files):
|
| 15 |
# Create a temporary directory
|
| 16 |
with tempfile.TemporaryDirectory() as temp_dir:
|
|
|
|
| 61 |
if not hf_token:
|
| 62 |
raise ValueError("Hugging Face token not found. Please set the token in Hugging Face secrets.")
|
| 63 |
|
| 64 |
+
# Push the updated vector database to Hugging Face Space
|
| 65 |
HfFolder.save_token(hf_token)
|
| 66 |
api = HfApi()
|
| 67 |
api.upload_folder(
|
| 68 |
folder_path=DB_FAISS_PATH, # Local path to the FAISS folder
|
| 69 |
+
path_in_repo="faiss_data", # Path in the Space repo
|
| 70 |
+
repo_id=SPACE_REPO, # Hugging Face Space ID
|
| 71 |
+
repo_type="space", # Specify that this is a Space
|
| 72 |
token=hf_token # Use the token from secrets
|
| 73 |
)
|
| 74 |
|
|
|
|
| 89 |
try:
|
| 90 |
success = create_vector_db(uploaded_files)
|
| 91 |
if success:
|
| 92 |
+
st.success("Vector database created and uploaded to your Hugging Face Space successfully!")
|
| 93 |
except Exception as e:
|
| 94 |
st.error(f"An error occurred: {str(e)}")
|
| 95 |
|
| 96 |
if __name__ == "__main__":
|
| 97 |
+
main()
|