vichudo commited on
Commit
f41e5db
·
1 Parent(s): a717c64

feat: add dataset uploader

Browse files
Files changed (1) hide show
  1. upload_datasets.py +61 -0
upload_datasets.py ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Content for upload_datasets.py
2
+ import pickle
3
+ import os
4
+ from datasets import Dataset
5
+ from huggingface_hub import HfApi
6
+
7
+ # Initialize Hugging Face API
8
+ api = HfApi()
9
+
10
+ # Upload embeddings
11
+ print("Preparing embeddings dataset...")
12
+ try:
13
+ with open('embeddings/embeddings.pkl', 'rb') as f:
14
+ embeddings_data = pickle.load(f)
15
+
16
+ # Create dataset with metadata to preserve the format
17
+ embeddings_ds = Dataset.from_dict({
18
+ "data": [pickle.dumps(embeddings_data)],
19
+ "format": ["pickle"]
20
+ })
21
+
22
+ # Push to hub
23
+ print("Uploading embeddings dataset...")
24
+ embeddings_ds.push_to_hub("vichudo/agentic-defensor-embeddings")
25
+ print("Embeddings dataset uploaded successfully!")
26
+ except Exception as e:
27
+ print(f"Error uploading embeddings: {e}")
28
+
29
+ # Upload FAISS index separately
30
+ print("Uploading FAISS index file...")
31
+ try:
32
+ api.upload_file(
33
+ path_or_fileobj="embeddings/faiss_index.index",
34
+ path_in_repo="faiss_index.index",
35
+ repo_id="vichudo/agentic-defensor-embeddings",
36
+ repo_type="dataset"
37
+ )
38
+ print("FAISS index uploaded successfully!")
39
+ except Exception as e:
40
+ print(f"Error uploading FAISS index: {e}")
41
+
42
+ # Upload document chunks
43
+ print("Preparing document chunks dataset...")
44
+ try:
45
+ with open('data/doc_chunks.pkl', 'rb') as f:
46
+ chunks_data = pickle.load(f)
47
+
48
+ # Create dataset
49
+ chunks_ds = Dataset.from_dict({
50
+ "data": [pickle.dumps(chunks_data)],
51
+ "format": ["pickle"]
52
+ })
53
+
54
+ # Push to hub
55
+ print("Uploading document chunks dataset...")
56
+ chunks_ds.push_to_hub("vichudo/agentic-defensor-chunks")
57
+ print("Document chunks dataset uploaded successfully!")
58
+ except Exception as e:
59
+ print(f"Error uploading document chunks: {e}")
60
+
61
+ print("Dataset upload process complete!")